56 lines
1.5 KiB
TypeScript
56 lines
1.5 KiB
TypeScript
// routes/auth/login.ts
|
|
import { deleteCookie, getCookies } from "$std/http/cookie.ts";
|
|
import { define } from "../../utils.ts";
|
|
import { generateNonce } from "../../services/stateMiddleware.ts";
|
|
|
|
const authority = Deno.env.get("AUTHORITY")!;
|
|
const clientId = Deno.env.get("CLIENT_ID")!;
|
|
const redirectUri = Deno.env.get("REDIRECT_URI")!;
|
|
|
|
export const handler = define.handlers({
|
|
async GET(ctx) {
|
|
const nonce = generateNonce();
|
|
if (!authority || !clientId || !redirectUri) {
|
|
console.error("Missing environment variables");
|
|
return new Response("", {
|
|
status: 302,
|
|
headers: {
|
|
"Location": "/",
|
|
},
|
|
});
|
|
}
|
|
|
|
const loginUrl =
|
|
`${authority}?client_id=${clientId}&scope=openid&nonce=${nonce}&response_type=code&prompt=login&redirect_uri=${redirectUri}`;
|
|
|
|
return new Response("", {
|
|
status: 302,
|
|
headers: {
|
|
"Location": loginUrl,
|
|
},
|
|
});
|
|
},
|
|
// async POST(ctx) {
|
|
// const nonce = generateNonce();
|
|
// if (!authority || !clientId || !redirectUri) {
|
|
// console.error("Missing environment variables");
|
|
// return new Response("", {
|
|
// status: 302,
|
|
// headers: {
|
|
// "Location": "/",
|
|
// },
|
|
// });
|
|
// }
|
|
|
|
// const loginUrl =
|
|
// `${authority}?client_id=${clientId}&scope=openid&nonce=${nonce}&response_type=code&prompt=login&redirect_uri=${redirectUri}`;
|
|
|
|
// return new Response("", {
|
|
// status: 302,
|
|
// headers: {
|
|
// "Location": loginUrl,
|
|
// },
|
|
// });
|
|
// },
|
|
});
|