Package org.mockserver.oidc
Class OidcAuthorizationStore
java.lang.Object
org.mockserver.oidc.OidcAuthorizationStore
In-memory state backing the mock OIDC authorization-code flow.
Two pieces of state are held:
- Providers — one
OidcAuthorizationStore.Providerper generated OIDC provider, keyed by theauthorizePath/tokenPathit serves. Each provider carries its configuration and theOidcTokenMinter(with its signing key pair) so tokens are minted per request, not pre-baked. The/authorizecallback looks up its provider by the request path to bind the per-request context (redirect_uri, PKCE challenge, scope, nonce) to a newly issued authorization code. - Codes — one
OidcAuthorizationStore.AuthorizationCodeper issued authorization code, keyed by the opaque code string. The/tokencallback consumes the code to validate theauthorization_codegrant (redirect_uri match + optional PKCE), then mints the token response at request time. Codes are single-use and expire afterCODE_TTL_MILLIS.
This is a process-wide singleton (mirroring GrpcHealthRegistry and the other in-memory
registries) because the /authorize and /token class callbacks are instantiated
fresh per request and therefore cannot share instance state.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classImmutable record of an issued authorization code: the redirect_uri it was bound to, optional PKCE challenge, the requested scope, and thenonceechoed from the authorize request.static classRecord of a device code issued by the device-authorization endpoint (RFC 8628).static classRecord of an opaque access token (issued whenOidcProviderConfiguration.isOpaqueAccessToken()) so the introspection endpoint can validate it: the claims to echo back and the absolute expiry.static classImmutable description of a generated OIDC provider. -
Method Summary
Modifier and TypeMethodDescriptionconsumeCode(String code) Consumes (removes and returns) the authorization code, ornullif unknown or expired.consumeDeviceCode(String deviceCode) Consumes (removes and returns) a device code once it has been approved and tokens are minted, so a device code is single-use for the successful exchange.static OidcAuthorizationStorelookupOpaqueToken(String token) Looks up an opaque access token for introspection.peekDeviceCode(String deviceCode) Looks up a device code WITHOUT consuming it (the client polls the same code repeatedly until it is approved).providerForAuthorizePath(String authorizePath) Finds the provider serving the given authorize path, ornullif none registered.providerForDeviceAuthorizationPath(String deviceAuthorizationPath) Finds the provider serving the given device-authorization path, ornullif none registered.providerForIntrospectPath(String introspectPath) Finds the provider serving the given introspection path, ornullif none registered.providerForTokenPath(String tokenPath) Finds the provider serving the given token path, ornullif none registered.voidputCode(String code, OidcAuthorizationStore.AuthorizationCode authorizationCode) voidputDeviceCode(String deviceCode, OidcAuthorizationStore.DeviceCode value) Records a device code issued by the device-authorization endpoint.voidputOpaqueToken(String token, OidcAuthorizationStore.OpaqueToken value) Records an opaque access token (whenOidcProviderConfiguration.isOpaqueAccessToken()) so the introspection endpoint can validate it.voidRegisters (or replaces) the provider serving the given authorize/token paths.voidreset()
-
Method Details
-
getInstance
-
registerProvider
Registers (or replaces) the provider serving the given authorize/token paths. The most recently registered provider for a path wins, so re-runningPUT /mockserver/oidcwith the same paths refreshes the minted tokens. -
providerForAuthorizePath
Finds the provider serving the given authorize path, ornullif none registered. -
providerForTokenPath
Finds the provider serving the given token path, ornullif none registered. -
providerForDeviceAuthorizationPath
public OidcAuthorizationStore.Provider providerForDeviceAuthorizationPath(String deviceAuthorizationPath) Finds the provider serving the given device-authorization path, ornullif none registered. -
providerForIntrospectPath
Finds the provider serving the given introspection path, ornullif none registered. -
putCode
-
consumeCode
Consumes (removes and returns) the authorization code, ornullif unknown or expired. Codes are single-use (removed on consume) and short-lived (older thanCODE_TTL_MILLISis treated as not-found), mirroring real authorization servers. -
putDeviceCode
Records a device code issued by the device-authorization endpoint. Like authorization codes, device codes are TTL-bounded (DEVICE_CODE_TTL_MILLIS); expired entries are evicted on write so the map cannot grow unbounded with codes that are never redeemed. -
peekDeviceCode
Looks up a device code WITHOUT consuming it (the client polls the same code repeatedly until it is approved). Returnsnullwhen unknown or expired (expired entries are evicted). -
consumeDeviceCode
Consumes (removes and returns) a device code once it has been approved and tokens are minted, so a device code is single-use for the successful exchange. Returnsnullwhen unknown or expired. -
putOpaqueToken
Records an opaque access token (whenOidcProviderConfiguration.isOpaqueAccessToken()) so the introspection endpoint can validate it. Bounded by the token's own expiry; expired entries are evicted on write so the map cannot grow unbounded. -
lookupOpaqueToken
Looks up an opaque access token for introspection. Returnsnullwhen unknown; an expired token is returned (so introspection can reportactive:false) but evicted from the map. -
reset
public void reset()
-