【问题标题】:spring boot Oauth Okta 404 on redirectspring boot Oauth Okta 404 重定向
【发布时间】:2022-01-26 01:33:54
【问题描述】:

从 Okta 服务器重定向后,我的 Spring Boot 应用程序给我一个错误 404。 我可以帮忙解决这个问题吗?我的配置如下。

这是我的 Okta 服务器重定向

https://dev-40483106.okta.com/oauth2/default/v1/authorize?response_type=code&client_id=0oa3p7a86ycJ7olpP5d7&scope=openid%20email&state=xVpkZIPGaGqAQCZIMXZgTrbmKmHJbcKbtM95KO9RwVU%3D&redirect_uri=http://localhost:8082/mms-sso/auth&nonce=cPdNAYT4tQ9mAjhj4HUiynBEQVAnJHnBTIezqquOpJM

这是我收到 404 错误的重定向 URI

http://localhost:8082/mms-sso/auth?code=rOh9u2fwBTB7gasIMUgtjIDMs5_Sydqz-0O_jG5Qhj0&state=xVpkZIPGaGqAQCZIMXZgTrbmKmHJbcKbtM95KO9RwVU%3D

下面是截图

[![error-404][1]][1]

 spring:
  security:
    oauth2:
      client:
        registration:
          okta:
            client-id: clientId
            client-secret: secret
            scope: openid, email
            authorization-grant-type: authorization_code
            redirect-uri: http://localhost:8082/mms-sso/auth
        provider:
          okta:
             issuer-uri: https://dev-40483106.okta.com/oauth2/default
             authorization-uri: https://dev-40483106.okta.com/oauth2/default/v1/authorize                     
        resource:
          server: http://localhost:8081
server: 
  port: 8082
  servlet: 
    context-path: /ui-one

安全配置


       protected void configure(HttpSecurity http) throws Exception {
           http.authorizeRequests().antMatchers("/login**", "/auth/**", 
               "/auth?**").permitAll().anyRequest().authenticated().and()
                .oauth2Login();


Okta 配置

登录重定向 URI - http://localhost:8082/mms-sso/auth

注销重定向 URI - http://localhost:8082/mms-sso/、http://localhost:8082/mms-sso/logout

重定向控制器

    @GetMapping("/auth")
    String home(@AuthenticationPrincipal OidcUser user) {
        
                return "Welcome to MMS SSO";
        
    }

【问题讨论】:

    标签: spring-boot oauth-2.0 okta


    【解决方案1】:

    您的控制器映射用于/auth,但在重定向中您将其指定为/mmo-sso/auth

    【讨论】:

    • 非常抱歉,我忘记在我添加了 contxt 路径的地方添加 spring application.yml。服务器:端口:8082 servlet:上下文路径:/ui-one 所以我的重定向 URI 是正确的。我忘记在问题中添加它是我的错误。我会更新它。谢谢
    猜你喜欢
    • 2018-12-28
    • 2019-11-10
    • 1970-01-01
    • 2018-12-26
    • 1970-01-01
    • 2023-03-10
    • 2019-07-26
    • 2021-01-02
    • 2017-06-14
    相关资源
    最近更新 更多