Skip to main content
Module

x/oauth2_client/mod.ts>AuthorizationCodeGrant

Minimalistic OAuth 2.0 client for Deno.
Latest
class AuthorizationCodeGrant
extends OAuth2GrantBase
import { AuthorizationCodeGrant } from "https://deno.land/x/oauth2_client@v1.0.2/mod.ts";

Implements the OAuth 2.0 authorization code grant.

See https://tools.ietf.org/html/rfc6749#section-4.1

Constructors

new
AuthorizationCodeGrant(client: OAuth2Client)

Methods

private
buildAccessTokenRequest(
code: string,
codeVerifier?: string,
requestOptions?: RequestOptions,
): Request
private
validateAuthorizationResponse(url: URL, options: AuthorizationCodeTokenOptions): Promise<{ code: string; state?: string; }>
getAuthorizationUri(options?: AuthorizationUriOptionsWithPKCE): Promise<AuthorizationUriWithVerifier>

Builds a URI you can redirect a user to to make the authorization request.

By default, PKCE will be used. You can opt out of PKCE by passing { disablePkce: true } in the options.

When using PKCE it is your responsibility to store the returned codeVerifier and associate it with the user's session just like with the state parameter. You have to pass it to the getToken() request when you receive the authorization callback or the token request will fail.

getAuthorizationUri(options: AuthorizationUriOptionsWithoutPKCE): Promise<AuthorizationUriWithoutVerifier>
getToken(authResponseUri: string | URL, options?: AuthorizationCodeTokenOptions): Promise<Tokens>

Parses the authorization response request tokens from the authorization server.

Usually you'd want to call this method in the function that handles the user's request to your configured redirectUri.