Multiple client ids spring security config

2019-04-12 12:35发布

I have successfully implemented Google Sign-In on iOS with following application.yml:

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

Now I need to add configuration for Android client. Obviously I cannot do this:

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

What is the correct approach and best practice to do this?

1条回答
地球回转人心会变
2楼-- · 2019-04-12 12:44

I found the syntax you are looking for from this file Will Tran Github project application.yml

It will look like this,

# 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.: Check the link for better reference.

查看更多
登录 后发表回答