为了不泄露机密信息,提供商将被替换为
$PROVIDER
。
授权是有效的,但它不是将我重定向到索引,而是将我重定向到
/error
。
复制步骤
-
启动应用程序
-
转到任何页面,它都会将我重定向到
http://localhost/oauth_login
其中显示链接
login
。
-
单击链接
登录名
(链接到
http://localhost/oauth2/authorization/$PROVIDER
)
-
重定向到
http://localhost/error
错误页面显示以下内容(为了便于阅读,我对其进行了格式化):
{
"timestamp":"2018-04-05T14:18:47.720+0000",
"status":999,
"error":"None",
"message":"No message available"
}
这显然与默认设置中显示的参数相同
白标错误页
,所以实际上,唯一的问题是它是JSON,而不是HTML页面。如果我刷新
http://localhost/error
之后,它向我展示了正常
白标错误页
。
如果我想导航到
http://localhost/
在重定向到错误页面后,我进行了身份验证(用户数据在那里,因此授权成功)。基本上,问题是我被重定向到
http://localhost/error
而不是
http://localhost/
。
因为它功能齐全(除了重定向),所以我不会发布整个安全配置,而是将其限制在相关代码中:
安全配置(SecurityConfiguration)
@Override
protected void configure(HttpSecurity httpSecurity) throws Exception {
httpSecurity
.csrf().disable()
.authorizeRequests().anyRequest()
.authenticated()
.and()
.oauth2Login()
.loginPage("/oauth_login")
.defaultSuccessUrl("/")
.failureUrl("/oauth_login")
.permitAll()
.and()
.logout()
.logoutUrl("/logout")
.logoutSuccessUrl("/oauth_login").permitAll()
;
}
相关属性
spring.security.oauth2.client.registration.$PROVIDER.redirectUriTemplate=http://localhost/login/oauth2/code/$PROVIDER
相关信息
-
一旦我在网站上通过身份验证,我就可以导航、刷新页面、做任何我想做的事(直到我注销)。
TL;DR公司
授权有效,但已重定向到
/错误
而不是
/
。