使用OAuth2自定义提供程序登录GitLab不会映射用户信息

时间:2019-04-05 11:59:07

标签: oauth gitlab gitlab-omnibus gitlab-ce

我已经在CentOS VM上安装了Gitlab-CE,并且正在尝试配置Sign On with an generic OAuth2 provider,更具体地说,是实际上在使用IBM Security Access Manager 9.0.6

到目前为止,{strong>登录工作了omniauth-oauth2-generic gem configuration几周之后:

我确实看到了SSO按钮: SSO Button

在管理区域中,我确实找到了具有oauth2身份提供者的用户: enter image description here

我的问题是用户登录时未设置用户信息: enter image description here

这是我的omniauth配置:

#https://gitlab.com/satorix/omniauth-oauth2-generic
gitlab_rails['omniauth_enabled'] = true
gitlab_rails['omniauth_allow_single_sign_on'] = ['oauth2_generic']
gitlab_rails['omniauth_block_auto_created_users'] = false
gitlab_rails['omniauth_providers'] = [
  {
    'name' => 'oauth2_generic',
    'app_id' => '9gzCzRKeiipexDRXsJOJ',
    'app_secret' => 'mysecret',
    'args' => {
      client_options: {
        'site' => 'https://example.com', # including port if necessary
        'authorize_url': '/mga/sps/oauth/oauth20/authorize',
        'token_url': '/mga/sps/oauth/oauth20/token',
        'user_info_url' => '/mga/sps/oauth/oauth20/userinfo'
      },
      user_response_structure: {
        root_path: [],
        id_path: ['sub'],
        attributes: {
          nickname: 'sub',
          name: 'name',
          first_name: 'given_name',
          last_name: 'family_name'
        }
      }
      # optionally, you can add the following two lines to "white label" the display name
      # of this strategy (appears in urls and Gitlab login buttons)
      # If you do this, you must also replace oauth2_generic, everywhere it appears above, with the new name.
      #name: 'IBM ISAM', # display name for this strategy
      #strategy_class: "OmniAuth::Strategies::OAuth2Generic" # Devise-specific config option Gitlab uses to find renamed strategy
    }
  }
]

我的用户信息端点返回:

{ "sub":"XCQX342",
  "nickname": "Kalem",
  "name": "My name",
  "given_name": "My name",
  "family_name": "My surname",
  "email": "myemail@example.com"
}

我已经将我的配置与http://lifeinide.com/post/2017-08-30-jetbrains-hub-as-oauth2-provider-for-gitlab/进行了比较,但是我看不出有什么问题,为什么gitlab无法解析用户属性。

感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

希望您能解决您的问题。

如果不是:

在这种情况下,尝试直接设置字段

https://gitlab.com/satorix/omniauth-oauth2-generic/blob/master/lib/omniauth/strategies/oauth2_generic.rb#L20

您在此处设置的效果

user_response_structure: {
  root_path: [],
  id_path: ['sub'],
  attributes: {
    nickname: 'sub',
    name: 'name',
    first_name: 'given_name',
    last_name: 'family_name',
    email: 'email'
  }
}