feat(auth): support OSS Google SSO via allowlisted redirect_uri#4855
Merged
Conversation
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>
Codecov Report❌ Patch coverage is
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. 🚀 New features to boost your workflow:
|
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
背景
OSS 後台(oss.matters.*)要改用 Google SSO 登入,重用 matters-web 既有的 Google OAuth client。但有兩個阻礙:
exchangeGoogleToken用單一寫死的MATTERS_GOOGLE_REDIRECT_URI換 token,而 Google 要求換 token 的 redirect_uri 必須與授權請求一致。OSS 在自己網域發起 → 永遠換不到 token。socialLogin對任何 Google 帳號getOrCreateUserBySocialAccount,對內部管理工具不可接受。變更
SocialLoginInput.redirectUri(選填):OSS SSO 的 OIDC redirect_uri。exchangeGoogleToken/fetchGoogleUserInfo接受 redirect_uri 覆寫(預設仍為 env 值)。socialLogin:當帶redirectUri時MATTERS_OSS_GOOGLE_REDIRECT_URIS內(防開放轉址 / token 竊取);role === admin,絕不自動建帳號。environment.ossGoogleRedirectUris:逗號分隔白名單。部署前置(缺一不可)
MATTERS_OSS_GOOGLE_REDIRECT_URIS,例如https://oss.matters.icu/callback/google,https://oss.matters.town/callback/google本 PR 必須先於 matters-oss 前端 PR 部署,否則前端送出的
redirectUri會被舊 schema 當未知欄位拒絕。對應前端 PR:thematters/matters-oss
feat/oss-google-sso。🤖 Generated with Claude Code