CrossidClient performs OAuth2 authorization code flow using the PKCE extension. A typical application will only need a sigle instance of this client. In more advanced cases, such as a single SPA app that requires interaction with multiple oauth2 clients, a client instance should be created per OAuth client id.

const opts = {
...
}
const crossid = new CrossidClient(opts)

Hierarchy

  • Client

Constructors

Methods

  • Creates a redirect URL that can be used to start an logout flow.

    This method is useful when you want control over the actual redirection, if you want browser to be redirected, call logoutWithRedirect instead.

    const url = createLogoutRedirectURL()
    window.location.assign(url)

    Returns

    a URL where the browser should be redirected to in order to logout.

    Parameters

    • opts: LogoutOpts = {}

      custom options that affects the logout flow.

    Returns Promise<string>

  • Creates a redirect URL that can be used to start an authorization code request.

    This method is useful when you want control over the actual redirection, if you want browser to be redirected, call loginWithRedirect instead.

    const url = createRedirectURL()
    window.location.assign(url)

    Returns

    a URL where the browser should be redirected to in order to login.

    Parameters

    • opts: AuthorizationOpts = {}

      custom options that affects the authorization code process.

    Returns Promise<string>

  • Returns an access token.

    Returns

    a promise which resolves to an access token string.

    Parameters

    • opts: GetAccessTokenOpts = {}

      options to get an access token for a more specific authentication.

    Returns Promise<string>

  • Returns an authenticated User.

    Returns

    a promise which resolves to a User or undefined if no authenticated user found.

    Type Parameters

    Parameters

    • opts: GetUserOpts = {}

      options to get a user for a more specific authentication.

    Returns Promise<E>

  • Call this method in order to complete authentication flow. this method should be called after the End-User successfully signs-in.

    Returns

    Parameters

    • url: URL = ...

      the URL returned from the authorization code endpoint, defaults to window.location.href

    Returns Promise<LoginCompleteResponse>

  • Call this method in order to complete logout flow. this method should be called after the End-User sucessfully logs out.

    note that this method only works if the logout was performed for a specific client.

    Returns

    Parameters

    • url: URL = ...

      the URL returned from the logout endpoint, defaults to window.location.href

    Returns Promise<LogoutCompleteResponse>

  • introspectAccessToken returns the decoded claims of the access token. handful for protecting spa routes by claims such 'scp'

    note: this method does not actually perform idp introspection nor checks the validity of the token.

    Returns

    Parameters

    Returns Promise<JWTClaims>