You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To support DPoP, we need to update oidc-spa/backend and introduce a breaking change.
If we're going to do that, let's redisign the API to make it's usage less boilerplaty and try avoid having to export specific adapters for express, Hono, NestJS, tRCP, socket.io ect.
We also want to have a mock mode like in the client side API.
Here is an aspirational API example with Hono:
// src/auth.tsimport{oidcStart}from"oidc-start/server";import{z}from"zod";import{HTTPException}from"hono/http-exception";importtype{HonoRequest}from"hono";exportconst{ bootstrapAuth, requireAuth, isAnonymous }=oidcStart.withExpectedDecodedAccessTokenShape({decodedAccessTokenSchema: z.object({sub: z.string(),realm_access: z.object({roles: z.array(z.string())})})})// Depending if the user is using vanilla express, hono, trpc, they will be able to // integrate..withFrameworkIntegration<HonoRequest>({getRequestHeader: ({ req, headerName })=>req.header(headerName),createHttp401Exception: ({ cause })=>newHTTPException(401,cause)})// Let user declare custom logic for authorization.withAuthorizationCheck<{requiredRole?: "realm-admin"|"support-staff"}>({checkAuthorization: ({
requiredRole,// Inherit the type declared in withExpectedDecodedAccessTokenShape
decodedAccessToken
})=>{if(!requiredRole){return;}if(!decodedAccessToken.realm_access.roles.includes(requiredRole)){thrownewHTTPException(403,`Missing role ${requiredRole}`);}}}).createUtils();bootstrapAuth(process.env.AUTH_USE_MOCK ?
{implementation: "mock",// Option 1: No token verification, trust payloadmockBehavior: "unsafe decode only",// Option 2: Pretend every request bears a static identity/* mockBehavior: "use static identity", decodedAccessToken_mock: { sub: "123", ream_access: { roles: ["realm-admin"] } } */}:
{implementation: "real",issuerUri: "https://auth.my-company.com/realms/myrealm",expectedAudience: "account",requireDPoP: true});// ====================================// src/main.tsimport{requireAuth,isAnonymous}from"@/auth";//...app.openapi(route,asyncc=>{const{ decodedAccessToken }=awaitrequireAuth({req: c.req,requiredRole: "realm-admin"});consttodos=awaitgetUserTodoStore(decodedAccessToken.sub).getAll();returnc.json(todos);});// With middlewareapp.middleware(async(c,next)=>{letuserId: string|undefined=undefined;if(!isAnonymous(c.req)){const{ decodedAccessToken }=awaitrequireAuth({req: c.req});userId=decodedAccessToken.sub;}returnnext(c,{ userId });});app.openapi(route,async({ req, userId })=>{if(userId===undefined){// Process the request as anonymous}consttodos=awaitgetUserTodoStore(userId).getAll();returnc.json(todos);});
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
To support DPoP, we need to update
oidc-spa/backendand introduce a breaking change.If we're going to do that, let's redisign the API to make it's usage less boilerplaty and try avoid having to export specific adapters for express, Hono, NestJS, tRCP, socket.io ect.
We also want to have a mock mode like in the client side API.
Here is an aspirational API example with Hono:
All reactions