Skip to content

feat(auth): add GitLab OAuth2 provider support#264

Open
myml wants to merge 1 commit intoiflytek:mainfrom
myml:gitlab
Open

feat(auth): add GitLab OAuth2 provider support#264
myml wants to merge 1 commit intoiflytek:mainfrom
myml:gitlab

Conversation

@myml
Copy link
Copy Markdown

@myml myml commented Apr 9, 2026

Summary

  • What changed?

    • GitLab OAuth2 client configuration with customizable base URL
    • GitLabClaimsExtractor for handling GitLab-specific user claims
    • Multi-provider login UI with provider-specific icons
    • Updated localization to use OAuth-agnostic terminology
    • JSON type annotation for IdentityBinding entity
  • Why is this needed?

Add GitLab as an additional OAuth2 authentication provider

Validation

  • Backend tests passed
  • Frontend typecheck/build passed
  • OpenAPI SDK regenerated or checked when API contracts changed
  • Smoke test run when relevant

Commands run:

# paste commands here
make test

Risk

  • User-facing impact:
  • Deployment or migration impact:
  • Rollback approach:

Notes

  • Related issue:
  • Follow-up work:
  • Docs or operator runbooks updated when behavior changed:

@myml myml marked this pull request as draft April 9, 2026 02:01
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Apr 9, 2026

CLA assistant check
All committers have signed the CLA.

@myml myml marked this pull request as ready for review April 9, 2026 02:30
Add GitLab as an additional OAuth2 authentication provider alongside
GitHub. This includes:

- GitLab OAuth2 client configuration with customizable base URL
- GitLabClaimsExtractor for handling GitLab-specific user claims
- Multi-provider login UI with provider-specific icons
- Updated localization to use OAuth-agnostic terminology
- JSON type annotation for IdentityBinding entity
wowo-zZ

This comment was marked as duplicate.

Copy link
Copy Markdown
Collaborator

@wowo-zZ wowo-zZ left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

整体实现清晰,测试覆盖到位。以下几个问题建议修复后再合并。

gitlab:
client-id: ${OAUTH2_GITLAB_CLIENT_ID:placeholder}
client-secret: ${OAUTH2_GITLAB_CLIENT_SECRET:placeholder}
scope: read_user,email
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

scope 格式不一致

GitHub 已改为 YAML list 格式,但 GitLab 仍用逗号分隔字符串。Spring Security 对逗号分隔 scope 的处理可能因版本而异,建议统一为 list 格式:

scope:
  - read_user
  - email

* Determines the GitLab API base URL from the provider configuration.
* The user-info-uri is configured as ${OAUTH2_GITLAB_BASE_URI}/api/v4/user,
* so we simply remove the /user suffix to get the API base URL.
*/
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

replace("/user", "") 存在误替换风险

如果自建 GitLab 的域名或路径中包含 "user"(例如 https://gitlab.usercompany.com/api/v4/user),会被错误替换。

建议改为:

if (userInfoUri.endsWith("/user")) {
    return userInfoUri.substring(0, userInfoUri.length() - "/user".length());
}
return userInfoUri;

return (
<img
src="/github-logo.svg"
alt="GitHub"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

未知 provider 默认返回 GitHub 图标

当前 fallback 是 GitHub logo,如果后续加入 Gitee 等其他 provider 会显示错误图标。建议 fallback 用一个通用登录图标,或者根据 provider name 动态匹配:

// 通用 fallback
return <LogIn className="w-5 h-5 mr-3" />

或者让后端在 provider 列表中返回 icon URL,前端直接渲染。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants