Awesome
<img src="https://aws1.discourse-cdn.com/standard14/uploads/oktadev/original/1X/0c6402653dfb70edc661d4976a43a46f33e5e919.png" align="right" width="256px"/>
Okta Maven Plugin
Okta's Maven Plugin will help you get started with Okta without ever leaving your console.
Prerequisite
- Java 8+
Usage
The basic usage is simply:
mvn com.okta:okta-maven-plugin:register # or use the "login" goal if you already have an Okta account
mvn com.okta:okta-maven-plugin:spring-boot
# if you are building a JHipster app use "jhipster" or for other types of web apps, use the "web-app" goal
This will prompt you for required information and setup a new OIDC application for you.
For more complete information see the complete plugin documentation
Spring Boot Quick start
Create a new Spring Boot project:
curl https://start.spring.io/starter.tgz -d dependencies=web,okta \
-d baseDir=okta-spring-security-example-app | tar -xzvf -
cd okta-spring-security-example-app
Run the Okta Maven Plugin to Register a new account:
./mvnw com.okta:okta-maven-plugin:register
Then, configure your new Spring OIDC application:
./mvnw com.okta:okta-maven-plugin:spring-boot
Add a simple REST controller, for example replace your src/main/java/com/example/demo/DemoApplication.java
with:
package com.example.demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.security.oauth2.core.oidc.user.OidcUser;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
@GetMapping("/")
String hello(@AuthenticationPrincipal OidcUser user) {
return String.format("Welcome, %s", user.getFullName());
}
}
Start your Spring Boot application:
./mvnw spring-boot:run
Now just browse to: http://localhost:8080/
you will be prompted to login.
Check your email to for your new account details!