mirror of
https://github.com/umami-software/umami.git
synced 2026-02-09 23:27:12 +01:00
Add OIDC authentification in project
This commit is contained in:
parent
777515f754
commit
7f904d9e92
17 changed files with 547 additions and 26 deletions
40
src/app/api/auth/oidc/authorize/route.ts
Normal file
40
src/app/api/auth/oidc/authorize/route.ts
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
import { NextRequest } from 'next/server';
|
||||
import {
|
||||
getEffectiveOIDCConfig,
|
||||
generateState,
|
||||
generateCodeVerifier,
|
||||
generateCodeChallenge,
|
||||
getAuthorizationUrl,
|
||||
} from '@/lib/oidc';
|
||||
import { json, badRequest } from '@/lib/response';
|
||||
|
||||
export const runtime = 'nodejs';
|
||||
|
||||
export async function GET(request: NextRequest) {
|
||||
const cfg = await getEffectiveOIDCConfig();
|
||||
|
||||
if (!cfg.enabled) {
|
||||
return badRequest('OIDC is not enabled');
|
||||
}
|
||||
|
||||
const url = new URL(request.url);
|
||||
const returnUrl = url.searchParams.get('returnUrl') || '/dashboard';
|
||||
|
||||
const state = await generateState();
|
||||
const codeVerifier = await generateCodeVerifier();
|
||||
const codeChallenge = await generateCodeChallenge(codeVerifier);
|
||||
|
||||
const authUrl = await getAuthorizationUrl(cfg, state, codeChallenge);
|
||||
|
||||
const stateData = Buffer.from(
|
||||
JSON.stringify({
|
||||
state,
|
||||
codeVerifier,
|
||||
returnUrl,
|
||||
}),
|
||||
).toString('base64url');
|
||||
|
||||
const finalAuthUrl = authUrl.replace(`state=${state}`, `state=${stateData}`);
|
||||
|
||||
return json({ url: finalAuthUrl });
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue