cra*_*gtb 5 google-app-engine spring-security spring-boot spring-security-oauth2
我试图在我的应用程序中使用Google应用程序引擎获取spring security oauth2设置.一切似乎在本地工作正常,但当我部署到应用程序引擎时,事情开始崩溃.我通过谷歌进行身份验证后,将其转发给Whitelabel错误页面.在控制台中我看到这个错误:
http://my-application.appspot.com/login?state=t…m&session_state=8b67f5df659a8324430803973b9e1726e39fd454..1ae3&prompt=none
401 (Unauthorized)
Run Code Online (Sandbox Code Playgroud)
我用这个application.yml文件设置我的auth:
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
Run Code Online (Sandbox Code Playgroud)
我的安全配置看起来像这样:
@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");
}
Run Code Online (Sandbox Code Playgroud)
我在google凭据页面上配置了Oauth ID,以允许授权的javascript来源:
http://my-application.appspot.com
https://my-application.appspot.com
http://localhost:8080
Run Code Online (Sandbox Code Playgroud)
并且授权的重定向URI为:
http://my-application.appspot.com/login
https://my-application.appspot.com/login
http://localhost:8080/login
Run Code Online (Sandbox Code Playgroud)
我部署到GAE后,为什么我可能会收到未经授权的错误?
谢谢,
克雷格
您的问题与授权有关,可能错过了完全授权应用程序的步骤,例如将 client_secret.json 移动到工作目录。
https://developers.google.com/drive/v3/web/quickstart/java#step_1_turn_on_the_api_name
第 1 步:打开云端硬盘 API
使用此向导在 Google Developers Console 中创建或选择项目并自动启用 API。单击继续,然后单击转到凭据。在“将凭据添加到项目”页面上,单击“取消”按钮。
在页面顶部,选择 OAuth 同意屏幕选项卡。选择电子邮件地址,输入产品名称(如果尚未设置),然后单击“保存”按钮。选择“凭据”选项卡,单击“创建凭据”按钮并选择 OAuth 客户端 ID。
选择应用程序类型“其他”,输入名称“Drive API Quickstart”,然后单击“创建”按钮。
单击“确定”关闭出现的对话框。
单击客户端 ID 右侧的 file_download(下载 JSON)按钮。
将此文件移动到您的工作目录并将其重命名为 client_secret.json。
有用的链接: GCM http 401 授权错误
| 归档时间: |
|
| 查看次数: |
382 次 |
| 最近记录: |