【问题标题】:Multiple client ids spring security config多个客户端 ID 弹簧安全配置
【发布时间】:2017-01-12 22:32:37
【问题描述】:

我已使用以下 application.yml 在 iOS 上成功实现 Google 登录:

security:
  oauth2:
    resource:
      user-info-uri: https://www.googleapis.com/plus/v1/people/me
      prefer-token-info: true
    client:
      client-id: xxxxx.apps.googleusercontent.com
      access-token-uri: https://www.googleapis.com/oauth2/v3/tokeninfo
      client-authentication-scheme: form
      scope: email,profile

现在我需要为 Android 客户端添加配置。显然我不能这样做:

security:
  oauth2:
    resource:
      user-info-uri: https://www.googleapis.com/plus/v1/people/me
      prefer-token-info: true
    client:
      client-id: xxxxx.apps.googleusercontent.com
      access-token-uri: https://www.googleapis.com/oauth2/v3/tokeninfo
      client-authentication-scheme: form
      scope: email,profile
    client:
      client-id: xxxxx.apps.googleusercontent.com
      access-token-uri: https://www.googleapis.com/oauth2/v3/tokeninfo
      client-authentication-scheme: form
      scope: email,profile

这样做的正确方法和最佳实践是什么?

【问题讨论】:

  • 我们在同一个人@Heisenbug。我有一种感觉,需要手动配置spring security来处理多个客户端id。也许这可以帮助指导您如何自定义弹簧安全性。 github.com/techdev-solutions/trackr-backend
  • @FrancisZabala 感谢您的回复。我尝试了以下方法:在 .yml 中,我只留下了服务器客户端 ID,一切都继续工作。现在我面临另一个问题:Android 没有自动接收 accessToken,获取它的最佳做法是什么?
  • 我真的无法帮助您使用 android,但如果您的意思是您的 android 客户端如何使用访问令牌,您可能想知道 auth0 是如何工作的。这是他们文档的链接。 auth0.com/docs/quickstart/native/android 但是如果你想确保你的rest api很好,我还在做一些研究。

标签: spring spring-security spring-boot google-signin google-oauth


【解决方案1】:

我在Will Tran Github project application.yml这个文件中找到了你正在寻找的语法

它看起来像这样,

# OAuth2 Details
security.oauth2:
    client:
        client-id: client001
        client-secret: pwd001
        authorized-grant-types: password,authorization_code,refresh_token
        scope: read,write

---

security.oauth2:
    client:    
        client-id: client002
        client-secret: pwd002
        authorized-grant-types: client_credentials
        scope: TRUSTED

---

# /\ Dont forget this one

Ps.:查看链接以获得更好的参考。

【讨论】:

    猜你喜欢
    • 2018-01-14
    • 2020-05-19
    • 1970-01-01
    • 1970-01-01
    • 2017-09-25
    • 2017-01-08
    • 2015-04-19
    • 2020-09-16
    相关资源
    最近更新 更多