------------------------------------------------------------------ == Public client, failed authentication at the token endpoint [acceptall profile: setIgnoredMediaTypes NOT called] ------------------------------------------------------------------ A public client authenticates at /oauth2/token by presenting a code_verifier. With no verifier there is nothing to authenticate with, so the request falls through to the AuthenticationEntryPoint - and which entry point runs depends on the Accept header. --- Accept: */* (curl's default, and most HTTP clients') $ curl -H 'Accept: */*' -d grant_type=authorization_code -d code=bogus \ -d client_id=demo-spa http://localhost:9000/oauth2/token HTTP/1.1 302 Location: http://localhost:9000/login --- Accept: application/json $ curl -H 'Accept: application/json' -d grant_type=authorization_code -d code=bogus \ -d client_id=demo-spa http://localhost:9000/oauth2/token HTTP/1.1 401 --- Accept: text/html (a browser) $ curl -H 'Accept: text/html' -d grant_type=authorization_code -d code=bogus \ -d client_id=demo-spa http://localhost:9000/oauth2/token HTTP/1.1 302 Location: http://localhost:9000/login ------------------------------------------------------------------ == Confidential client with a wrong secret, for contrast ------------------------------------------------------------------ This never reaches the entry point: OAuth2ClientAuthenticationFilter writes the error itself, so the Accept header makes no difference. HTTP/1.1 401 ------------------------------------------------------------------ == Public client, failed authentication at the token endpoint [default profile: setIgnoredMediaTypes(ALL) called] ------------------------------------------------------------------ A public client authenticates at /oauth2/token by presenting a code_verifier. With no verifier there is nothing to authenticate with, so the request falls through to the AuthenticationEntryPoint - and which entry point runs depends on the Accept header. --- Accept: */* (curl's default, and most HTTP clients') $ curl -H 'Accept: */*' -d grant_type=authorization_code -d code=bogus \ -d client_id=demo-spa http://localhost:9000/oauth2/token HTTP/1.1 401 --- Accept: application/json $ curl -H 'Accept: application/json' -d grant_type=authorization_code -d code=bogus \ -d client_id=demo-spa http://localhost:9000/oauth2/token HTTP/1.1 401 --- Accept: text/html (a browser) $ curl -H 'Accept: text/html' -d grant_type=authorization_code -d code=bogus \ -d client_id=demo-spa http://localhost:9000/oauth2/token HTTP/1.1 302 Location: http://localhost:9000/login ------------------------------------------------------------------ == Confidential client with a wrong secret, for contrast ------------------------------------------------------------------ This never reaches the entry point: OAuth2ClientAuthenticationFilter writes the error itself, so the Accept header makes no difference. HTTP/1.1 401