DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Newsletter
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Actuator Enhancements: Spring Framework 6.2 and Spring Boot 3.4
  • How Spring Boot Starters Integrate With Your Project
  • A Practical Guide to Creating a Spring Modulith Project
  • Structured Logging in Spring Boot 3.4 for Improved Logs

Trending

  • How to Submit a Post to DZone
  • When to Use AMQP, JMS, Kafka, or MQTT: Trade-Offs, Not a Winner
  • You Do Not Need a PhD to Become an AI Engineer: The Essential Skill Stack
  • Designing a Polling Pipeline for Rate-Limited APIs Without Losing Data

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

  1. DZone
  2. Coding
  3. Frameworks
  4. A Quick Guide to Okta and Spring Boot

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.

By 
Matt Raible
·
Jan. 14, 21 · Tutorial
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
6.8K Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in

Meet 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:

Shell
 




x


 
1
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.If you already have anOkta account, you can run "okta login" first.

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:

Shell
 




xxxxxxxxxx
1


 
1
cd spring-boot
2
./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.Hello: Matt Raible screenshot

If you use another browser or an incognito window, you’ll be prompted to sign in first.


Okta login page

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.

Java
 




xxxxxxxxxx
1


 
1
@RestController
2
static class SimpleRestController {
3
    @GetMapping("/")
4
    String sayHello(@AuthenticationPrincipal OidcUser oidcUser) {
5
        return "Hello: " + oidcUser.getFullName();
6
    }
7
}


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:

  • Deploy a Secure Spring Boot App to Heroku
  • OAuth 2.0 Patterns with Spring Cloud Gateway
  • OpenID Connect Logout Options with Spring Boot
  • Build a CRUD App with Angular 9 and Spring Boot 2.2
  • OAuth 2.0 Java Guide: Secure Your App in 5 Minutes
Spring Framework Spring Boot

Published at DZone with permission of Matt Raible. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Actuator Enhancements: Spring Framework 6.2 and Spring Boot 3.4
  • How Spring Boot Starters Integrate With Your Project
  • A Practical Guide to Creating a Spring Modulith Project
  • Structured Logging in Spring Boot 3.4 for Improved Logs

Partner Resources

×

Comments

Loading comments

The comments didn't load

Please try again in a moment.

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook