Skip to content

Latest commit

 

History

History
127 lines (90 loc) · 2.4 KB

README.adoc

File metadata and controls

127 lines (90 loc) · 2.4 KB

Java OAuth Examples

See this demo script to learn how these apps were created.

Get the Code

Clone this repo to begin.

git clone https://github.com/oktadev/auth0-java-oauth-examples.git
cd auth0-java-oauth-examples

Configure Spring Boot

Create an OIDC application using the Auth0 CLI.

auth0 apps create \
  --name "Spring Boot" \
  --description "Spring Boot Example" \
  --type regular \
  --callbacks http://localhost:8080/login/oauth2/code/okta \
  --logout-urls http://localhost:8080 \
  --reveal-secrets

Update application.properties to use these values.

okta.oauth2.issuer=https://<your-auth0-domain>/
okta.oauth2.audience=${okta.oauth2.issuer}api/v2/
okta.oauth2.client-id=<client-id>
okta.oauth2.client-secret=<client-secret>

Start the app:

gradle bootRun

API Access with OAuth 2.0

Create an access token using Auth0’s CLI:

auth0 test token -a https://<your-auth0-domain>/api/v2/

Set the access token as an environment variable:

TOKEN=eyJhbGciOiJSUzI1NiIsInR5cCI6...

Access your resource server using HTTPie:

http :8080/hello "Authorization: Bearer $TOKEN"

Configure Quarkus

Update quarkus/src/main/resources/application.properties to use your Auth0 domain.

quarkus.oidc.auth-server-url=https://<your-auth0-domain>

Run the app:

mvn quarkus:dev

Verify you can access it with an access token.

http :8080/hello "Authorization: Bearer $TOKEN"

Configure Micronaut

Update micronaut/src/main/resources/application.yml to use your Auth0 domain.

micronaut.security.token.jwt.signatures.jwks.auth0.url: https://<your-auth0-domain>/.well-known/jwks.json

Run the app:

mvn mn:run

Verify you can access it with an access token.

http :8080/hello "Authorization: Bearer $TOKEN"

Learn More

For more details on Java and OAuth, please read OAuth for Java Developers.