Class AuthToken
The AuthToken
class represents an authorization token and encapsulates information
about the authorization scheme and its associated value.
- Scheme - The authorization scheme (e.g., "Basic" or "Bearer").
- Value - The encoded value, which is scheme-dependent (e.g., an access token per RFC6750 or Base64-encoded "user:password" per RFC2617).
- String representation - A string that combines the scheme and value in the format: [scheme + " " + value].
public class AuthToken
- Inheritance
-
AuthToken
- Inherited Members
Fields
BasicScheme
The Basic Authentication Scheme.
public const string BasicScheme = "Basic"
Field Value
BearerScheme
The Bearer Authentication (token authentication) Scheme.
public const string BearerScheme = "Bearer"
Field Value
Properties
HttpAuthorization
Gets the HTTP authorization header value.
public string HttpAuthorization { get; }
Property Value
Password
Gets the password or null
if it is not known or applicable.
public string? Password { get; }
Property Value
Scheme
Gets the authentication scheme.
public string Scheme { get; }
Property Value
User
Gets the username or null
if it is not known or applicable.
public string? User { get; }
Property Value
Value
Gets the access token for RFC6750 or the Base64-encoded "username:password" for RFC2617.
public string Value { get; }
Property Value
Methods
CreateBasicToken(string)
Constructs an AuthToken with the specified username and password per RFC2617. Username and password can be empty.
public static AuthToken CreateBasicToken(string userPassword)
Parameters
userPassword
stringThe string containing the username and password in the format
username:password
.
Returns
Exceptions
- JavaException
If the userPassword is malformed.
CreateBasicToken(string, string)
Constructs an AuthToken with the specified username and password per RFC2617. Username and password can be empty.
public static AuthToken CreateBasicToken(string user, string password)
Parameters
Returns
CreateBasicTokenOrNull(string?, string?)
Constructs an AuthToken with the specified username and password per RFC2617.
If both the username and password are empty or null
, returns null
.
public static AuthToken? CreateBasicTokenOrNull(string? user, string? password)
Parameters
Returns
CreateBearerToken(string)
Constructs an AuthToken with the specified bearer token per RFC6750.
public static AuthToken CreateBearerToken(string token)
Parameters
token
stringThe access token.
Returns
Exceptions
- JavaException
If the token is empty.
CreateBearerTokenOrNull(string?)
Constructs an AuthToken with the specified bearer token per RFC6750.
public static AuthToken? CreateBearerTokenOrNull(string? token)
Parameters
token
stringThe access token.
Returns
CreateCustomToken(string, string)
Constructs an AuthToken with a custom scheme and value.
public static AuthToken CreateCustomToken(string scheme, string value)
Parameters
Returns
Exceptions
- JavaException
If the scheme or value is empty.
Equals(object?)
Determines whether the specified object is equal to the current object.
public override bool Equals(object? obj)
Parameters
obj
objectThe object to compare with the current object.
Returns
- bool
true
if the specified object is equal to the current object; otherwise,false
.
GetHashCode()
Returns a hash code value for this object.
public override int GetHashCode()
Returns
- int
A hash code value for this object.
ToString()
Returns string representation of this token.
public override string ToString()
Returns
- string
The string representation.
ValueOf(string)
Constructs an AuthToken from the specified string.
public static AuthToken ValueOf(string str)
Parameters
str
stringThe string with space-separated scheme and value.
Returns
Exceptions
- JavaException
If the string is malformed, or if the scheme is "Basic" but the format does not comply with RFC2617.