A Quick Guide to Okta and Spring Boot
In this article, take a look at a tutorial on how to install the Okta CLI and create a Spring Boot app.
Join the DZone community and get the full member experience.
Join For FreeMeet Okta CLI, a new tool created here at Okta. Designed to streamline the creation of new Okta accounts, register apps, and get started, Okta CLI is a one-stop shop for all your Okta needs!
To show you just how Okta CLI can benefit you, I created a screencast. Feel free to watch it here.
For those that would rather read than watch, please read on.
Install the Okta CLI
You can find the website for the Okta CLI at cli.okta.com. This site has instructions on how to use common package managers on macOS, Windows, and Linux. You can also use cURL:
curl https://raw.githubusercontent.com/oktadeveloper/okta-cli/master/cli/src/main/scripts/install.sh | bash
Once you have the Okta CLI installed, you’ll need Java 11 installed to run your Spring Boot app.
Create a Spring Boot App
To create a secure Spring Boot app with Okta, run okta start spring-boot
. You’ll need to verify your email and set a password as part of this.
This will download our Okta Spring Boot sample, register your app on Okta, and configure it by adding your Okta settings to src/main/resources/application.properties
.
Follow the instructions that are printed out for you. To summarize:
xxxxxxxxxx
cd spring-boot
./mvnw spring-boot:run
Next, open your browser to http://localhost:8080
. You’ll likely be logged in straight away and see your name printed on the screen.
If you use another browser or an incognito window, you’ll be prompted to sign in first.
If you open src/main/java/com/example/sample/Application.java
, you’ll see the Java code that’s used to render your name. You might appreciate how Spring Security makes authentication with OpenID Connect easy.
xxxxxxxxxx
static class SimpleRestController {
"/") (
String sayHello( OidcUser oidcUser) {
return "Hello: " + oidcUser.getFullName();
}
}
Learn More About Spring Boot and Okta
I hope you’ve enjoyed this brief intro to the Okta CLI. It’s a tool for developers to make their lives easier. If you have any suggestions for improvement, please add an issue to our okta/okta-cli repository.
If you like Spring Boot and Okta, you might like these posts:
Published at DZone with permission of Matt Raible, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.
Comments