首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何修复此OAuth2.0错误重定向

如何修复此OAuth2.0错误重定向
EN

Stack Overflow用户
提问于 2018-12-21 04:54:58
回答 2查看 1.5K关注 0票数 1

  1. 这是个错误。错误: redirect_uri_mismatch请求中的重定向URI http://testing.com:8008/login与为OAuth客户机授权的URI不匹配。要更新授权的重定向URI,请访问:

凭证页面中的授权重定向URI是http://testing.com:8008/success,但是它总是重定向到http://testing.com:8008/login,不知道这里出了什么问题,有人可以帮忙。

配置的application.yml文件如下所示。

代码语言:javascript
运行
复制
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安全配置类。

代码语言:javascript
运行
复制
@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();
    }
}

下面的控制器

代码语言:javascript
运行
复制
@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;
    }
}
EN

回答 2

Stack Overflow用户

发布于 2018-12-21 05:03:30

代码语言:javascript
运行
复制
Actually nothing is wrong,  you are being redirected to spring security login page.

您缺少的是spring-security的凭据。

仔细查看日志,您将看到类似于Using generated security password: 5608543f-48fd-46ae-94a4-3f7094aa0d53的密码。

因此,您需要在登录页面中输入这些凭据。默认情况下,用户名是:每次在日志(如):user中生成密码

只有这样,您才会被重定向到您的google页面或api,您已经公开了。

添加图片供您参考

票数 0
EN

Stack Overflow用户

发布于 2018-12-21 07:02:48

  • 确保检查协议"http://“或"https://”,因为谷歌也检查协议。最好在列表中添加两个URL。
  • 这似乎相当奇怪和恼人的是,没有“一个”的解决方案。对我来说,http://localhost:8000没有成功,但http://localhost:8000/成功了。
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53879373

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档