import { DenoKVOAuth } from "https://deno.land/x/fathym_common@v0.0.143/src/src.deps.ts";
const { createHelpers } = DenoKVOAuth;
Creates the full set of helpers with the given OAuth configuration and options.
Examples
Example 1
Example 1
// server.ts
import {
createGitHubOAuthConfig,
createHelpers,
} from "https://deno.land/x/deno_kv_oauth@$VERSION/mod.ts";
const {
signIn,
handleCallback,
signOut,
getSessionId,
} = createHelpers(createGitHubOAuthConfig(), {
cookieOptions: {
name: "__Secure-triple-choc",
domain: "news.site",
},
});
async function handler(request: Request) {
const { pathname } = new URL(request.url);
switch (pathname) {
case "/oauth/signin":
return await signIn(request);
case "/oauth/callback":
const { response } = await handleCallback(request);
return response;
case "/oauth/signout":
return await signOut(request);
case "/protected-route":
return await getSessionId(request) === undefined
? new Response("Unauthorized", { status: 401 })
: new Response("You are allowed");
default:
return new Response(null, { status: 404 });
}
}
Deno.serve(handler);
Parameters
oauthConfig: OAuth2ClientConfig
optional
options: CreateHelpersOptions