Skip to content

feat(auth): support OSS Google SSO via allowlisted redirect_uri#4855

Merged
mashbean merged 3 commits into
developfrom
feat/oss-google-sso
Jun 17, 2026
Merged

feat(auth): support OSS Google SSO via allowlisted redirect_uri#4855
mashbean merged 3 commits into
developfrom
feat/oss-google-sso

Conversation

@mashbean

Copy link
Copy Markdown
Contributor

背景

OSS 後台(oss.matters.*)要改用 Google SSO 登入,重用 matters-web 既有的 Google OAuth client。但有兩個阻礙:

  1. redirect_uri 對不上exchangeGoogleToken 用單一寫死的 MATTERS_GOOGLE_REDIRECT_URI 換 token,而 Google 要求換 token 的 redirect_uri 必須與授權請求一致。OSS 在自己網域發起 → 永遠換不到 token。
  2. 會自動建帳號socialLogin 對任何 Google 帳號 getOrCreateUserBySocialAccount,對內部管理工具不可接受。

變更

  • SocialLoginInput.redirectUri(選填):OSS SSO 的 OIDC redirect_uri。
  • exchangeGoogleToken / fetchGoogleUserInfo 接受 redirect_uri 覆寫(預設仍為 env 值)。
  • socialLogin:當帶 redirectUri
    • 必須在白名單 MATTERS_OSS_GOOGLE_REDIRECT_URIS 內(防開放轉址 / token 竊取);
    • 視為 OSS admin 登入:以 Google 驗證過的 email 比對既有帳號,要求 role === admin絕不自動建帳號
  • environment.ossGoogleRedirectUris:逗號分隔白名單。
  • 測試:拒絕非白名單 redirectUri。

部署前置(缺一不可)

  • MATTERS_OSS_GOOGLE_REDIRECT_URIS,例如 https://oss.matters.icu/callback/google,https://oss.matters.town/callback/google
  • 在現有 Google OAuth client 註冊上述 OSS callback URI

⚠️ 部署順序

本 PR 必須先於 matters-oss 前端 PR 部署,否則前端送出的 redirectUri 會被舊 schema 當未知欄位拒絕。

對應前端 PR:thematters/matters-oss feat/oss-google-sso

🤖 Generated with Claude Code

OSS (oss.matters.*) reuses the existing Google OAuth client to sign admins
in, but the server previously exchanged the auth code with a single hardcoded
redirect_uri (matters-web's), so an OSS-originated login could never complete
(Google requires the token-exchange redirect_uri to match the authorization
request). It also auto-created a Matters account for any Google login, which
is unacceptable for an internal admin tool.

- SocialLoginInput.redirectUri: optional OIDC redirect_uri for OSS SSO.
- exchangeGoogleToken / fetchGoogleUserInfo accept a redirect_uri override.
- socialLogin: when redirectUri is set it must be in the allowlist
  (MATTERS_OSS_GOOGLE_REDIRECT_URIS); the login is then treated as an OSS
  admin login — restricted to an existing admin account (matched by the
  Google-verified email) and never auto-creates a user.
- environment.ossGoogleRedirectUris: comma-separated allowlist.
- test: reject a non-allowlisted redirectUri.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@mashbean mashbean requested a review from a team as a code owner June 17, 2026 04:14
@codecov

codecov Bot commented Jun 17, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 73.91304% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 72.77%. Comparing base (b12c8b7) to head (154c4c2).
⚠️ Report is 22 commits behind head on develop.

Files with missing lines Patch % Lines
src/mutations/user/socialLogin.ts 64.70% 6 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #4855      +/-   ##
===========================================
+ Coverage    72.68%   72.77%   +0.09%     
===========================================
  Files         1068     1068              
  Lines        21246    21263      +17     
  Branches      4641     4651      +10     
===========================================
+ Hits         15442    15474      +32     
+ Misses        5325     5312      -13     
+ Partials       479      477       -2     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

mashbean and others added 2 commits June 17, 2026 12:52
Raise patch coverage for the OSS social-login branch:
- non-allowlisted redirectUri is rejected
- non-admin / unknown account is rejected (no auto-create)
- existing admin account logs in successfully

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Mock the Google token exchange to cover exchangeGoogleToken using the supplied
OSS redirect_uri (the non-e2e path), raising patch coverage for the SSO change.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@mashbean mashbean merged commit 1d9cd62 into develop Jun 17, 2026
5 checks passed
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.

1 participant