【发布时间】:2019-05-21 14:33:30
【问题描述】:
400。这是一个错误。错误:redirect_uri_mismatch 请求中的重定向 URI,http://testing.com:8008/login,与授权给 OAuth 客户端的不匹配。要更新授权的重定向 URI,请访问:
凭据页面中的授权重定向 URI 是 http://testing.com:8008/success,但它总是重定向到 http://testing.com:8008/login 不知道这里出了什么问题,有人可以帮忙。
下面是我的 application.yml 配置文件。
security:
oauth2:
client:
clientId: 701691307057-184m2p0ce76k.apps.googleusercontent.com
clientSecret: 7186351
pre-established-redirect-uri: http://testing.com:8008/success
accessTokenUri: https://www.googleapis.com/oauth2/v3/token
userAuthorizationUri: https://accounts.google.com/o/oauth2/auth
tokenName: oauth_token
authenticationScheme: query
clientAuthenticationScheme: form
scope: profile email
resource:
userInfoUri: https://www.googleapis.com/userinfo/v2/me
preferTokenInfo: false
Web 安全配置类如下。
@EnableOAuth2Sso
@Configuration
public class WebSecurityConfiguration extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.csrf()
.disable()
.antMatcher("/**")
.authorizeRequests()
.antMatchers("/", "/home", "/success")
.permitAll()
.anyRequest()
.authenticated();
}
}
下面的控制器
@Controller
@RequestMapping("/")
public class WelcomeController {
@RequestMapping(value = {"home"}, method = RequestMethod.GET)
public String welcomePage(){
return "welcomePageAfterSignin";
}
@RequestMapping(method = RequestMethod.GET)
public String welcomePage2(){
return "welcomePage";
}
@RequestMapping(value = {"success"}, method = RequestMethod.GET)
public String AfterSignIn(){
return "success";
}
@RequestMapping(value = "user")
public Principal user(Principal principal) {
return principal;
}
}
【问题讨论】:
-
如果您被 Spring Security 重定向到 /login on,这意味着 URL /success 受到保护,未经身份验证无法访问。您需要允许无需身份验证即可访问它。
-
是的,有道理,但使用谷歌登录重定向的全部目的将丢失。因为我想在使用 Oauth 登录后重定向到 /success。如果我允许 /success,它将不会使用 Oauth 进行身份验证。
标签: java oauth-2.0 spring-security-oauth2