Class: BasicAuthScheme
@divine/uri.BasicAuthScheme
The basic
AuthScheme provides support for 'Basic' HTTP Authentication.
Hierarchy
AuthScheme
<PasswordCredentials
>↳
BasicAuthScheme
Constructors
constructor
• new BasicAuthScheme(scheme?
)
Parameters
Name | Type | Default value |
---|---|---|
scheme | string | 'Basic' |
Overrides
Defined in
uri/src/auth-schemes/basic.ts:26
Properties
proxy
• proxy: boolean
Specifies wheter or not this scheme provides proxy auhentication. Usually false.
Inherited from
Defined in
realm
• Optional
realm: string
The realm or domain this instance is handling.
Inherited from
Defined in
scheme
• scheme: string
The canonical name of the scheme this instance handles.
Inherited from
Defined in
Methods
_assertCompatibleAuthHeader
▸ Protected
_assertCompatibleAuthHeader<H
>(header
): H
Asserts that an authentication header is compatible with this AuthScheme.
Throws
AuthSchemeError If the header is incompatible with this AuthScheme.
Type parameters
Name | Type |
---|---|
H | extends undefined | AuthHeader |
Parameters
Name | Type | Description |
---|---|---|
header | H | The header to check, or undefined to do nothing. |
Returns
H
The provided header.
Inherited from
AuthScheme._assertCompatibleAuthHeader
Defined in
_assertCompatibleCredentials
▸ Protected
_assertCompatibleCredentials<C
>(credentials
): C
Asserts that some credentials are compatible with this AuthScheme.
Throws
AuthSchemeError If the credentials are incompatible with this AuthScheme.
Type parameters
Name | Type | Description |
---|---|---|
C | extends undefined | Credentials | The type of credentials that the scheme uses. |
Parameters
Name | Type | Description |
---|---|---|
credentials | C | The credentials to check, or undefined to do nothing. |
Returns
C
The provided credentials.
Inherited from
AuthScheme._assertCompatibleCredentials
Defined in
_createChallenge
▸ Protected
_createChallenge(authorization?
): Promise
<WWWAuthenticate
>
Creates a new challenge for the client.
Parameters
Name | Type | Description |
---|---|---|
authorization? | Authorization | The authentication the client provided. |
Returns
Promise
<WWWAuthenticate
>
A new challenge.
Inherited from
Defined in
_getCredentials
▸ Protected
_getCredentials(options
): Promise
<undefined
| PasswordCredentials
>
Asks the credentials provider for credentials.
Throws
AuthSchemeError If the authentication, challenge or the credentials provided via setCredentialsProvider are incompatibe with this AuthScheme.
Parameters
Name | Type | Description |
---|---|---|
options | CredentialsProviderOptions <PasswordCredentials > | Options to pass to the credentials provider. |
Returns
Promise
<undefined
| PasswordCredentials
>
Valid credentials or undefined
if no credentials could be provided.
Inherited from
Defined in
_isCompatibleCredentials
▸ Protected
_isCompatibleCredentials(credentials
): boolean
Checks if the provided credentials are compatible with this AuthScheme.
Throws
AuthSchemeError If the credentials provided are incompatibe with this AuthScheme.
Parameters
Name | Type | Description |
---|---|---|
credentials | PasswordCredentials | The credentials to check for compatibility. |
Returns
boolean
true
if the provided credentials are usable by this AuthScheme.
Overrides
AuthScheme._isCompatibleCredentials
Defined in
uri/src/auth-schemes/basic.ts:83
createAuthorization
▸ createAuthorization(challenge?
, request?
, _payload?
): Promise
<undefined
| Authorization
>
Generates an Authorization header for an outgoing request.
Throws
AuthSchemeError If the challenge or the credentials provided via setCredentialsProvider are incompatibe with this AuthScheme.
Parameters
Name | Type | Description |
---|---|---|
challenge? | WWWAuthenticate | An optional challenge sent by the remote server. |
request? | AuthSchemeRequest | The request that is to be authenticated. |
_payload? | Uint8Array | The request payload that will be sent. |
Returns
Promise
<undefined
| Authorization
>
An Authorization header with the provided credentials.
Overrides
AuthScheme.createAuthorization
Defined in
uri/src/auth-schemes/basic.ts:52
setCredentialsProvider
▸ setCredentialsProvider(cp?
): BasicAuthScheme
Attaches a CredentialsProvider for retrieving or verifying credentials.
Parameters
Name | Type | Description |
---|---|---|
cp? | PasswordCredentials | CredentialsProvider <PasswordCredentials > | The CredentialsProvider to register. |
Returns
This AuthScheme.
Inherited from
AuthScheme.setCredentialsProvider
Defined in
setProxyMode
▸ setProxyMode(proxy
): BasicAuthScheme
Sets the proxy mode.
Parameters
Name | Type | Description |
---|---|---|
proxy | boolean | true if proxy mode, else false . |
Returns
This AuthScheme.
Inherited from
Defined in
setRealm
▸ setRealm(realm
): BasicAuthScheme
Sets the realm/domain.
Parameters
Name | Type | Description |
---|---|---|
realm | string | The realm this instance handles. |
Returns
This AuthScheme.
Inherited from
Defined in
verifyAuthenticationInfo
▸ verifyAuthenticationInfo<T
>(authentication
, _request?
, _payload?
): Promise
<T
>
Verifies an AuthenticationInfo or ServerAuthorization header received from a server response.
Not all protocols supports verification of responses. In that case, this method does nothing.
Throws
AuthSchemeError If the authentication or the credentials provided via setCredentialsProvider are incompatibe with this AuthScheme.
Type parameters
Name | Type | Description |
---|---|---|
T | extends undefined | AuthenticationInfo | ServerAuthorization | The type of the header to validate. |
Parameters
Name | Type | Description |
---|---|---|
authentication | T | The authentication provided by the remote server. |
_request? | AuthSchemeRequest | The response to a request that is to be authenticated. |
_payload? | Uint8Array | The response payload received from the remote server. |
Returns
Promise
<T
>
The validated AuthenticationInfo/ServerAuthorization header.
Overrides
AuthScheme.verifyAuthenticationInfo
Defined in
uri/src/auth-schemes/basic.ts:79
verifyAuthorization
▸ verifyAuthorization<T
>(authorization
, request?
, _payload?
): Promise
<T
>
Verifies an Authorization header from an incoming request.
Throws
AuthSchemeError If the authentication or the credentials provided via setCredentialsProvider are incompatibe with this AuthScheme.
Type parameters
Name | Type | Description |
---|---|---|
T | extends undefined | Authorization | The type of the header to validate. |
Parameters
Name | Type | Description |
---|---|---|
authorization | T | The authentication provided by the remote client. |
request? | AuthSchemeRequest | The request that is to be authenticated. |
_payload? | Uint8Array | The request payload that was sent. |
Returns
Promise
<T
>
The validated Authorization header.
Overrides
AuthScheme.verifyAuthorization
Defined in
uri/src/auth-schemes/basic.ts:59
create
▸ Static
create(from
, proxy?
): AuthScheme
<Credentials
>
Creates an authentication scheme class from an authentication header or authentication name.
If the authentication scheme is unknown, an instance of UnknownAuthScheme will be returned.
Parameters
Name | Type | Description |
---|---|---|
from | string | RegExp | AuthHeader | The type of authentication scheme to create. |
proxy? | boolean | Set to true to force proxy mode. Defaults to AuthHeader.isProxyHeader or false . |
Returns
An AuthScheme instance that provides authentication for the requested scheme.
Inherited from
Defined in
decodeCredentials
▸ Static
decodeCredentials(credentials?
): undefined
| PasswordCredentials
Utility method to decode encoded 'Basic' HTTP Authentication credentials into a username/password pair.
Parameters
Name | Type | Description |
---|---|---|
credentials? | string | Base64-encoded credentials to decode. |
Returns
undefined
| PasswordCredentials
A PasswordCredentials object or undefined
if the credentials could not be decoded.
Defined in
uri/src/auth-schemes/basic.ts:46
encodeCredentials
▸ Static
encodeCredentials(credentials
): string
Utility method to encode a username/password pair according to the 'Basic' HTTP Authentication scheme.
Parameters
Name | Type | Description |
---|---|---|
credentials | PasswordCredentials | The credentials to encode. |
Returns
string
A Base64-encoded string with the username and password separated with a colon.
Defined in
uri/src/auth-schemes/basic.ts:36
register
▸ Static
register<C
>(scheme
, authScheme
): typeof AuthScheme
Registers a new authentication scheme. All subclasses must register their authentication type support with this method.
Type parameters
Name | Type | Description |
---|---|---|
C | extends Credentials | The type of credentials this authentication scheme uses. |
Parameters
Name | Type | Description |
---|---|---|
scheme | string | The name of the authentication scheme to be registered. |
authScheme | Constructor <AuthScheme <C >> | The AuthScheme subclass to register. |
Returns
typeof AuthScheme
The AuthScheme base class (for method chaining).
Inherited from
Defined in
safeCompare
▸ Static
safeCompare(untrusted
, trusted
): boolean
Utility method to compare two secrets in a time-constant manner.
Parameters
Name | Type | Description |
---|---|---|
untrusted | string | number [] | The untrusted secret that should be verified. |
trusted | string | number [] | The trusted secret that the untrusted secret should be compared against. |
Returns
boolean
true
if the secrets are equal, else false
.