【问题标题】:spring - oauth2 redirecting to unknown urlspring - oauth2 重定向到未知 url
【发布时间】:2019-11-02 19:22:51
【问题描述】:

我正在尝试在我的 Spring 应用程序中使用 OAuth2。

这是我的pom.xml

现在在Giithub->Profile->Developer,我创建了一个 OAUth 应用程序,

主页网址是:http://localhost:8080/login

回调地址为:http://localhost:8080/datum

因此,每当我运行此应用程序(在端口 8080 上运行)并尝试访问 http://localhost:8080/ 的任何 url 子级时,我都会在 登录 http://localhost:8080/login,现在如果我登录,它会将我重定向到一个复杂的 url,并立即转到 http://localhost:8080/oauth2/authorization/github。之后无论我尝试多少次,我总是会被重定向到这里。

http://localhost:8080/datum 是一个有效的网址。

我已经添加了

spring.security.oauth2.client.registration.github.client-id=
spring.security.oauth2.client.registration.github.client-secret=

application.properties

这里有什么问题?我错过了什么?

【问题讨论】:

标签: spring spring-boot spring-security oauth-2.0


【解决方案1】:

我将回调url设置为http://localhost:8080/oauth2/authorization/github,问题就解决了。

【讨论】:

    【解决方案2】:

    不确定它是否会有所帮助,但也许可以尝试添加:

    import org.springframework.context.annotation.Configuration;
    import org.springframework.security.config.annotation.web.builders.HttpSecurity;
    import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
    
    @Configuration
    public class WebSecurityConfiguration extends WebSecurityConfigurerAdapter {
        @Override
        protected void configure(HttpSecurity http) throws Exception {
            http.authorizeRequests()
                .anyRequest().authenticated()
                .and()
                .oauth2Login();
        }
    }
    

    【讨论】:

    • 不行,你可以看看the视频..
    • 我也得到了这个:2019-11-03 16:19:14.457 WARN 11268 --- [nio-8080-exec-1] o.a.c.util.SessionIdGeneratorBase : Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [329] milliseconds.
    • 我找到了一个解决方案,可以在没有 WebSecurityConfigurerAdapter 的情况下工作,但是这是做什么的,你能告诉我吗?
    • 它允许在使用 Spring Boot 时配置 Spring Security。见baeldung.com/…
    猜你喜欢
    • 2020-04-15
    • 2017-05-03
    • 2020-01-23
    • 2019-10-14
    • 1970-01-01
    • 2021-08-08
    • 1970-01-01
    • 2015-10-28
    • 1970-01-01
    相关资源
    最近更新 更多