chore: Remove deno_kv_auth plugin (#1910)
This commit is contained in:
@@ -1,72 +0,0 @@
|
||||
import {
|
||||
createAuth0OAuthConfig,
|
||||
createDiscordOAuthConfig,
|
||||
createDropboxOAuthConfig,
|
||||
createFacebookOAuthConfig,
|
||||
createGitHubOAuthConfig,
|
||||
createGitLabOAuthConfig,
|
||||
createGoogleOAuthConfig,
|
||||
createNotionOAuthConfig,
|
||||
createOktaOAuthConfig,
|
||||
createPatreonOAuthConfig,
|
||||
createSlackOAuthConfig,
|
||||
createSpotifyOAuthConfig,
|
||||
createTwitterOAuthConfig,
|
||||
getRequiredEnv,
|
||||
handleCallback,
|
||||
type OAuth2ClientConfig,
|
||||
signIn,
|
||||
signOut,
|
||||
} from "https://deno.land/x/deno_kv_oauth@v0.9.1/mod.ts";
|
||||
import type { Handler } from "$fresh/server.ts";
|
||||
|
||||
export {
|
||||
createAuth0OAuthConfig,
|
||||
createDiscordOAuthConfig,
|
||||
createDropboxOAuthConfig,
|
||||
createFacebookOAuthConfig,
|
||||
createGitHubOAuthConfig,
|
||||
createGitLabOAuthConfig,
|
||||
createGoogleOAuthConfig,
|
||||
createNotionOAuthConfig,
|
||||
createOktaOAuthConfig,
|
||||
createPatreonOAuthConfig,
|
||||
createSlackOAuthConfig,
|
||||
createSpotifyOAuthConfig,
|
||||
createTwitterOAuthConfig,
|
||||
getRequiredEnv,
|
||||
type OAuth2ClientConfig,
|
||||
};
|
||||
|
||||
/** @see {@link https://fresh.deno.dev/docs/examples/using-deno-kv-oauth} */
|
||||
export function createRoutes<T extends string = "/oauth">(
|
||||
oauthConfig: OAuth2ClientConfig,
|
||||
/** Parent path for sign-in, callback and sign-out pages. */
|
||||
oauthPath = "/oauth" as T,
|
||||
): [
|
||||
{ path: `${T}/signin`; handler: Handler },
|
||||
{ path: `${T}/callback`; handler: Handler },
|
||||
{ path: `${T}/signout`; handler: Handler },
|
||||
] {
|
||||
return [
|
||||
{
|
||||
path: `${oauthPath}/signin`,
|
||||
handler: async (req) => await signIn(req, oauthConfig),
|
||||
},
|
||||
{
|
||||
path: `${oauthPath}/callback`,
|
||||
handler: async (req) => {
|
||||
// Return object also includes `accessToken` and `sessionId` properties.
|
||||
const { response } = await handleCallback(
|
||||
req,
|
||||
oauthConfig,
|
||||
);
|
||||
return response;
|
||||
},
|
||||
},
|
||||
{
|
||||
path: `${oauthPath}/signout`,
|
||||
handler: signOut,
|
||||
},
|
||||
];
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
// Copyright 2023 the Deno authors. All rights reserved. MIT license.
|
||||
import { assertArrayIncludes } from "$std/testing/asserts.ts";
|
||||
import { colors } from "$fresh/src/server/deps.ts";
|
||||
import { createRoutes } from "$fresh/plugins/kv_oauth.ts";
|
||||
|
||||
function randomOAuthConfig() {
|
||||
return {
|
||||
clientId: crypto.randomUUID(),
|
||||
clientSecret: crypto.randomUUID(),
|
||||
authorizationEndpointUri: `http://${crypto.randomUUID()}.com/authorize`,
|
||||
tokenUri: `http://${crypto.randomUUID()}.com/token`,
|
||||
};
|
||||
}
|
||||
|
||||
// @ts-ignore openKv is only available with --unstable
|
||||
const isKvEnabled = typeof Deno.openKv === "function";
|
||||
if (!isKvEnabled) {
|
||||
console.log(
|
||||
colors.yellow(`Skipping Deno KV tests. Pass "--unstable" to run them.`),
|
||||
);
|
||||
}
|
||||
|
||||
Deno.test({
|
||||
name: "createRoutes() has all handlers defined with default OAuth path",
|
||||
ignore: !isKvEnabled,
|
||||
fn: () => {
|
||||
const routes = createRoutes(randomOAuthConfig());
|
||||
assertArrayIncludes(routes.map((route) => route.path), [
|
||||
"/oauth/signin",
|
||||
"/oauth/callback",
|
||||
"/oauth/signout",
|
||||
]);
|
||||
},
|
||||
});
|
||||
|
||||
Deno.test({
|
||||
name: "createRoutes() has all handlers defined with set OAuth path",
|
||||
ignore: !isKvEnabled,
|
||||
fn: () => {
|
||||
const oauthPath = "/" + crypto.randomUUID();
|
||||
const routes = createRoutes(randomOAuthConfig(), oauthPath);
|
||||
assertArrayIncludes(routes.map((route) => route.path), [
|
||||
oauthPath + "/signin",
|
||||
oauthPath + "/callback",
|
||||
oauthPath + "/signout",
|
||||
]);
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user