Skip to content

Self-hosted personal gallery application with online photo management and albums, supporting Live/Motion Photos, EXIF parsing, geolocation recognition, and an explore map.

fix(auth): allow connected providers with different verified emails

Timothy Yin1d1f9dcf8f2c
diff --git a/apps/cloud/i18n/locales/en.json b/apps/cloud/i18n/locales/en.json
index 20f77a33..31f42954 100644
--- a/apps/cloud/i18n/locales/en.json
+++ b/apps/cloud/i18n/locales/en.json
@@ -2,7 +2,7 @@
"cloud": {
"connections": {
"title": "Connected accounts",
- "help": "Link an enabled sign-in provider using the same verified email as your account.",
+ "help": "Link an enabled sign-in provider. Its verified email can differ from your account email.",
"linked": "Connected",
"notLinked": "Not connected",
"disabled": "Connected · sign-in disabled by administrator",
@@ -12,7 +12,7 @@
"unlinkProvider": "Disconnect {provider}",
"linkedNotice": "Account connected.",
"unlinkedNotice": "Account disconnected.",
- "failed": "Unable to connect this account. Use the same verified email and ensure it is not linked to another account.",
+ "failed": "Unable to connect this account. Verify its email and ensure it is not linked to another account.",
"loadFailed": "Unable to load connected accounts. Please reload.",
"keepMethod": "Keep another available sign-in method. Set a password or connect another enabled provider before disconnecting.",
"empty": "No sign-in providers are currently available.",
diff --git a/apps/cloud/i18n/locales/zh-Hans.json b/apps/cloud/i18n/locales/zh-Hans.json
index 58660b9f..9063b195 100644
--- a/apps/cloud/i18n/locales/zh-Hans.json
+++ b/apps/cloud/i18n/locales/zh-Hans.json
@@ -2,7 +2,7 @@
"cloud": {
"connections": {
"title": "第三方账号",
- "help": "可绑定管理员已启用的登录方式,请使用与本账号相同的已验证邮箱。",
+ "help": "可绑定管理员已启用的登录方式,第三方账号的已验证邮箱可以与本账号不同。",
"linked": "已绑定",
"notLinked": "未绑定",
"disabled": "已绑定 · 管理员已停用此登录方式",
@@ -12,7 +12,7 @@
"unlinkProvider": "解绑 {provider}",
"linkedNotice": "账号绑定成功。",
"unlinkedNotice": "已解除账号绑定。",
- "failed": "绑定失败,请确认使用相同的已验证邮箱,且该第三方账号尚未绑定其他账号。",
+ "failed": "绑定失败,请确认第三方账号的邮箱已验证,且该账号尚未绑定其他平台账号。",
"loadFailed": "无法加载绑定信息,请重新加载。",
"keepMethod": "请保留另一种可用的登录方式。设置密码或绑定另一种已启用的第三方账号后,才能解绑。",
"empty": "管理员尚未启用可绑定的第三方登录方式。",
diff --git a/apps/cloud/server/utils/account-auth.ts b/apps/cloud/server/utils/account-auth.ts
index c4424504..7053487d 100644
--- a/apps/cloud/server/utils/account-auth.ts
+++ b/apps/cloud/server/utils/account-auth.ts
@@ -160,7 +160,7 @@ export function accountAuthOptions(
encryptOAuthTokens: true,
accountLinking: {
enabled: true,
- allowDifferentEmails: false,
+ allowDifferentEmails: true,
requireLocalEmailVerified: true,
trustedProviders: [],
},
diff --git a/tests/social-login.test.ts b/tests/social-login.test.ts
index b72869ce..50c35346 100644
--- a/tests/social-login.test.ts
+++ b/tests/social-login.test.ts
@@ -18,7 +18,9 @@ import {
import { parseAccountProfile } from '../packages/contracts/src/account-profile.ts'
type TestEvent = { path: string; origin?: string; raw?: string }
type TestError = { statusMessage?: string; statusCode?: number }
-type TestSession = { user: { id: string; emailVerified: boolean } } | null
+type TestSession = {
+ user: { id: string; email: string; emailVerified: boolean }
+} | null
const require = createRequire(import.meta.url)
const { Miniflare, convertV4MiniflareOptions } = createRequire(
require.resolve('wrangler/package.json'),
@@ -550,15 +552,55 @@ test('credentials are root-only, encrypted, redacted, revision fenced and disabl
)
githubId = 202
- await connect('connection=failed')
+ await connect('connection=updated')
+ assert.equal(
+ (
+ await db
+ .prepare(
+ "SELECT user_id FROM platform_accounts WHERE account_id='202' AND provider_id='github'",
+ )
+ .first()
+ ).user_id,
+ 42,
+ )
+ assert.equal(
+ (
+ await db
+ .prepare('SELECT email FROM platform_users WHERE id=42')
+ .first()
+ ).email,
+ )
assert.equal(
await db
.prepare(
- "SELECT id FROM platform_accounts WHERE account_id='202' AND provider_id='github'",
+ "SELECT id FROM platform_users WHERE email='[email protected]'",
)
.first(),
null,
)
+ const alternateEmailSession = await login('/workspace')
+ assert(alternateEmailSession)
+ assert.equal(Number(alternateEmailSession.user.id), 42)
+ assert.equal(alternateEmailSession.user.email, '[email protected]')
+ // A verified third-party account owned by someone else cannot be reassigned.
+ await db
+ .prepare(
+ "INSERT INTO platform_accounts(account_id,provider_id,user_id,created_at,updated_at) VALUES('204','github',43,1,1)",
+ )
+ .run()
+ githubId = 204
+ await connect('connection=failed')
+ assert.equal(
+ (
+ await db
+ .prepare(
+ "SELECT user_id FROM platform_accounts WHERE account_id='204' AND provider_id='github'",
+ )
+ .first()
+ ).user_id,
+ 43,
+ )
githubId = 203
verified = false