A basic sample to show how to use Spring Boot as an OAuth framework for managing JWT validation.
After validating the JWT, the controller then uses scopes and claims from the API when serving data.
First ensure that a Java Development Kit of 17 or later is installed.
Then edit the application.yml file to point to a valid issuer URI:
spring:
security:
oauth2:
resourceserver:
jwt:
issuer-uri: https://idsvr.example.com/oauth/v2/oauth-anonymous
Build and run the API with the following command, and the API will listen on port 8080 by default:
./gradlew bootRun
The API requires a valid JWT access token, or it will return a 401 response:
curl -i http://localhost:8080/services -H "Authorization: Bearer eyJraWQiOiIxNzQwNDU5OTIxIiwieDV0..."
The JWT access token must have a services:read
scope or the API will return a 403 response.
If the access token includes a claim containing role=developer
, then the API returns additional data.
- See the Spring Boot API Tutorial for a technical walkthrough
- Please visit curity.io for more information about the Curity Identity Server.