This example code is used in the blog post found here
This example takes you from using Spring Security for basic authentication, to form authentication and finally to integrating with Okta using OAuth 2.0.
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.
In the first two examples, you can simply switch into the basic-auth
and form-auth
folders respectively and run:
./gradlew bootRun
For the final example, switch into the oauth-okta
folder.
You'll need to create an Okta org here.
Follow the instructions in the blog post for creating an application in Okta.
Setup src/main/resources/application.yml
like so:
okta:
oauth2:
issuer: https://okta.okta.com/oauth2/default
client-id: {yourClientID}
client-secret: {yourClientSecret}
spring:
thymeleaf:
cache: false
Then, you can run the app as before:
./gradlew bootRun
If you'd like to learn more about Spring Boot, Spring Security, or secure authentication, 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 page.
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.