Skip to main content
The Deno 2 Release Candidate is here
Learn more
Module

x/oauth2_server/resource_server.ts>ResourceServer

A standards compliant implementation of an OAuth 2.0 authorization server with PKCE support.
Latest
class ResourceServer
import { ResourceServer } from "https://deno.land/x/oauth2_server@0.12.0/resource_server.ts";

Constructors

new
ResourceServer(options: ResourceServerOptions<Client, User, Scope>)

Type Parameters

Client extends ClientInterface
User
Scope extends ScopeInterface

Methods

authenticate<Request extends OAuth2Request<Client, User, Scope>>(
request: Request,
response: OAuth2Response,
next: () => Promise<unknown>,
getAccessToken: (request: Request) => Promise<string | null>,
acceptedScope?: Scope,
): Promise<void>

Authenticates a request and verifies the token has the required scope.

authenticateError(): Promise<void>

Handles the response for an unauthenticated request.

authenticateResponse(request: OAuth2Request<Client, User, Scope>, response: OAuth2Response): Promise<void>

Adds authentication scope headers to the response.

authenticateSuccess(
response: OAuth2Response,
next: () => Promise<unknown>,
): Promise<void>

Handles the response for an authenticated request.

errorHandler(
response: OAuth2Response,
error: Error,
): Promise<void>

Handles error responses.

getAccessToken(request: OAuth2Request<Client, User, Scope>): Promise<string | null>

Gets an access token string from the authorization header or post body.

getToken(accessToken: string): Promise<Token<Client, User, Scope>>

Gets a token for an access token string.

getTokenForRequest<Request extends OAuth2Request<Client, User, Scope>>(request: Request, getAccessToken: (request: Request) => Promise<string | null>): Promise<Token<Client, User, Scope>>

Gets a token for a request and adds it onto the request.