apolloconfig / apollo

Apollo is a reliable configuration management system suitable for microservice configuration management scenarios.
https://www.apolloconfig.com
Apache License 2.0
29.06k stars 10.2k forks source link

使用oauth2登录时,username 是openid #4746

Open lework opened 1 year ago

lework commented 1 year ago

描述bug

使用oauth2登录时,username 是openid,在授权的页面展示也是openid,对用户不友好 image

复现

application-oidc.yaml: |
    server:
      forward-headers-strategy: framework
    spring:
      security:
        oidc:
          user-display-name-claim-name: "username"
          jwt-user-display-name-claim-name: "username"
        oauth2:
          client:
            provider:
              # provider-name 是 oidc 提供者的名称, 任意字符均可, registration 的配置需要用到这个名称
              authing:
                # 必须是 https, oidc 的 issuer-uri, 和 jwt 的 issuer-uri 一致的话直接引用即可, 也可以单独设置
                issuer-uri: https://xxx.com/oidc
            registration:
              # registration-name 是 oidc 客户端的名称, 任意字符均可, oidc 登录必须配置一个 authorization_code 类型的 registration
              authing:
                # oidc 登录必须配置一个 authorization_code 类型的 registration
                authorization-grant-type: authorization_code
                client-authentication-method: basic
                # client-id 是在 oidc 提供者处配置的客户端ID, 用于登录 provider
                client-id: 
                # provider 的名称, 需要和上面配置的 provider 名称保持一致
                provider: authing
                # openid 为 oidc 登录的必须 scope, 此处可以添加其它自定义的 scope
                scope:
                  - openid
                  - Username
                  - preferred_username
                  - profile
                  - email
                # client-secret 是在 oidc 提供者处配置的客户端密码, 用于登录 provider
                # 从安全角度考虑更推荐使用环境变量来配置, 环境变量的命名规则为: 将配置项的 key 当中的 点(.)、横杠(-)替换为下划线(_), 然后将所有字母改为大写, spring boot 会自动处理符合此规则的环境变量
                # 例如 spring.security.oauth2.client.registration.registration-name.client-secret -> SPRING_SECURITY_OAUTH2_CLIENT_REGISTRATION_NAME_VDISK_CLIENT_SECRET (REGISTRATION_NAME 可以替换为自定义的 oidc 客户端的名称)
                client-secret: 

期望

可以自定义claim-name 作为username的对应字段

截图

如果可以,附上截图来描述你的问题

额外的细节和日志

Shelby-Jiao commented 1 year ago

Hi lework, refer to https://github.com/apolloconfig/apollo/issues/4714 are we suffering the same problem ?

kyleli666 commented 1 year ago

我也没找到好办法,暂时是配置preferred_username让某些地方能把两个都显示出来,就是有点长 囧 https://github.com/apolloconfig/apollo/blob/master/docs/zh/development/portal-how-to-implement-user-login-function.md#13-%E7%94%A8%E6%88%B7%E6%98%BE%E7%A4%BA%E5%90%8D%E9%85%8D%E7%BD%AE