【发布时间】:2017-12-30 12:34:02
【问题描述】:
我正在尝试在 Google 应用引擎中的应用程序上设置 spring security oauth2。一切似乎在本地运行良好,但是当我部署到应用程序引擎时,事情开始崩溃。在我通过 google 进行身份验证后,它会将我转发到 Whitelabel 错误页面。在控制台中我看到了这个错误:
http://my-application.appspot.com/login?state=t…m&session_state=8b67f5df659a8324430803973b9e1726e39fd454..1ae3&prompt=none
401 (Unauthorized)
我使用这个 application.yml 文件设置我的身份验证:
security:
oauth2:
client:
clientId: client-key
clientSecret: secret-key
accessTokenUri: https://www.googleapis.com/oauth2/v4/token
userAuthorizationUri: https://accounts.google.com/o/oauth2/v2/auth
clientAuthenticationScheme: form
scope:
- openid
- email
- profile
- https://www.googleapis.com/auth/cloud-platform
resource:
userInfoUri: https://www.googleapis.com/oauth2/v3/userinfo
preferTokenInfo: true
我的安全配置看起来像这样:
@Override
protected void configure(HttpSecurity http) throws Exception {
http.csrf().csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse())
.and()
.authorizeRequests()
.antMatchers("/static/**").permitAll()
.antMatchers("/**").hasAuthority("ROLE_ADMIN")
.anyRequest().authenticated()
.and()
.exceptionHandling()
.accessDeniedPage("/403");
}
我已在 google 凭据页面上配置 Oauth ID 以允许授权的 javascript 来源为:
http://my-application.appspot.com
https://my-application.appspot.com
http://localhost:8080
授权重定向 URI 到:
http://my-application.appspot.com/login
https://my-application.appspot.com/login
http://localhost:8080/login
任何想法为什么我在部署到 GAE 后可能会遇到未经授权的错误?
谢谢,
克雷格
【问题讨论】:
-
您确定您尝试进行身份验证的用户具有“ROLE_ADMIN”权限吗?
-
阳性。我已经尝试将其剥离并在所有页面上仅使用 oauth 身份验证,但它仍然给出相同的错误。
-
如果可能,您能否在 GitHub 上分享一个最小的、可重现的示例项目?
-
我能够解决这个问题。原来它与 app.yaml 文件有关(很遗憾我没有在这里发布)。问题似乎与弹簧安全性和在多个实例上运行应用程序有关。当它试图加载 js 库和其他资源时,似乎没有在实例之间传递安全性。尚未研究如何解决此问题。
标签: google-app-engine spring-boot spring-security spring-security-oauth2