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:
1 parent
6f29e3d865
commit
6db34646ed
11 files changed
+939
-28
No files matched your search
+5
-3
@@ -352,7 +352,9 @@ final class OAuth {
|
||||
}
|
||||
|
||||
private function handle_callback(): void {
|
||||
$state = sanitize_text_field((string) ($_GET['state'] ?? ''));
|
||||
// Apple 使用 response_mode=form_post,state/code 走 POST 而不是 query。
|
||||
$input = $_SERVER['REQUEST_METHOD'] === 'POST' ? $_POST : $_GET;
|
||||
$state = sanitize_text_field((string) ($input['state'] ?? ''));
|
||||
$row = $state !== '' ? OAuthTransactionStore::claim($state, 'direct') : null;
|
||||
$payload = is_array($row['payload'] ?? null) ? $row['payload'] : [];
|
||||
$provider = sanitize_key((string) ($payload['provider'] ?? ''));
|
||||
@@ -363,10 +365,10 @@ final class OAuth {
|
||||
if ($action === 'bind' && (int) ($payload['user_id'] ?? 0) !== get_current_user_id()) {
|
||||
$this->redirect_error('state_user_mismatch', $provider, $action);
|
||||
}
|
||||
if (!empty($_GET['error'])) {
|
||||
if (!empty($input['error'])) {
|
||||
$this->redirect_error('provider_cancelled', $provider, $action);
|
||||
}
|
||||
$code = sanitize_text_field((string) ($_GET['code'] ?? ''));
|
||||
$code = sanitize_text_field((string) ($input['code'] ?? ''));
|
||||
if ($code === '') {
|
||||
$this->redirect_error('code_missing', $provider, $action);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user