------------------------------------------------------------------ == 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": "eyJraWQiOiIyNDgwNWM5Ni02MGY1LTQ5MDItYTczYi03ODgxYmFkNWY5ZGMiLCJhbGciOiJSUzI1NiJ9.eyJzdWIiOiJkZW1vLXNlcnZpY2UiLCJhdWQiOiJkZW1vLXNlcnZpY2UiLCJuYmYiOjE3ODc1Mzg3MzksInNjb3BlIjpbIm9yZGVycy5yZWFkIl0sImlzcyI6Imh0dHA6Ly9sb2NhbGhvc3Q6OTAwMCIsImV4cCI6MTc4NzUzOTMzOSwiaWF0IjoxNzg3NTM4NzM5LCJqdGkiOiIzN2E0NTlmMS0xZjdlLTQ5ZTktOWQyNi01YmY0MjM5YmM1ZTkifQ.UxWq_Cs1bBhqQicgcLU7Z-vYW-jWxuVbrmco1gmXM8cxRvRjXoNpaDkYCiTI51gu21K9mXsOxf45l5dg7Rh9Gku7fNWJeKcWll5Ekcjpgq9msCwjLNPVxbuDVV8K-2f8OcPJ1Y6ojDtqxQq9RCBKEMxuBhl1Plz8nMjUYUm1A-njz43wL9SDJslz2xiIgoEkLkiRyVdk4ArzWGOQ4WLKR_y-bIn0dIhyTh4bVDy4rf2LTFqyPl_ZTCAH_ZUqXZuJhFn73MpxEaavwIHl-b8EDCpyk2vCUQnSykIMEaAbEPs0JBNaBpah-lPR0FFZIr2vZQxI4xpxButI98W2d9CtBQ", "scope": "orders.read", "token_type": "Bearer", "expires_in": 599 } ------------------------------------------------------------------ == JOSE header ------------------------------------------------------------------ { "alg": "RS256", "kid": "24805c96-60f5-4902-a73b-7881bad5f9dc" } ------------------------------------------------------------------ == Claims ------------------------------------------------------------------ { "aud": "demo-service", "exp": 1787539339, "iat": 1787538739, "iss": "http://localhost:9000", "jti": "37a459f1-1f7e-49e9-9d26-5bf4239bc5e9", "nbf": 1787538739, "scope": [ "orders.read" ], "sub": "demo-service" } ------------------------------------------------------------------ == 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: the required audience orders-api is missing", 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: the required audience orders-api is missing", 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: the required audience orders-api is missing", error_uri="https://tools.ietf.org/html/rfc6750#section-3.1", resource_metadata="http://localhost:8090/.well-known/oauth-protected-resource"