feat: add authentication
This commit is contained in:
29
routes/api/auth/login.ts
Normal file
29
routes/api/auth/login.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import { Handlers } from "$fresh/server.ts";
|
||||
import { oauth2Client } from "@lib/auth.ts";
|
||||
import { sha256 } from "@lib/string.ts";
|
||||
import { setCookie } from "https://deno.land/std@0.197.0/http/cookie.ts";
|
||||
|
||||
export const codeChallengeMap = new Map();
|
||||
|
||||
export const handler: Handlers = {
|
||||
async GET() {
|
||||
const { codeVerifier, uri } = await oauth2Client.code.getAuthorizationUri();
|
||||
|
||||
const codeChallenge = uri.searchParams.get("code_challenge");
|
||||
if (!codeChallenge) return new Response();
|
||||
|
||||
codeChallengeMap.set(codeChallenge, codeVerifier);
|
||||
|
||||
const headers = new Headers();
|
||||
setCookie(headers, {
|
||||
name: "code_challenge",
|
||||
value: codeChallenge,
|
||||
});
|
||||
headers.append("location", uri.href);
|
||||
|
||||
return new Response(null, {
|
||||
headers,
|
||||
status: 302,
|
||||
});
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user