# Class OpenIdConnectClient

##### Index

### Methods

disconnect
getAccessToken
getIdentityToken
create
createFromTokenResponse
loginWithRedirect

## Methods

### disconnect

- disconnect(): void

  #### Returns void

### getAccessToken

- getAccessToken(): Promise<string>

  Provides an access token from the Open ID connect provider.

  Returns a cached value if there's sufficient time left until the access_token expires. If the access_token is about to expire a fresh token is fetched.

  #### Returns Promise<string>

  access_token from the `/token` endpoint.

### getIdentityToken

- getIdentityToken(): Promise<IdentityToken>

  Provides an identity token from the Open ID connect provider.

  Returns a cached value if there's sufficient time left until the id_token expires. If the id_token is about to expire a fresh token is fetched.

  #### Returns Promise<IdentityToken>

  parsed id_token from the `/token` endpoint.

### `Static` create

- create(
  clientOptions: OpenIdConnectClientOptions,
  callbackState: SuccessfulLoginCallbackState,
  createDependencies?: CreateDependencies,
  ): Promise<OpenIdConnectClient>

  Creates an Open ID Connect client that uses refresh tokens. Expects callbackState to be the values from the callback caused by loginWithRedirect.

  See https://auth0.com/docs/get-started/authentication-and-authorization-flow/add-login-auth-code-flow

  #### Parameters

  - clientOptions: OpenIdConnectClientOptions

    specifies which Open ID provider to login with and the client credentials

  - callbackState: SuccessfulLoginCallbackState

    code and state received from the query parameters in the callback caused by loginWithRedirect

  - `Optional` createDependencies: CreateDependencies

    dependency injection

  #### Returns Promise<OpenIdConnectClient>

  an Open ID Connect client that uses refresh tokens

  #### Example

      const options: OpenIdConnectClientOptions = {
          clientId: '<client-id>',
          openIdProviderUrl: 'http://my/idp'
      };
      const callbackState = inferLoginCallbackStateFromUrl(window.location.href);
      if (isSuccessfulLoginCallbackState(callbackState)) {
          const client = await OpenIdConnectClient.create(options, callbackState);
          const token = await client.getToken();
      } else {
        // ...
      }

### `Static` createFromTokenResponse

- createFromTokenResponse(
  response: Response,
  openIdProviderMetadata: OpenIdProviderMetadata,
  clientOptions: OpenIdConnectClientOptions,
  code_verifier?: string,
  redirect_uri?: string,
  fetch?: typeof fetch,
  ): Promise<OpenIdConnectClient>

  #### Parameters

  - response: Response
  - openIdProviderMetadata: OpenIdProviderMetadata
  - clientOptions: OpenIdConnectClientOptions
  - `Optional` code_verifier: string
  - `Optional` redirect_uri: string
  - `Optional` fetch: typeof fetch

  #### Returns Promise<OpenIdConnectClient>

### `Static` loginWithRedirect

- loginWithRedirect(
  clientOptions: OpenIdConnectClientOptions,
  loginWithRedirectDependencies?: Partial<LoginWithRedirectDependencies>,
  ): Promise<never>

  Initializes the login with redirect for code flow with the Open ID provider specified in clientOptions. The returned promise will never resolve. Awaiting the return value will block the continued execution of the promise chain.

  See https://auth0.com/docs/get-started/authentication-and-authorization-flow/add-login-auth-code-flow

  #### Parameters

  - clientOptions: OpenIdConnectClientOptions

    specifies which Open ID provider to login with

  - `Optional` loginWithRedirectDependencies: Partial<LoginWithRedirectDependencies>

    dependency injection

  #### Returns Promise<never>

  an unfulfilled promise that will never resolve

  #### Example

      const options: OpenIdConnectClientOptions = {
          clientId: '<client-id>',
          openIdProviderUrl: 'http://my/idp'
      };
      await OpenIdConnectClient.loginWithRedirect(options);
      throw 'The async function OpenIdConnectClient#loginWithRedirect should never resolve, returns an unfulfilled promise';