fix(oidc): migrate OIDC endpoints and internal handlers to use typedserver IRequestContext and update dependencies
This commit is contained in:
@@ -3,6 +3,6 @@
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@idp.global/idp.global',
|
||||
version: '1.14.0',
|
||||
version: '1.14.1',
|
||||
description: 'An identity provider software managing user authentications, registrations, and sessions.'
|
||||
}
|
||||
|
||||
+12
-12
@@ -28,40 +28,40 @@ export const runCli = async () => {
|
||||
typedserver.options.spaFallback = true;
|
||||
|
||||
// OIDC Discovery endpoint
|
||||
typedserver.addRoute('/.well-known/openid-configuration', 'GET', async (req) => {
|
||||
typedserver.addRoute('/.well-known/openid-configuration', 'GET', async (ctx) => {
|
||||
return new Response(JSON.stringify(reception.oidcManager.getDiscoveryDocument()), {
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
});
|
||||
});
|
||||
|
||||
// JWKS endpoint
|
||||
typedserver.addRoute('/.well-known/jwks.json', 'GET', async (req) => {
|
||||
typedserver.addRoute('/.well-known/jwks.json', 'GET', async (ctx) => {
|
||||
return new Response(JSON.stringify(reception.oidcManager.getJwks()), {
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
});
|
||||
});
|
||||
|
||||
// OAuth Authorization endpoint
|
||||
typedserver.addRoute('/oauth/authorize', 'GET', async (req) => {
|
||||
return reception.oidcManager.handleAuthorize(req);
|
||||
typedserver.addRoute('/oauth/authorize', 'GET', async (ctx) => {
|
||||
return reception.oidcManager.handleAuthorize(ctx);
|
||||
});
|
||||
|
||||
// OAuth Token endpoint
|
||||
typedserver.addRoute('/oauth/token', 'POST', async (req) => {
|
||||
return reception.oidcManager.handleToken(req);
|
||||
typedserver.addRoute('/oauth/token', 'POST', async (ctx) => {
|
||||
return reception.oidcManager.handleToken(ctx);
|
||||
});
|
||||
|
||||
// OAuth UserInfo endpoint (GET and POST)
|
||||
typedserver.addRoute('/oauth/userinfo', 'GET', async (req) => {
|
||||
return reception.oidcManager.handleUserInfo(req);
|
||||
typedserver.addRoute('/oauth/userinfo', 'GET', async (ctx) => {
|
||||
return reception.oidcManager.handleUserInfo(ctx);
|
||||
});
|
||||
typedserver.addRoute('/oauth/userinfo', 'POST', async (req) => {
|
||||
return reception.oidcManager.handleUserInfo(req);
|
||||
typedserver.addRoute('/oauth/userinfo', 'POST', async (ctx) => {
|
||||
return reception.oidcManager.handleUserInfo(ctx);
|
||||
});
|
||||
|
||||
// OAuth Revocation endpoint
|
||||
typedserver.addRoute('/oauth/revoke', 'POST', async (req) => {
|
||||
return reception.oidcManager.handleRevoke(req);
|
||||
typedserver.addRoute('/oauth/revoke', 'POST', async (ctx) => {
|
||||
return reception.oidcManager.handleRevoke(ctx);
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
@@ -95,9 +95,8 @@ export class OidcManager {
|
||||
/**
|
||||
* Handle the authorization endpoint request
|
||||
*/
|
||||
public async handleAuthorize(request: Request): Promise<Response> {
|
||||
const url = new URL(request.url);
|
||||
const params = url.searchParams;
|
||||
public async handleAuthorize(ctx: plugins.typedserver.IRequestContext): Promise<Response> {
|
||||
const params = ctx.url.searchParams;
|
||||
|
||||
// Extract authorization request parameters
|
||||
const clientId = params.get('client_id');
|
||||
@@ -196,21 +195,21 @@ export class OidcManager {
|
||||
/**
|
||||
* Handle the token endpoint request
|
||||
*/
|
||||
public async handleToken(request: Request): Promise<Response> {
|
||||
public async handleToken(ctx: plugins.typedserver.IRequestContext): Promise<Response> {
|
||||
// Parse form data
|
||||
const contentType = request.headers.get('content-type');
|
||||
const contentType = ctx.headers.get('content-type');
|
||||
if (!contentType?.includes('application/x-www-form-urlencoded')) {
|
||||
return this.tokenErrorResponse('invalid_request', 'Content-Type must be application/x-www-form-urlencoded');
|
||||
}
|
||||
|
||||
const formData = await request.formData();
|
||||
const formData = await ctx.formData();
|
||||
const grantType = formData.get('grant_type') as string;
|
||||
|
||||
// Extract client credentials from Basic auth or form
|
||||
let clientId = formData.get('client_id') as string;
|
||||
let clientSecret = formData.get('client_secret') as string;
|
||||
|
||||
const authHeader = request.headers.get('authorization');
|
||||
const authHeader = ctx.headers.get('authorization');
|
||||
if (authHeader?.startsWith('Basic ')) {
|
||||
const base64 = authHeader.substring(6);
|
||||
const decoded = Buffer.from(base64, 'base64').toString('utf-8');
|
||||
@@ -469,9 +468,9 @@ export class OidcManager {
|
||||
/**
|
||||
* Handle the userinfo endpoint
|
||||
*/
|
||||
public async handleUserInfo(request: Request): Promise<Response> {
|
||||
public async handleUserInfo(ctx: plugins.typedserver.IRequestContext): Promise<Response> {
|
||||
// Get access token from Authorization header
|
||||
const authHeader = request.headers.get('authorization');
|
||||
const authHeader = ctx.headers.get('authorization');
|
||||
if (!authHeader?.startsWith('Bearer ')) {
|
||||
return new Response(JSON.stringify({ error: 'invalid_token' }), {
|
||||
status: 401,
|
||||
@@ -575,8 +574,8 @@ export class OidcManager {
|
||||
/**
|
||||
* Handle the revocation endpoint
|
||||
*/
|
||||
public async handleRevoke(request: Request): Promise<Response> {
|
||||
const formData = await request.formData();
|
||||
public async handleRevoke(ctx: plugins.typedserver.IRequestContext): Promise<Response> {
|
||||
const formData = await ctx.formData();
|
||||
const token = formData.get('token') as string;
|
||||
const tokenTypeHint = formData.get('token_type_hint') as string;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user