Skip to content

oktadev/okta-maven-plugin

Repository files navigation

Maven Central License

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!

About

No description, website, or topics provided.

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published