This example shows how to build a simple REST service with Jetty embedded, how to create the same service using Spring Boot and Jetty embedded, and how to secure the service with Okta and Auth0.
Please read Get Started with Jetty, Java, and OAuth to see how this example was created.
Prerequisites: Java 17, HTTPie, and an Okta Developer Account.
Okta has Authentication and User Management APIs that reduce development time with instant-on, scalable user infrastructure. Okta's intuitive API and expert support make it easy for developers to authenticate, manage, and secure users and roles in any application.
Clone this repository to your local hard drive using Git.
git clone https://github.com/oktadev/okta-spring-boot-jetty-example.git spring-boot-jetty
This repository has several projects:
maven-jetty
: web service using Mavengradle-jetty
: web service using Gradlespring-boot-jetty-maven-no-auth
: web service using Spring Boot and Mavenspring-boot-jetty-maven-okta
: web service using Spring Boot and Maven secured with Oktaspring-boot-jetty-maven-auth0
: web service using Spring Boot and Maven secured with Auth0
To run the Okta example, you will need to create an OIDC Application in Okta.
- Log in to your developer account on developer.okta.com.
- Navigate to Applications and click on Add Application.
- Select Web and click Next.
- Give the application a name (e.g.,
Spring Boot Jetty
) and add the following as Login redirect URIs:http://localhost:8080/login/oauth2/code/okta
https://oidcdebugger.com/debug
Go to Security > API and copy the Issuer URI
from the default Authorization Server into spring-boot-jetty-maven-okta/src/main/resources/application.properties
:
okta.oauth2.issuer=https://<your-okta-domain>/oauth2/default
Then, modify spring-boot-jetty-maven-okta/pom.xml
to uncomment the Okta Spring Boot starter.
Now, you should now be able to run the Spring Boot app from a shell with:
cd spring-boot-jetty-maven-okta
./mvnw spring-boot:run
Install the Auth0 CLI and run auth0 login
in a terminal.
You need to find your Auth0 domain. One way to do this is to use the following command.
auth0 tenants list
Take the resulting domain and replace the placeholder in the issuer
property in the spring-boot-jetty-maven-auth0/src/main/resources/application.properties
file. Don't remove the trailing slash!
okta.oauth2.issuer=https://<your-auth0-domain>/
okta.oauth2.audience=https://<your-auth0-domain>/api/v2/
Then, modify spring-boot-jetty-maven-auth0/pom.xml
to uncomment the Okta Spring Boot starter.
Now, you should now be able to run the Spring Boot app from a shell with:
cd spring-boot-jetty-maven-auth0
./mvnw spring-boot:run
This example uses the following open source libraries:
Please post any questions as comments on the blog post, or visit our Okta Developer Forums.
Apache 2.0, see LICENSE.