This is the completed project corresponding to the guide "Protect your API endpoints".
- Java 25 or later
- An Okta org with a custom authorization server (the
defaultone works). The org authorization server cannot issue access tokens that third-party APIs can validate. - A custom scope named
messages.readon that authorization server, and an access policy with a rule that grants it. Without a policy, no tokens are issued.
This API has no login page of its own. To use it, run it with a front-end that signs the user in and sends the access token to the API. Use okta-spring-boot-sample-app, which is set up to call this API.
Copy the file .env.example to .env and set:
ISSUER: the issuer URI of your authorization server, for examplehttps://{yourOktaDomain}/oauth2/default.AUDIENCE: the audience configured on that authorization server, for exampleapi://default.
Load the variables and run the app (it starts on port 8081):
set -a && source .env && set +a
./mvnw spring-boot:run- Keep the API running on port 8081.
- In a second terminal, run okta-spring-boot-sample-app using the same
ISSUER. - Open
http://localhost:8080, sign in, and click Messages. The app calls/api/messageswith your access token and shows the response.