import { handleCallback } from "https://deno.land/x/deno_kv_oauth@v0.2.7/mod.ts";
Handles the OAuth 2.0 callback request for a given OAuth 2.0 client, and then redirects the client to the given redirect URL.
It does this by:
- Getting the OAuth 2.0 session ID from the cookie in the given request.
- Getting, then deleting, the OAuth 2.0 session object from KV using the OAuth 2.0 session ID. The OAuth 2.0 session object was generated in the sign-in process.
- Getting the OAuth 2.0 tokens from the given OAuth 2.0 client using the OAuth 2.0 session object.
- Storing the OAuth 2.0 tokens in KV using a generated session ID.
- Returning a response that sets a session cookie and redirects the client to the given redirect URL, the access token and the session ID for processing during the callback handler.
Examples
Example 1
Example 1
import { handleCallback, createGitHubOAuth2Client } from "https://deno.land/x/deno_kv_oauth@$VERSION/mod.ts";
const oauth2Client = createGitHubOAuth2Client();
export async function handleOAuthCallback(request: Request) {
const { response, accessToken, sessionId } = await handleCallback(
request,
oauth2Client,
"/redirect-path-after-handle"
);
// Perform some actions with the `accessToken` and `sessionId`.
return response;
}
Parameters
request: Request
The HTTP request from the client. The URL of the request must match that of the OAuth 2.0 redirect URL.
oauth2Client: OAuth2Client
The absolute URL or path that the client is redirected to after callback handling is complete.