Add Spring Authorization Server project: OAuth2/OIDC provider, client and resource server
Three modules on Spring Boot 4.1.1 with Spring Authorization Server 7.1.1: the provider
itself, a relying party, and an API that trusts its tokens. Client registration, PKCE,
a custom consent page and token customisation, with profiles that make each failure
reproducible.
Every claim is backed by captured output in docs/output/as-*.txt, regenerated by
authorization-server/scripts/run-all.sh. Notable findings, verified against the jars:
- OAuth2AuthorizationServerConfiguration.applyDefaultSecurity(HttpSecurity) was deleted
in 7.0, and both configuration classes moved into spring-security-config
- ClientSettings.requireProofKey flipped from false to true, on the authorization server
(1.5.8 -> 7.1.1) and on the OAuth2 client (6.5.1 -> 7.1.1)
- requireProofKey(false) does not make PKCE optional for a public client; the code
verifier is that client's only authentication at the token endpoint
- MediaTypeRequestMatcher(TEXT_HTML) matches Accept: */*, so the token endpoint answers
API callers with 302 -> /login unless setIgnoredMediaTypes(ALL) is called
Also renames the repository to spring-auth-demo and cross-links the new chapter set from
the existing documentation.
This commit is contained in:
68
docs/output/as-client-credentials-opaque.txt
Normal file
68
docs/output/as-client-credentials-opaque.txt
Normal file
@@ -0,0 +1,68 @@
|
||||
|
||||
------------------------------------------------------------------
|
||||
== POST /oauth2/token grant_type=client_credentials
|
||||
------------------------------------------------------------------
|
||||
$ curl -su demo-service:service-secret -d grant_type=client_credentials \
|
||||
-d scope=orders.read http://localhost:9000/oauth2/token
|
||||
{
|
||||
"access_token": "DE0Ps3Jo6f6IdZ1Jd6bqBg_HnYTatIanVFutxdNihyAkHjlgMHWElxo4TGiWI9oNkxgdOAZZu6vgW9BXZrd_KkYVkKrV238fmHUCD9Xpz0_U3k55Brs9fXcMwxxTKGWa",
|
||||
"scope": "orders.read",
|
||||
"token_type": "Bearer",
|
||||
"expires_in": 599
|
||||
}
|
||||
|
||||
------------------------------------------------------------------
|
||||
== Not a JWT
|
||||
------------------------------------------------------------------
|
||||
The access token is an opaque reference: DE0Ps3Jo6f6IdZ1Jd6bqBg_HnYTatIanVFutxdNihyAkHjlgMHWElxo4TGiWI9oNkxgdOAZZu6vgW9BXZrd_KkYVkKrV238fmHUCD9Xpz0_U3k55Brs9fXcMwxxTKGWa
|
||||
Length 128. It carries no claims; the resource server must introspect it.
|
||||
|
||||
------------------------------------------------------------------
|
||||
== POST /oauth2/introspect
|
||||
------------------------------------------------------------------
|
||||
{
|
||||
"active": true,
|
||||
"sub": "demo-service",
|
||||
"aud": [
|
||||
"demo-service"
|
||||
],
|
||||
"nbf": 1787538776,
|
||||
"scope": "orders.read",
|
||||
"iss": "http://localhost:9000",
|
||||
"exp": 1787539376,
|
||||
"iat": 1787538776,
|
||||
"jti": "9d96a819-4f1e-4efb-8816-4523bb6def61",
|
||||
"client_id": "demo-service",
|
||||
"token_type": "Bearer"
|
||||
}
|
||||
|
||||
------------------------------------------------------------------
|
||||
== Wrong secret
|
||||
------------------------------------------------------------------
|
||||
$ curl -si -u demo-service:WRONG -d grant_type=client_credentials http://localhost:9000/oauth2/token
|
||||
HTTP/1.1 401
|
||||
{"error":"invalid_client"}
|
||||
------------------------------------------------------------------
|
||||
== A grant the client is not registered for
|
||||
------------------------------------------------------------------
|
||||
$ curl -si -u demo-service:service-secret -d grant_type=authorization_code -d code=x http://localhost:9000/oauth2/token
|
||||
HTTP/1.1 400
|
||||
{"error":"invalid_grant"}
|
||||
------------------------------------------------------------------
|
||||
== A scope the client is not registered for
|
||||
------------------------------------------------------------------
|
||||
$ curl -s -u demo-service:service-secret -d grant_type=client_credentials -d scope=orders.write http://localhost:9000/oauth2/token
|
||||
{"error":"invalid_scope"}
|
||||
|
||||
------------------------------------------------------------------
|
||||
== Calling the resource server with the token
|
||||
------------------------------------------------------------------
|
||||
GET /public -> 401
|
||||
WWW-Authenticate: Bearer error="invalid_token", error_description="An error occurred while attempting to decode the Jwt: Malformed token", error_uri="https://tools.ietf.org/html/rfc6750#section-3.1", resource_metadata="http://localhost:8090/.well-known/oauth-protected-resource"
|
||||
|
||||
GET /api/orders -> 401
|
||||
WWW-Authenticate: Bearer error="invalid_token", error_description="An error occurred while attempting to decode the Jwt: Malformed token", error_uri="https://tools.ietf.org/html/rfc6750#section-3.1", resource_metadata="http://localhost:8090/.well-known/oauth-protected-resource"
|
||||
|
||||
GET /api/admin -> 401
|
||||
WWW-Authenticate: Bearer error="invalid_token", error_description="An error occurred while attempting to decode the Jwt: Malformed token", error_uri="https://tools.ietf.org/html/rfc6750#section-3.1", resource_metadata="http://localhost:8090/.well-known/oauth-protected-resource"
|
||||
|
||||
Reference in New Issue
Block a user