MonoCloud Authentication SDK
    Preparing search index...
    Index

    Constructors

    Methods

    • Generates a session with user and tokens by exchanging authorization code from callback params.

      Parameters

      • code: string

        The authorization code received from the callback

      • redirectUri: string

        The redirect URI that was used in the authorization request

      • requestedScopes: string

        A space-separated list of scopes originally requested via the /authorize endpoint. This is stored in the session to ensure the correct access token can be identified and refreshed during refreshSession().

      • Optionalresource: string

        A space-separated list of resource indicators originally requested via the /authorize endpoint. Used alongside scopes to uniquely identify and refresh the specific access token associated with these resources.

      • Optionaloptions: AuthenticateOptions

        Options for authenticating a user with authorization code

      Returns Promise<MonoCloudSession>

      The user's session containing authentication tokens and user information.

      MonoCloudValidationError - When the token scope does not contain the openid scope, or if 'expires_in' or 'scope' is missing from the token response.

      MonoCloudOPError - When the OpenID Provider returns a standardized OAuth 2.0 error response.

      MonoCloudTokenError - If ID Token validation fails

      MonoCloudHttpError - Thrown if there is a network error during the request or unexpected status code during the request or a serialization error while processing the response.

    • Generates an authorization URL with specified parameters.

      If no values are provided for responseType, or codeChallengeMethod, they default to code, and S256, respectively.

      Parameters

      Returns Promise<string>

      Tenant's authorization url.

      MonoCloudHttpError - Thrown if there is a network error during the request or unexpected status code during the request or a serialization error while processing the response.

    • Generates OpenID end session url for signing out.

      Note - The state is added only when postLogoutRedirectUri is present.

      Parameters

      Returns Promise<string>

      Tenant's end session url

      MonoCloudHttpError - Thrown if there is a network error during the request or unexpected status code during the request or a serialization error while processing the response.

    • Exchanges an authorization code for tokens.

      Parameters

      • code: string

        The authorization code received from the authorization server.

      • redirectUri: string

        The redirect URI used in the initial authorization request.

      • OptionalcodeVerifier: string

        Code verifier for PKCE.

      • Optionalresource: string

        Space-separated list of resources the access token should be scoped to

      Returns Promise<Tokens>

      Tokens obtained by exchanging an authorization code at the token endpoint.

      MonoCloudOPError - When the OpenID Provider returns a standardized OAuth 2.0 error response.

      MonoCloudHttpError - Thrown if there is a network error during the request or unexpected status code during the request or a serialization error while processing the response.

    • Fetches the JSON Web Keys used to sign the id token. The JWKS is cached for 1 minute.

      Parameters

      • OptionalforceRefresh: boolean

        If true, bypasses the cache and fetches fresh set of JWKS from the server.

      Returns Promise<Jwks>

      The JSON Web Key Set containing the public keys for token verification.

      MonoCloudHttpError - Thrown if there is a network error during the request or unexpected status code during the request or a serialization error while processing the response.

    • Fetches the authorization server metadata from the .well-known endpoint. The metadata is cached for 1 minute.

      Parameters

      • OptionalforceRefresh: boolean

        If true, bypasses the cache and fetches fresh metadata from the server.

      Returns Promise<IssuerMetadata>

      The issuer metadata for the tenant, retrieved from the OpenID Connect discovery endpoint.

      MonoCloudHttpError - Thrown if there is a network error during the request or unexpected status code during the request or a serialization error while processing the response.

    • Performs a pushed authorization request.

      Parameters

      Returns Promise<ParResponse>

      Response from Pushed Authorization Request (PAR) endpoint

      MonoCloudOPError - When the request is invalid.

      MonoCloudHttpError - Thrown if there is a network error during the request or unexpected status code during the request or a serialization error while processing the response.

    • Refetches user information for an existing session using the userinfo endpoint. Updates the session's user object with the latest user information while preserving existing properties.

      Parameters

      Returns Promise<MonoCloudSession>

      Updated session with the latest userinfo

      MonoCloudValidationError - When the token scope does not contain openid scope

      MonoCloudOPError - When the OpenID Provider returns a standardized OAuth 2.0 error response.

      MonoCloudTokenError - If ID Token validation fails

      MonoCloudHttpError - Thrown if there is a network error during the request or unexpected status code during the request or a serialization error while processing the response.

    • Exchanges a refresh token for new tokens.

      Parameters

      • refreshToken: string

        The refresh token used to request new tokens.

      • Optionaloptions: RefreshGrantOptions

        Refresh grant options.

      Returns Promise<Tokens>

      Tokens obtained by exchanging a refresh token at the token endpoint.

      MonoCloudOPError - When the OpenID Provider returns a standardized OAuth 2.0 error response.

      MonoCloudHttpError - Thrown if there is a network error during the request or unexpected status code during the request or a serialization error while processing the response.

    • Refreshes an existing session using the refresh token. This function requests new tokens using the refresh token and optionally updates user information.

      Parameters

      Returns Promise<MonoCloudSession>

      User's session containing refreshed authentication tokens and user information.

      MonoCloudValidationError - If the refresh token is not present in the session, or if 'expires_in' or 'scope' (including the openid scope) is missing from the token response.

      MonoCloudOPError - When the OpenID Provider returns a standardized OAuth 2.0 error response.

      MonoCloudTokenError - If ID Token validation fails

      MonoCloudHttpError - Thrown if there is a network error during the request or unexpected status code during the request or a serialization error while processing the response.

    • Revokes an access token or refresh token, rendering it invalid for future use.

      Parameters

      • token: string

        The token string to be revoked

      • OptionaltokenType: string

        Hint about the token type ('access_token' or 'refresh_token')

      Returns Promise<void>

      If token revocation succeeded

      MonoCloudValidationError - If token is invalid or unsupported token type

      MonoCloudOPError - When the OpenID Provider returns a standardized OAuth 2.0 error response.

      MonoCloudHttpError - Thrown if there is a network error during the request or unexpected status code during the request or a serialization error while processing the response.

    • Fetches userinfo associated with the provided access token.

      Parameters

      • accessToken: string

        A valid access token used to retrieve userinfo.

      Returns Promise<UserinfoResponse>

      The authenticated user's claims.

      MonoCloudOPError - When the OpenID Provider returns a standardized OAuth 2.0 error (e.g., 'invalid_token') in the 'WWW-Authenticate' header following a 401 Unauthorized response.

      MonoCloudHttpError - Thrown if there is a network error during the request or unexpected status code during the request or a serialization error while processing the response.

      MonoCloudValidationError - When the access token is invalid.

    • Validates an ID Token.

      Parameters

      • idToken: string

        The ID Token JWT string to validate

      • jwks: Jwk[]

        Array of JSON Web Keys (JWK) used to verify the token's signature

      • clockSkew: number

        Number of seconds to adjust the current time to account for clock differences

      • clockTolerance: number

        Additional time tolerance in seconds for time-based claim validation

      • OptionalmaxAge: number

        maximum authentication age in seconds

      • Optionalnonce: string

        nonce value to validate against the token's nonce claim

      Returns Promise<IdTokenClaims>

      Validated ID Token claims

      MonoCloudTokenError - If ID Token validation fails

    • Decodes the payload of a JSON Web Token (JWT) and returns it as an object. THIS METHOD DOES NOT VERIFY JWT TOKENS.

      Parameters

      • jwt: string

        JWT to decode

      Returns IdTokenClaims

      Decoded payload

      MonoCloudTokenError - If decoding fails