Skip to content

feat: 添加 Google OAuth 登录支持 - #4118

Closed
Laurc2004 wants to merge 1 commit into
QuantumNous:mainfrom
Laurc2004:main
Closed

feat: 添加 Google OAuth 登录支持#4118
Laurc2004 wants to merge 1 commit into
QuantumNous:mainfrom
Laurc2004:main

Conversation

@Laurc2004

@Laurc2004 Laurc2004 commented Apr 7, 2026

Copy link
Copy Markdown
  • 新增 Google OAuth 提供者实现,包括令牌交换和用户信息获取
  • 在用户模型中添加 GoogleId 字段及相关查询方法
  • 添加系统设置页面用于配置 Google OAuth 客户端信息
  • 在前端登录和注册页面添加 Google 登录按钮
  • 在用户状态更新时同步 GoogleId 字段

Summary by CodeRabbit

  • New Features
    • Google OAuth sign-in: Users can now log in using their Google accounts
    • Google OAuth registration: New users can register via Google
    • Google account binding: Existing users can link their Google accounts
    • Configuration panel: Administrators can manage Google OAuth settings including API credentials in system settings

- 新增 Google OAuth 提供者实现,包括令牌交换和用户信息获取
- 在用户模型中添加 GoogleId 字段及相关查询方法
- 添加系统设置页面用于配置 Google OAuth 客户端信息
- 在前端登录和注册页面添加 Google 登录按钮
- 在用户状态更新时同步 GoogleId 字段
@coderabbitai

coderabbitai Bot commented Apr 7, 2026

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: b0ec8fdd-9a51-4d12-9488-2cf774b661e6

📥 Commits

Reviewing files that changed from the base of the PR and between 960bf9c and ca49b3f.

📒 Files selected for processing (10)
  • controller/misc.go
  • controller/oauth.go
  • controller/option.go
  • model/user.go
  • oauth/google.go
  • setting/system_setting/google.go
  • web/src/components/auth/LoginForm.jsx
  • web/src/components/auth/RegisterForm.jsx
  • web/src/components/settings/SystemSetting.jsx
  • web/src/helpers/api.js

Walkthrough

This pull request implements Google OAuth provider support end-to-end: adds Google provider ID and settings to backend models and configuration, creates a Google OAuth provider with token exchange and user info flows, updates controllers to expose Google OAuth status and handle provider bindings, and adds login/registration/configuration UI components on the frontend.

Changes

Cohort / File(s) Summary
Model & Settings
model/user.go, setting/system_setting/google.go
Extended User model with GoogleId field and methods (FillUserByGoogleId, IsGoogleIdAlreadyTaken); added GoogleSettings struct with client credentials and enabled flag.
OAuth Provider Implementation
oauth/google.go
Implemented GoogleProvider with token exchange (via Google token endpoint), user info retrieval, and provider-specific bindings (IsUserIDTaken, FillUserByProviderID, SetProviderUserID).
Backend Controllers
controller/misc.go, controller/oauth.go, controller/option.go
Updated GetStatus to return google_oauth and google_client_id; added google_id to OAuth user binding updates; added validation for google.enabled option checks.
Frontend Auth Components
web/src/components/auth/LoginForm.jsx, web/src/components/auth/RegisterForm.jsx
Added Google login/register buttons with onClick handlers, loading states, and conditional rendering based on google_oauth status flag.
Frontend Settings & Helpers
web/src/components/settings/SystemSetting.jsx, web/src/helpers/api.js
Added Google OAuth configuration card for client credentials and enabled toggle; implemented onGoogleOAuthClicked OAuth flow handler.

Sequence Diagram

sequenceDiagram
    participant User as User (Browser)
    participant Frontend as Frontend (LoginForm)
    participant Google as Google OAuth
    participant Backend as Backend (Controller)
    participant DB as Database

    User->>Frontend: Click "Login with Google"
    Frontend->>Frontend: handleGoogleClick: prepare state
    Frontend->>Google: Redirect to authorization endpoint<br/>(with client_id, redirect_uri, scope)
    Google->>User: Show consent screen
    User->>Google: Authorize
    Google->>Frontend: Redirect with authorization code
    Frontend->>Backend: POST /oauth/google/exchange<br/>(code from redirect)
    Backend->>Google: POST token endpoint<br/>(code + client credentials)
    Google->>Backend: Return access token
    Backend->>Google: GET userinfo endpoint<br/>(with access token)
    Google->>Backend: Return user profile (sub, email, name)
    Backend->>DB: Query/create user with GoogleId
    DB->>Backend: Return user
    Backend->>User: Login session established
    Frontend->>User: Redirect to dashboard
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • seefs001

Poem

🐰 Hops with glee,
Google logins now flow free,
OAuth's dance complete,
Frontend and backend meet!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 8.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat: 添加 Google OAuth 登录支持' clearly and specifically describes the main change: adding Google OAuth login support, which is the core objective of this pull request across all modified files.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@seefs001

seefs001 commented Apr 7, 2026

Copy link
Copy Markdown
Collaborator

现有自定义oauth登录已经可以完成google登录流程,不考虑增加

@seefs001 seefs001 closed this Apr 7, 2026
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.

2 participants