百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
O

okta-spring-boot

> 编程语言
开源

Okta Spring Boot 启动程序

370 stars0 点赞2 次浏览
访问官网GitHub

工具介绍

Okta Spring Boot 启动程序

Okta Spring Boot Starter

Okta's Spring Boot Starter will enable your Spring Boot application to work with Okta via OAuth 2.0/OIDC.

Release status

This library uses semantic versioning and follows Okta's library version policy.

:heavy_check_mark: The current stable major version series is: 3.x

Version Status
0.x.x, 1.x.x :warning: Retired
2.x.x :heavy_check_mark: Stable
3.0.x :heavy_check_mark: Stable (Spring Boot 3.x & 4.x)

Note: Version 3.0.10+ requires JDK 17 or above and supports both Spring Boot 3.x / Spring Security 6.x and Spring Boot 4.x / Spring Security 7.x.

Spring Boot Version Compatibility

Okta Spring Boot SDK Versions Compatible Spring Boot Versions Compatible Spring Security Minimum Java
1.2.x 2.1.x 5.x 8
1.4.x 2.2.x 5.x 8
1.5.x 2.4.x 5.x 8
2.0.x 2.4.x 5.x 8
2.1.x 2.7.x 5.x 11
3.0.x - 3.0.9 3.x.y 6.x 17
3.0.10+ 3.x.y and 4.x.y 6.x and 7.x 17

Upgrading to Spring Boot 4.x (3.0.10+)

Version 3.0.10+ adds full support for Spring Boot 4.x and Spring Security 7.x while maintaining compatibility with Spring Boot 3.x. If you're using Spring Boot 3.x and upgrading to 4.x, review the following:

Key Changes

1. Java 17 Required

Spring Boot 4.x requires Java 17 as the minimum version. Ensure your application is compiled and run on Java 17 or higher.

2. Package Path Changes (Spring Boot 4.x only)

Spring Boot 4.x relocated OAuth2 autoconfiguration classes. If you import any of these classes directly, update your imports:

java
// Old (Spring Boot 3.x)
import org.springframework.boot.autoconfigure.security.oauth2.client.OAuth2ClientProperties;

// New (Spring Boot 4.x)
import org.springframework.boot.security.oauth2.client.OAuth2ClientProperties;

3. Spring Security 7.x Lambda DSL

Spring Security 7.x (used with Spring Boot 4.x) requires the lambda DSL style for security configurations. Update your SecurityFilterChain beans:

java
// Old style (Spring Security 6.x) - DEPRECATED
http.authorizeRequests()
    .antMatchers("/").permitAll()
    .anyRequest().authenticated();

// New style (Spring Security 7.x)
http.authorizeHttpRequests(authorize -> authorize
    .requestMatchers("/").permitAll()
    .anyRequest().authenticated());

For a complete list of changes, see the CHANGELOG.

The latest release can always be found on the releases page.

What you need

  • An Okta account (sign up for a forever-free developer account)
  • An OIDC application (typically a 'Web' application)
  • An access token

Quickstart

  1. Create a Spring Boot application with Spring initializr:

    bash
    curl https://start.spring.io/starter.tgz -d dependencies=web,okta -d baseDir=> | tar -xzvf -
    cd >
  2. Configure it with Okta CLI:

    bash
    okta apps create
  3. Run it:

    bash
    ./mvnw spring-boot:run

Include the dependency

For Apache Maven:

xml

    com.okta.spring
    okta-spring-boot-starter
    ${okta.springboot.version}

For Gradle:

groovy
implementation 'com.okta.spring:okta-spring-boot-starter:${okta.springboot.version}'

where ${okta.springboot.version} is the latest published version in Maven Central.

Building API Applications - Resource Server

Are you building backend endpoints in order to support a client side application? If so follow along, otherwise skip to the next section.

Configure your properties

You can configure your applications properties with environment variables, system properties, or configuration files. Take a look at the Spring Boot documentation for more details.

Only these three properties are required for a web app:

Property Default Required Details
okta.oauth2.issuer N/A ✅ Authorization Server issuer URL, i.e.: https://{yourOktaDomain}/oauth2/default
okta.oauth2.clientId N/A * The Client Id of your Okta OIDC application
okta.oauth2.clientSecret N/A * The Client Secret of your Okta OIDC application
okta.oauth2.audience api://default The audience of your Authorization Server
okta.oauth2.groupsClaim groups The claim key in the Access Token's JWT that corresponds to an array of the users groups.

* Required when using opaque access tokens.

Create a Controller

The above client makes a request to /hello-oauth, you simply need to create a Spring Boot application and Controller to handle the response:

java
@SpringBootApplication
@RestController
public class DemoApplication {

	public static void main(String[] args) {
		SpringApplication.run(DemoApplication.class, args);
	}

	@GetMapping("/hello-oauth")
	public String hello(Principal principal) {
	    return "Hello, " + principal.getName();
	}
}

That's it!

To test things out you can use curl:

bash
$ curl http://localhost:8080/hello-oauth \
   --header "Authorization: Bearer ${accessToken}"

The result should look something like:

Hello, [email protected]

Okta's Spring Security integration will parse the JWT access token from the HTTP request's Authorization: Bearer header value.

Check out a minimal example that uses the Okta Signin Widget and JQuery or this blog post.

Spring MVC

  1. Setup your MVC project by following Quickstart section above.

  2. Configure the URL mappings for handling GET and POST requests.

…

NOTE: message:read and message:write used above in @PreAuthorize are OAuth scopes. If you are looking to add custom scopes, refer to the documentation.

  1. Configure your Resource Server either for JWT or Opaque Token validation by creating a SecurityFilterChain bean. If neither JWT nor Opaque Token is specified in configuration, JWT validation will be used by default.
…

Refer Spring Security documentation here for more details on resource server configuration.

Spring WebFlux

To configure a resource server when using Spring WebFlux, you need to use a couple annotations, and define a SecurityWebFilterChain bean.

…

If you want to support SSO and a resource server in the same application, you can do that too!

java
@Configuration
@EnableWebFluxSecurity 
@EnableReactiveMethodSecurity 
public class SecurityConfiguration {

    @Bean 
    public SecurityWebFilterChain securityWebFilterChain(ServerHttpSecurity http) {
        http
            .authorizeExchange(exchanges -> exchanges
                .anyExchange().authenticated())
            .oauth2Login(oauth2 -> {})
            .oauth2ResourceServer(oauth2 -> oauth2.jwt(jwt -> {}));
        return http.build();
    }
}

Full Stack Reactive with Spring WebFlux, WebSockets, and React uses both SSO and a resource server. Its current code uses Spring Security's OIDC support. Changing it to use the Okta Spring Starter reduces the lines of code quite a bit.

Supporting server side applications - OAuth Code flow

Building a server side application and just need to redirect to a login page? This OAuth 2.0 code flow is for you.

Create a Web App on Okta

To create a new OIDC app for Spring Boot on Okta:

  1. Log in to your developer account, navigate to Applications, and click on Add Application.
  2. Select Web and click Next.
  3. Give the application a name and add http://localhost:8080/login/oauth2/code/okta as a login redirect URI.
  4. Click Done.

Configure your properties

You can configure your applications properties with environment variables, system properties, or configuration files. Take a look at the Spring Boot documentation for more details.

Property Required Details
okta.oauth2.issuer true Authorization Server issuer URL, i.e.: https://{yourOktaDomain}/oauth2/default
okta.oauth2.clientId true The Client Id of your Okta OIDC application
okta.oauth2.clientSecret true The Client Secret of your Okta OIDC application
okta.oauth2.postLogoutRedirectUri false Set to a relative or absolute URI to enable RP-Initiated (SSO) logout.

NOTE: On setting postLogoutRedirectUri, you will be redirected to it after the end of your session. Therefore, this resource must be available anonymously, so be sure to add it to your HttpSecurity configuration.

See a postLogoutRedirectUri example:

yaml
okta:
  oauth2:
    postLogoutRedirectUri: "http://localhost:8080/logout/callback"
…

Create a simple application

Create a minimal Spring Boot application:

java
@RestController
@SpringBootApplication
public class ExampleApplication {

    public static void main(String[] args) {
        SpringApplication.run(ExampleApplication.class, args);
    }

    @GetMapping("/")
    public String getMessageOfTheDay(@AuthenticationPrincipal OidcUser user) {
        return user.getName() + ", this message of the day is boring";
    }
}

If you want to allow anonymous access to specific routes you can add a SecurityFilterChain bean:

java
@Configuration
static class SecurityConfig {
    @Bean
    SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
        http.authorizeHttpRequests(authorize -> authorize
                .requestMatchers("/my-anon-page").permitAll()
                .anyRequest().authenticated())
            .oauth2Client(oauth2 -> {})
            .oauth2Login(oauth2 -> {});
        return http.build();
    }
}

If you want to add custom claims to JWT tokens in your custom Authorization Server, see [Add Custom claim to a to

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Java

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言