Package dev.relism.flash.ext.oidc
Class OidcMiddleware
java.lang.Object
dev.relism.flash.ext.oidc.OidcMiddleware
Request-level OIDC middleware. Exposed in the
FlashContext
for manual use on lambda routes; injected automatically for handlers annotated with
Authenticated, RolesAllowed or ScopesAllowed.
Resolution order on each request:
Authorization: Bearer ...header — validated via JWKS (JwtValidator).oidc_sessioncookie — looked up inOidcSessionStore; transparently refreshed if the access token is expired.- Browser clients (no
Accept: application/json) → redirect to{routePrefix}/login?redirect={path}. - API clients → 401.
// Manual use on a lambda route:
OidcMiddleware oidc = app.ctx().require(OidcMiddleware.class);
app.get("/api/me", (req, res) -> ClaimsHolder.claim("sub"), oidc.protect());
app.delete("/admin/users/{id}", handler, oidc.requireRole("admin"));
-
Method Summary
Modifier and TypeMethodDescriptiondev.relism.flash.routing.Middlewareauthorize(dev.relism.flash.ext.oidc.OidcAuthPolicy policy) Compiled authorization policy path used by annotation-driven mounting.issuer()OIDC issuer this middleware validates tokens against — theissclaim it enforces.dev.relism.flash.routing.Middlewareoptional()Silently populatesClaimsHolderif a valid bearer token or session cookie is present, but never rejects or redirects unauthenticated requests.dev.relism.flash.routing.Middlewareprotect()Validates the bearer token or session cookie.dev.relism.flash.routing.MiddlewareLikeprotect(), but a 401 challenge also carriesresource_metadata(RFC 9728 §5.1), resolved against this request's own scheme/host exactly likeOidcExtension's redirect URIs.dev.relism.flash.routing.MiddlewarerequireAnyScope(String... scopes) Requires at least one of the listed scopes to be present in the token.dev.relism.flash.routing.MiddlewarerequireRole(String... roles) Likeprotect()but also enforces that the caller holds at least one of the given roles (OR semantics).dev.relism.flash.routing.MiddlewarerequireScopes(String... scopes) Requires all listed scopes to be present in the token.The single configured claim path used by every transport for role checks.static StringselfOrigin(dev.relism.flash.models.Request req, String fallbackScheme) scheme://hostclients actually reach this app on — the basis for every absolute URL it publishes about itself (OAuth2redirect_uri, the RFC 9728 resource identifier and theresource_metadatachallenge).Scheme used to build this app's own absolute URLs — seeOidcConfig.selfScheme().
-
Method Details
-
rolesClaimPath
The single configured claim path used by every transport for role checks. -
protect
public dev.relism.flash.routing.Middleware protect()Validates the bearer token or session cookie. Browser clients are redirected to the login page on failure; API clients receive 401. -
protect
Likeprotect(), but a 401 challenge also carriesresource_metadata(RFC 9728 §5.1), resolved against this request's own scheme/host exactly likeOidcExtension's redirect URIs.resourceMetadataPathis an absolute path (e.g."/.well-known/oauth-protected-resource/mcp"); passnullfor plain challenges. Used byflash-ext-mcpto make its Protected Resource Metadata document discoverable straight from theWWW-Authenticateheader, per the MCP Authorization spec. -
issuer
OIDC issuer this middleware validates tokens against — theissclaim it enforces. -
selfScheme
Scheme used to build this app's own absolute URLs — seeOidcConfig.selfScheme(). -
optional
public dev.relism.flash.routing.Middleware optional()Silently populatesClaimsHolderif a valid bearer token or session cookie is present, but never rejects or redirects unauthenticated requests. Use this on public routes that want to personalise the response when the user happens to be logged in (e.g. showing a username on a landing page).app.get("/", handler, oidc.optional()); // Inside handler: ClaimsHolder.user() is non-null iff the user is logged in. -
authorize
public dev.relism.flash.routing.Middleware authorize(dev.relism.flash.ext.oidc.OidcAuthPolicy policy) Compiled authorization policy path used by annotation-driven mounting. The policy is immutable and built once at boot. -
requireRole
Likeprotect()but also enforces that the caller holds at least one of the given roles (OR semantics). Roles are extracted viaOidcConfig.rolesClaimPath(). -
requireScopes
Requires all listed scopes to be present in the token. Scopes are resolved from configured claim paths (default:scope,scp). -
requireAnyScope
Requires at least one of the listed scopes to be present in the token. Scopes are resolved from configured claim paths (default:scope,scp). -
selfOrigin
scheme://hostclients actually reach this app on — the basis for every absolute URL it publishes about itself (OAuth2redirect_uri, the RFC 9728 resource identifier and theresource_metadatachallenge). Behind a reverse proxy the request's ownHostis the upstream address the proxy dialled, soX-Forwarded-Host/-Protowin whenever present: without them the app would name an address no client can resolve, and OAuth2 discovery fails with no error anyone can trace back to here. Trusted unconditionally — a caller able to reach this app without passing the proxy can do worse than spoof a self URL.
-