Package: auth
The auth package defines generic authentication abstractions that are usable across multiple protocols.
Interfaces
AuthRequest
Object used to perform authenticated HTTP requests. In languages where such constructs are already provided (e.g. python, see [1]), they should be used instead of this object to take advantage of the existing ecosystem.
This can be created from the OAuth2ClientCredentials Object by using oauth2AuthRequest.
[1] https://requests.readthedocs.io/en/latest/user/authentication/
Methods
configureRequest(request:Request)Configures the HTTP request as needed to use a specific authorization type. This method allows adopters to implement a specific authorization type depending their environment.
request:RequestRequest or equivalent object used in the language.
Classes
OAuth2ClientCredentials
Credentials class implementing the OAuth 2.0 Client Credentials grant. Retrieves and refreshes access tokens from a direct OAuth 2.0 token endpoint (tokenEndpoint), which MUST be an HTTPS URL, using the Client Credentials grant. Token endpoint requests retry transient connection and timeout errors, HTTP 429 responses, and HTTP 5xx responses with bounded exponential backoff and jitter. Other errors are returned without retrying.
Constructors
OAuth2ClientCredentials(clientId:string,clientSecret:string,tokenEndpoint:string,retry?:RetryOptions)Initialize the credential helper.
clientId:stringOAuth 2.0 client identifier
clientSecret:stringOAuth 2.0 client secret
tokenEndpoint:stringOAuth 2.0 token endpoint HTTPS URL
retry?:RetryOptionsOptional retry policy for token endpoint requests. Defaults to 3 retries with full-jitter exponential backoff capped at 0.5, 1, and 2 seconds. Set
maxRetriesto 0 to disable retries.
Methods
getToken(forceRefresh?:boolean):RefreshTokenResponseObtains a valid token for the client. If
forceRefreshis set totrue, a new token is fetched and cached regardless of the current token’s expiry. The cached token is returned when it does not expire in the next 5 minutes (300 seconds). Otherwise, a new one is fetched and cached.Implementations must be thread-safe.
forceRefresh?:booleanSet to true to bypass the cache and fetch a new token (default: false). NOT RECOMMENDED. Force with caution!
RetryOptions
Configuration for bounded retries on transient OAuth token endpoint failures. Retry behavior is applied only while obtaining a token, not to arbitrary API calls or OIDC discovery. Implementations must preserve thread-safe token caching and coalesce concurrent refresh attempts.
Properties
maxRetries:integerMaximum number of retries after the initial request (default: 3; 0 disables retries).
baseDelay:numberInitial exponential backoff delay in seconds (default: 0.5).
maxDelay:numberMaximum exponential backoff delay in seconds (default: 2.0).
jitter:stringJitter mode, either
full(default) ornone.
RefreshTokenResponse
Parsed token data
Properties
accessToken:stringOAuth 2.0 token
expiresAt:DatetimeToken's expiration time.
OIDCDiscoveryMetadata
Parsed OIDC discovery document exposing useful endpoints.
Properties
tokenEndpoint:stringOAuth 2.0 token endpoint URL advertised by the provider
Functions
fetchOIDCDiscovery(issuerUrl:string):OIDCDiscoveryMetadataRetrieve and parse the OIDC discovery document for the given issuer. See: https://openid.net/specs/openid-connect-discovery-1_0.html
issuerUrl:stringBase URL of the OIDC issuer
oAuth2AuthRequest(oAuth2ClientCredentials:OAuth2ClientCredentials):AuthRequestWraps an OAuth2ClientCredentials object into an AuthRequest (or the specific construct used in the language) to allow injecting the token provided by the OAuth2ClientCredentials into the request.
oAuth2ClientCredentials:OAuth2ClientCredentialsOAuth token provider used to authenticate the requests.