Legacy implicit flow
| This documentation was generated with the assistance of AI. Please report any inaccuracies. |
In the implicit grant (response_type=token) the authorization endpoint returns the access token directly in the
fragment of the redirect URI, with no code and no token request. The token then sits in the browser’s address bar and
history, can leak through referrers, logs and injected scripts, cannot be bound to the client, and cannot be refreshed.
OAuth 2.0 Security BCP (RFC 9700) says not to use it and OAuth 2.1 removes it; the authorization code flow with PKCE
replaces it. This server rejects it by default, for every client. Under the opt-in legacy-implicit profile, which must
never be enabled in production, one demo client may use it so that the risk can be shown end to end. The feature page
Implicit flow (legacy demo) and PAR describes the classes; this page follows the flow.
-
Actors: the user with a browser, the demo page
/legacy-implicit/(a single-page app served by the authorization server),auth-server. -
Clients involved:
legacy-implicit-spa, public (none), only grant typeimplicit, no consent, no refresh token, seeded byLegacyImplicitClientSeeder. The admin API refusesimplicitfor any other client (ImplicitClientRefusedException,400 invalid). -
Preconditions: Spring profile
legacy-implicitonauth-serverand the settings ofapplication-legacy-implicit.yml:authserver.legacy-implicit.client-id(legacy-implicit-spa),redirect-uri(AUTHSERVER_LEGACY_IMPLICIT_REDIRECT_URI, defaulthttp://localhost:9000/legacy-implicit/),scopes(documents.read),audience(resource-server) andaccess-token-ttl(PT5M, at mostPT15M). -
Endpoints:
GET /oauth2/authorizewithresponse_type=token,/login, the demo page/legacy-implicit/.
Steps
Without the profile (default)
-
A request to
GET /oauth2/authorizewithresponse_type=tokenreaches Spring Authorization Server’s authorization endpoint, which only knowscode. -
The server answers
400withunsupported_response_type, without redirecting, whatever the client. -
/legacy-implicit/is not served (it ends at the catch-all rule and redirects to/login).
With the legacy-implicit profile
-
At startup
LegacyImplicitClientSeedercreateslegacy-implicit-spa(if missing) with the exact redirect URI, scopes and audience of the settings, and logs a warning. -
The user opens
/legacy-implicit/(served fromclasspath:/legacy-implicit/by a resource handler that exists only under the profile). The page generates a randomstateand redirects to/oauth2/authorize?response_type=token&client_id=legacy-implicit-spa&redirect_uri=…&scope=documents.read&state=…. -
The authorization endpoint runs behind the authorization filter, so a user who is not signed in goes to
/loginfirst and the request resumes afterwards. -
LegacyImplicitProtocolChainCustomizer(aProtocolChainCustomizer, order 4) has addedLegacyImplicitAuthorizationRequestConverterfirst: it takes onlyGETrequests withresponse_type=token; any client butlegacy-implicit-spais refused withunsupported_response_type, and repeatedclient_id,scope,redirect_uriorstateparameters withinvalid_request. -
LegacyImplicitAuthenticationProviderchecks that the client has theimplicitgrant and that the redirect URI matches a registered one exactly; until then errors are thrown and the browser is not redirected. It applies the MFA policy (a client or user that requires a second factor is sent to/login/second-factor). A missingstateor a scope outside the client’s becomes aLegacyImplicitErrorToken. -
It issues the access token through the token generator, with the lifetime capped at
PT15M, stores the authorization and never issues a refresh token. -
LegacyImplicitResponseHandleranswers302toredirect_uriwith the fragmentaccess_token=…&token_type=Bearer&expires_in=…&scope=…&state=…(orerror=…&state=…), withCache-Control: no-storeandReferrer-Policy: no-referrer. Every other result (acoderesponse) is delegated toAuthorizationCodeResponseHandler, the framework’s default, so the code flow is unchanged. -
The demo page reads the fragment, refuses it when
statedoes not match, removes it from the address withhistory.replaceStateand shows the token’s claims.
Why it is deprecated
-
The token travels in a URL: browser history, referrer headers (the response sets
Referrer-Policy: no-referrerto limit this), proxy logs and any script on the page can read it. -
There is no client authentication and no PKCE, so a token injected into the redirect cannot be told apart from a genuine one;
stateonly protects against cross-site request forgery. -
The token cannot be sender-constrained and there is no refresh token, so clients ask for long-lived tokens instead.
-
The authorization code flow with PKCE gives a browser app the same result without these problems (see Authorization code with PKCE for a public client).
Tokens and claims
-
Fragment parameters:
access_token,token_type=Bearer,expires_in,scope,state. No refresh token, no ID token. -
Access token claims:
subthe user,audthe configured audience (resource-server),scopethe granted scopes (documents.read), plus the user’srolesandtenant; nocnf, it is a plain bearer token. Lifetimeaccess-token-ttl, at most 15 minutes.
How it is tested
-
auth-server/boot:ImplicitRejectedIT(default profile:response_type=tokenand an unknown response type answerunsupported_response_type, the demo page is not served);LegacyImplicitIT(profile active: token in the fragment, login redirect, another client refused, unregistered redirect URI not followed, missingstatereturned asinvalid_requestin the fragment, code flow unchanged, demo page served). -
e2e-tests:LegacyImplicitEndToEndITsigns the demo user in through the demo page in headless Chromium, checks the claims and that the fragment is cleared, and checks that another client is refused.