You can find the blog post that this source code backs here
This example leverages the information found in the OidcUser
object that is automatically injected after authenticating
using OpenId Connect.
It uses JPA to add user activity information to a MySQL database.
In order to use this example, you'll need to create an Okta Org here
You'll also need to create an application.properties
file in src/main/resources
:
okta.oauth2.issuer={authServerUrl}
okta.oauth2.clientId={clientId}
okta.oauth2.clientSecret={clientSecret}
## MySQL
spring.datasource.url=jdbc:mysql://{mysql url}:{mysql port}/{dbName}
spring.datasource.username={dbUser}
spring.datasource.password={dbPassword}
# drop in to create the table, good for testing, comment this in production. This will create the table for you on each load of application, so you may want to comment this out after the first load
spring.jpa.hibernate.ddl-auto=create
Once you've created an Okta org, configured it according to the blog post and set your application.properties
file, you can run the application like so:
mvn spring-boot:run
To learn more about the Okta OIDC and Single Sign-On (SSO), check out these links:
To learn more about JPA and Hibernate, check these out:
If you'd like to learn more about Spring Boot, Spring Security, or secure user management, check out any of these great tutorials:
- Get Started with Spring Boot, OAuth 2.0, and Okta
- Add Single Sign-On to Your Spring Boot Web App in 15 Minutes
- Secure Your Spring Boot Application with Multi-Factor Authentication
- Build a Secure API with Spring Boot and GraphQL
If you want to dive deeper, take a look at the Okta Spring Boot Starter GitHub Project.
If you have any questions about this post, please add a comment below. For more awesome content, follow @oktadev on Twitter, like us on Facebook, or subscribe to our YouTube channel.