使用 GitLab 作为 Oauth 上源

Upsource with GitLab as Oauth

我是 运行 GitLab,本地地址 http://192.168.0.18/. Upsource is running on http://192.168.0.11/

我已经在 GitLab 上以管理员身份添加了 Upsource 应用程序。正如 GitLab 所说,我已经设置了客户端 ID 和秘密令牌。授权设置为 http://192.168.0.18/oauth/authorize, token to http://192.168.0.18/oauth/token and user data to http://192.168.0.18/api/v4/user (according to GitLab documentation)。在字段映射中,我将用户 ID 设置为“id”,将两封电子邮件都设置为“email”。

然后,在 Upsource 的登录页面上,我有誓言身份验证图标。单击它后,GitLab 需要登录,用户必须为其帐户授权应用程序:

Authorization required

Authorize Upsource to use your account?

You are an admin, which means granting access to Upsource will allow them to interact with GitLab as an admin as well. Proceed with caution.

This application will be able to:

Access your API

Read user information

然而,点击 authorize 按钮后,Upsource 显示信息:Authentication failed. Check your credentials and try again.。我设置错了什么?字段映射?

哦,我找到答案了。正如经常发生的那样,我为此苦苦挣扎了好几个小时,就在我问了这个问题之后,我有了自己 运行 这个想法。橡皮鸭法,我猜...

如我所料,问题出在字段映射中。

我查看了 Chrome 中的 Network 选项卡,有这样的回复:

http://192.168.0.11/hub/auth/login?response_type=token&client_id=[CLIENT_ID]&redirect_uri=[REDIRECT_URI]&message=hub-auth-failed&developer_message=getValueByPath%28json%2C+aut%E2%80%A6userIdPath%29%21%21.textValue%28%29+must+not+be+null

我手动完成了所有 Gitlab 工作流程,然后我可以登录 - 在 运行 宁 http://192.168.0.18/api/v4/user 端点之后,我得到了用户数据:

{"name":"username","username":"username","id":3,"state":"active","avatar_url":"http://www.gravatar.com/avatar/94232f2d1f8bb2fe940de439a4df1014?s=80&d=identicon","web_url":"http://debian/username","created_at":"2017-03-25T22:28:21.375Z","is_admin":true,"bio":null,"location":null,"skype":"","linkedin":"","twitter":"","website_url":"","organization":null,"last_sign_in_at":"2017-03-25T22:28:21.487Z","confirmed_at":"2017-03-25T22:28:21.376Z","email":"username@username.username","color_scheme_id":1,"projects_limit":100000,"current_sign_in_at":"2017-03-25T22:36:31.853Z","identities":[],"can_create_group":true,"can_create_project":true,"two_factor_enabled":false,"external":false}

问题出在设置 ID 字段名称中。正如我们在上面的 JSON 数据中看到的,id 字段应该映射到 name/username,而不是 id 本身。 进行此更改后,我可以成功登录到 Upsource。