feat(oauth): add the seven missing providers and open the full aggregate list

The theme shipped six direct providers while the reference carries fourteen,
and its aggregate-login channel offered three of sixteen platforms.

OAuthProviderClient now owns the providers the bundled SDK does not cover.
Douyin, Microsoft, Facebook, Twitter and Apple talk to their documented OAuth2
endpoints directly; Baidu and Alipay reuse yurunsoft, which already ships both
(Alipay needs its application private key, so provider_config learned an
extra_keys map to surface it). The broker dispatches through handles(), so the
existing start/callback routes stay provider-agnostic.

Three provider quirks needed handling rather than a plain copy:

Apple returns the callback as response_mode=form_post, and handle_callback
only read $_GET, so it now reads $_POST when the request is a POST — otherwise
every Apple login would fail with code_missing. Its client secret is built as
an ES256 JWT from Team ID / Key ID / .p8 rather than a static string.

Twitter requires PKCE. The verifier is derived from the state token, so it
travels with the existing transaction row and needs no extra storage.

Facebook hands back protocol-less avatar URLs, which are upgraded to https the
same way the OAuth avatar resolver does.

Settings gained matching toggles and credential groups on both sides — the PHP
schema and the Vue schema — and the aggregate platform list went from three to
sixteen, with CLoginClient's hard-coded allowlist replaced by the catalog
constant. Brand icons were extended so each new provider resolves to its
sprite; facebook and twitter moved to their colour sprites, and the
`twitter -> x` alias was dropped since it bypassed the new mapping.

The oauth-security contract previously asserted that Baidu and Alipay must not
appear on the OAuth surface. That was the old intent, so the assertion is
replaced with a positive one, keeping the separate check that the Alipay
payment gateway still exists.

Verification: a new harness stubs the HTTP layer and drives all five custom
clients — authorization URLs carry redirect/state (Twitter also a PKCE
challenge), identities normalize to the shared shape, Facebook's avatar is
upgraded to https, Apple's private-relay email survives, and an error payload
throws instead of yielding an empty identity. 871 widget/navigation tests pass
and the PSR-4 audit reports 0 errors.

Not covered: no live handshake happened — every provider needs real AppID and
secret pairs, and Apple/Douyin require developer-account review before the
full round trip can be exercised.
This commit is contained in:
kate522 committed 2026-11-04 18:00:29 +08:00
1 parent 6f29e3d865
commit 6db34646ed
11 files changed
+939 -28

No files matched your search

@@ -33,19 +33,20 @@ test('OAuth PHP behavior harness passes', () => {
const output = execFileSync('php', [path.join(root, 'tests/widget-system/oauth-security-harness.php')], { encoding: 'utf8' })
assert.match(output, /OAuth security harness passed/)
})
test('Baidu and Alipay are absent from the OAuth surface', () => {
for (const needle of [
'oauth_baidu_s',
'oauth_alipay_s',
'get_baidu_user_data',
'get_alipay_user_data',
'OAuthLogin\\Baidu',
'OAuthLogin\\Alipay',
"'baidu' => [",
"'alipay' => [",
]) {
assert.equal(oauthScope.includes(needle), false, `unexpected OAuth reference: ${needle}`)
test('Baidu and Alipay are wired into the OAuth surface', () => {
const catalog = read('src/Auth/OAuthProviderCatalog.php')
const client = read('src/Auth/OAuthProviderClient.php')
const schema = read('src/Admin/Schema/SchemaUsers.php')
for (const provider of ['baidu', 'alipay']) {
assert.match(catalog, new RegExp(`'${provider}'\\s*=>`), provider)
assert.match(schema, new RegExp(`oauth_${provider}_s`), provider)
}
// 复用打包的 yurun SDK,而不是自己重写签名。
assert.match(client, /Yurun\\OAuthLogin\\Baidu\\OAuth2/)
assert.match(client, /Yurun\\OAuthLogin\\Alipay\\OAuth2/)
// 支付宝的支付网关仍在,两者互不影响。
assert.match(read('src/Payment/Gateways/AlipayGateway.php'), /class AlipayGateway/)
})
test('Alipay payment remains available', () => {
@@ -71,10 +72,19 @@ test('OAuth uses one-time transactions and no PHP sessions', () => {
test('provider catalog is the canonical provider list', () => {
const catalog = read('src/Auth/OAuthProviderCatalog.php')
for (const provider of ['github', 'gitee', 'qq', 'google', 'weibo', 'weixin']) {
assert.match(catalog, new RegExp(`'${provider}'\\s*=>`))
const direct = ['github', 'gitee', 'qq', 'google', 'weibo', 'weixin', 'douyin', 'baidu', 'alipay', 'microsoft', 'facebook', 'twitter', 'apple']
for (const provider of direct) {
assert.match(catalog, new RegExp(`'${provider}'\\s*=>`), provider)
}
assert.match(catalog, /CLOGIN_TYPES = \['qq', 'weixin', 'weibo'\]/)
// 聚合登录平台与参考主题一致(16 种)。
const block = catalog.slice(catalog.indexOf('CLOGIN_TYPES = ['), catalog.indexOf('];', catalog.indexOf('CLOGIN_TYPES = [')))
const types = [...block.matchAll(/'([a-z]+)'/g)].map((m) => m[1])
assert.equal(types.length, 16, types.join(','))
for (const type of ['dingtalk', 'huawei', 'xiaomi', 'alipay', 'douyin', 'apple', 'microsoft']) {
assert.ok(types.includes(type), type)
}
assert.match(catalog, /oauth_s/)
assert.match(catalog, /oauth_bind_type/)
})