ADK for TypeScript: API Reference
    Preparing search index...

    Class AuthHandler

    A handler that handles the auth flow in Agent Development Kit to help orchestrates the credential request and response flow (e.g. OAuth flow) This class should only be used by Agent Development Kit.

    authConfig: AuthConfig

    The auth config this handler reads. It stays readable and replaceable after construction; each method reads the current value.

    • Builds the auth request to send to the client.

      The result is always a new object, and its exchangedAuthCredential is never an object held by authConfig. A caller that fills in the response, for example exchangedAuthCredential.oauth2.authResponseUri, therefore leaves the handler's credentials unchanged.

      When the config is returned as is, because the scheme is not OAuth2 or OpenID Connect or the exchanged credential already has an auth URI, the result is a deep copy of the whole config. In the other branches only the exchanged credential is guaranteed independent: authScheme and rawAuthCredential are the handler's own objects.

      Returns AuthConfig

      The auth config to request from the client.

      Error: If an OAuth2 or OpenID Connect scheme has no raw credential, no oauth2 on it, or no client ID and secret.

    • Generates an response containing the auth uri for user to sign in.

      When the credential requests PKCE, the URI also carries the S256 code challenge derived from the credential's code verifier, and the returned credential carries the verifier the later token exchange must send.

      The URI leaves out redirect_uri when the credential has no redirectUri, so the provider uses the redirect registered for the client, and leaves out scope when the scheme lists no scopes.

      Returns AuthCredential | undefined

      An AuthCredential object containing the auth URI and state.

      Error: If the authorization endpoint is not configured in the auth scheme, or the credential requests a code challenge method other than 'S256'.

    • Stores the exchanged credential in the session state.

      Parameters

      • state: State

        The session state to store the credential in.

      Returns Promise<void>

      Error: If the auth config has no credentialKey.