Skip to content

Commit 9bf77d1

Browse files
committed
fix(plugin-auth): a provider the boot did not declare counts as a way in only as the settings-added Google
Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Utp6CXhZcHuALPAjkDCiiT
1 parent 0b89bdf commit 9bf77d1

3 files changed

Lines changed: 30 additions & 8 deletions

File tree

‎packages/plugins/plugin-auth/src/auth-plugin.ts‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ import {
108108
reportIfNoSignInAccountExists,
109109
type SignInPathConfigView,
110110
} from './boot-sign-in-reachability.js';
111-
import { providerCredentialIndex, registerSignInMethodFloor } from './sign-in-method-floor.js';
111+
import { providerCredentialIndex, providerCredentialsFrom, registerSignInMethodFloor } from './sign-in-method-floor.js';
112112
import { judgePlatformAdmin, isPlatformAdminUser, type PlatformAdminActor } from './platform-admin-gate.js';
113113
import {
114114
decideDemoStaffEnvironmentGate,
@@ -2067,9 +2067,8 @@ export class AuthPlugin implements Plugin {
20672067
},
20682068
hostSignInHandoff: this.options.hostSignInHandoff === true,
20692069
stackConfiguredGoogle: () => !!this.configuredSocialProviders?.google,
2070-
// Not declared at boot = the Google the settings added, which the apply
2071-
// adds only with a client ID and secret.
2072-
providerHasCredentials: ({ id, type }) => this.bootProviderCredentials.get(`${type}:${id}`) ?? true,
2070+
// Read at save time: the index is set in init, after `auth:configure`.
2071+
providerHasCredentials: (provider) => providerCredentialsFrom(this.bootProviderCredentials)(provider),
20732072
env: () => ((globalThis as any)?.process?.env ?? {}) as Record<string, string | undefined>,
20742073
},
20752074
ctx.logger,

‎packages/plugins/plugin-auth/src/sign-in-method-floor.test.ts‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
* is refused at both keys, and Google filled in, or switched on over a
2929
* stored credential pair, in the same save as email and password off is
3030
* accepted;
31-
* 7. a provider listed without a credential pair is no way in.
31+
* 7. a provider listed without a credential pair is no way in, and one the
32+
* boot did not declare counts only as the settings-added Google.
3233
*/
3334

3435
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
@@ -45,7 +46,7 @@ import {
4546
import { AuthPlugin } from './auth-plugin.js';
4647
import type { AuthManager } from './auth-manager.js';
4748
import { SSO_PROVIDER_OBJECT } from './sso-client-secret.js';
48-
import { SIGN_IN_FLOOR_COPY, providerCredentialIndex } from './sign-in-method-floor.js';
49+
import { SIGN_IN_FLOOR_COPY, providerCredentialIndex, providerCredentialsFrom } from './sign-in-method-floor.js';
4950

5051
const SECRET = 'test-secret-at-least-32-chars-long';
5152

@@ -387,7 +388,7 @@ describe('the auth settings save keeps a way to sign in', () => {
387388
expect(passwordOn(manager)).toBe(true);
388389
});
389390

390-
it('indexes each boot provider, social and OIDC, by whether it holds both credentials', () => {
391+
it('indexes each boot provider, social and OIDC, by whether it holds both credentials; an unindexed one other than Google does not count', () => {
391392
const index = providerCredentialIndex(
392393
{ github: { clientId: 'id', clientSecret: 'secret' }, gitlab: { clientId: 'id', clientSecret: '' } },
393394
[{ providerId: 'okta', clientId: 'id', clientSecret: 'secret' }, { providerId: 'azure', clientId: '', clientSecret: 's' }],
@@ -399,6 +400,14 @@ describe('the auth settings save keeps a way to sign in', () => {
399400
'oidc:azure': false,
400401
});
401402
expect(providerCredentialIndex(undefined, undefined).size).toBe(0);
403+
404+
// Outside the index only the settings-added social Google counts.
405+
const has = providerCredentialsFrom(index);
406+
expect(has({ id: 'gitlab', type: 'social' })).toBe(false);
407+
expect(has({ id: 'google', type: 'social' })).toBe(true);
408+
expect(has({ id: 'google', type: 'oidc' })).toBe(false);
409+
expect(has({ id: 'bitbucket', type: 'social' })).toBe(false);
410+
expect(has({ id: 'keycloak', type: 'oidc' })).toBe(false);
402411
});
403412

404413
// ── 5. Recovery for a deployment that already stored the dead end ─────────

‎packages/plugins/plugin-auth/src/sign-in-method-floor.ts‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ export interface SignInMethodFloorDeps {
9292
/**
9393
* Whether a provider in force holds a credential pair: a non-blank `clientId`
9494
* AND `clientSecret` in the configuration it came from. Google added from the
95-
* settings has one by construction (the apply adds it only with both).
95+
* settings has one by construction (the apply adds it only with both); a
96+
* provider of unknown origin does not count ({@link providerCredentialsFrom}).
9697
*/
9798
providerHasCredentials(provider: { id: string; type: 'social' | 'oidc' }): boolean;
9899
env(): Record<string, string | undefined>;
@@ -126,6 +127,19 @@ export function providerCredentialIndex(socialProviders: unknown, oidcProviders:
126127
return index;
127128
}
128129

130+
/**
131+
* {@link SignInMethodFloorDeps.providerHasCredentials} over a boot index. A
132+
* provider the index holds answers for itself. Of the providers it does not
133+
* hold, only the social Google counts: the settings add it at runtime, and
134+
* only with a client ID and secret. Any other provider the boot did not declare
135+
* is unaccounted for, so it is not counted as a way in.
136+
*/
137+
export function providerCredentialsFrom(
138+
index: ReadonlyMap<string, boolean>,
139+
): SignInMethodFloorDeps['providerHasCredentials'] {
140+
return ({ id, type }) => index.get(`${type}:${id}`) ?? (type === 'social' && id === 'google');
141+
}
142+
129143
const isSettingsGoogle = (p: { id?: string; type?: string } | undefined): boolean =>
130144
p?.id === 'google' && p?.type !== 'oidc';
131145

0 commit comments

Comments
 (0)