@venturekit/auth 0.0.50 → 0.0.51
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -7
- package/dist/index.d.ts +1 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -2
- package/dist/index.js.map +1 -1
- package/dist/migrations/vk_auth_006_verification_code_issuance.sql +29 -0
- package/dist/server/api-keys.d.ts +10 -5
- package/dist/server/api-keys.d.ts.map +1 -1
- package/dist/server/api-keys.js +24 -8
- package/dist/server/api-keys.js.map +1 -1
- package/dist/server/config.d.ts +6 -0
- package/dist/server/config.d.ts.map +1 -1
- package/dist/server/config.js +2 -0
- package/dist/server/config.js.map +1 -1
- package/dist/server/cookies.d.ts +9 -5
- package/dist/server/cookies.d.ts.map +1 -1
- package/dist/server/cookies.js +19 -6
- package/dist/server/cookies.js.map +1 -1
- package/dist/server/errors.d.ts +18 -2
- package/dist/server/errors.d.ts.map +1 -1
- package/dist/server/errors.js +46 -3
- package/dist/server/errors.js.map +1 -1
- package/dist/server/federated/account-linking.d.ts +90 -0
- package/dist/server/federated/account-linking.d.ts.map +1 -0
- package/dist/server/federated/account-linking.js +78 -0
- package/dist/server/federated/account-linking.js.map +1 -0
- package/dist/server/federated/authorization.d.ts +81 -0
- package/dist/server/federated/authorization.d.ts.map +1 -0
- package/dist/server/federated/authorization.js +229 -0
- package/dist/server/federated/authorization.js.map +1 -0
- package/dist/server/federated/credentials.d.ts +22 -0
- package/dist/server/federated/credentials.d.ts.map +1 -0
- package/dist/server/federated/credentials.js +81 -0
- package/dist/server/federated/credentials.js.map +1 -0
- package/dist/server/federated/oauth-transaction.d.ts +54 -0
- package/dist/server/federated/oauth-transaction.d.ts.map +1 -0
- package/dist/server/federated/oauth-transaction.js +92 -0
- package/dist/server/federated/oauth-transaction.js.map +1 -0
- package/dist/server/federated/providers.d.ts +34 -0
- package/dist/server/federated/providers.d.ts.map +1 -0
- package/dist/server/federated/providers.js +65 -0
- package/dist/server/federated/providers.js.map +1 -0
- package/dist/server/federated/sign-in.d.ts +81 -0
- package/dist/server/federated/sign-in.d.ts.map +1 -0
- package/dist/server/federated/sign-in.js +180 -0
- package/dist/server/federated/sign-in.js.map +1 -0
- package/dist/server/federated/types.d.ts +36 -0
- package/dist/server/federated/types.d.ts.map +1 -0
- package/dist/server/federated/types.js +5 -0
- package/dist/server/federated/types.js.map +1 -0
- package/dist/server/federated-routes.d.ts +15 -7
- package/dist/server/federated-routes.d.ts.map +1 -1
- package/dist/server/federated-routes.js +27 -16
- package/dist/server/federated-routes.js.map +1 -1
- package/dist/server/federated.d.ts +25 -196
- package/dist/server/federated.d.ts.map +1 -1
- package/dist/server/federated.js +19 -521
- package/dist/server/federated.js.map +1 -1
- package/dist/server/forgot-password.d.ts +4 -3
- package/dist/server/forgot-password.d.ts.map +1 -1
- package/dist/server/forgot-password.js +3 -5
- package/dist/server/forgot-password.js.map +1 -1
- package/dist/server/handoff-routes.d.ts +16 -5
- package/dist/server/handoff-routes.d.ts.map +1 -1
- package/dist/server/handoff-routes.js +23 -11
- package/dist/server/handoff-routes.js.map +1 -1
- package/dist/server/impersonation.d.ts +6 -3
- package/dist/server/impersonation.d.ts.map +1 -1
- package/dist/server/impersonation.js +11 -5
- package/dist/server/impersonation.js.map +1 -1
- package/dist/server/index.d.ts +5 -2
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +2 -1
- package/dist/server/index.js.map +1 -1
- package/dist/server/invitations.d.ts +6 -2
- package/dist/server/invitations.d.ts.map +1 -1
- package/dist/server/invitations.js +6 -3
- package/dist/server/invitations.js.map +1 -1
- package/dist/server/local-cognito.d.ts +19 -0
- package/dist/server/local-cognito.d.ts.map +1 -0
- package/dist/server/local-cognito.js +19 -0
- package/dist/server/local-cognito.js.map +1 -0
- package/dist/server/refresh.d.ts +23 -12
- package/dist/server/refresh.d.ts.map +1 -1
- package/dist/server/refresh.js +35 -19
- package/dist/server/refresh.js.map +1 -1
- package/dist/server/resource-scope.d.ts +19 -0
- package/dist/server/resource-scope.d.ts.map +1 -0
- package/dist/server/resource-scope.js +2 -0
- package/dist/server/resource-scope.js.map +1 -0
- package/dist/server/route-rate-limit.d.ts +50 -0
- package/dist/server/route-rate-limit.d.ts.map +1 -0
- package/dist/server/route-rate-limit.js +39 -0
- package/dist/server/route-rate-limit.js.map +1 -0
- package/dist/server/session-routes.d.ts +9 -2
- package/dist/server/session-routes.d.ts.map +1 -1
- package/dist/server/session-routes.js +6 -4
- package/dist/server/session-routes.js.map +1 -1
- package/dist/server/sign-up.d.ts +32 -17
- package/dist/server/sign-up.d.ts.map +1 -1
- package/dist/server/sign-up.js +30 -12
- package/dist/server/sign-up.js.map +1 -1
- package/dist/server/store/postgres.d.ts.map +1 -1
- package/dist/server/store/postgres.js +43 -27
- package/dist/server/store/postgres.js.map +1 -1
- package/dist/server/verification.d.ts +76 -33
- package/dist/server/verification.d.ts.map +1 -1
- package/dist/server/verification.js +68 -67
- package/dist/server/verification.js.map +1 -1
- package/dist/server/verify.d.ts.map +1 -1
- package/dist/server/verify.js +8 -3
- package/dist/server/verify.js.map +1 -1
- package/dist/session/index.d.ts +11 -13
- package/dist/session/index.d.ts.map +1 -1
- package/dist/session/index.js +13 -14
- package/dist/session/index.js.map +1 -1
- package/package.json +6 -6
- package/src/migrations/vk_auth_006_verification_code_issuance.sql +29 -0
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Account linking — who may enter which account through a federated
|
|
3
|
+
* sign-in. A pure decision over facts, so every rule is unit-tested
|
|
4
|
+
* without Cognito; `sign-in.ts` loads the facts and applies the decision.
|
|
5
|
+
*
|
|
6
|
+
* # The binding
|
|
7
|
+
*
|
|
8
|
+
* A Cognito account is entered through a provider by ONE identity at that
|
|
9
|
+
* provider: its stable subject (`profile.externalId`), recorded on the
|
|
10
|
+
* account as `custom:<provider>Sub` the first time. After that, the
|
|
11
|
+
* address alone opens nothing: a different identity at the same provider
|
|
12
|
+
* claiming the same address (a recycled mailbox, a provider account
|
|
13
|
+
* someone else registered) is refused.
|
|
14
|
+
*
|
|
15
|
+
* # Linking — the e-mail-recovery case
|
|
16
|
+
*
|
|
17
|
+
* A user who registered with an address and a password, and later signs
|
|
18
|
+
* in with a provider asserting that same address, may land in the same
|
|
19
|
+
* account — that is how a member who forgot their password recovers it
|
|
20
|
+
* through LinkedIn. Both sides must have PROVEN the address, though:
|
|
21
|
+
*
|
|
22
|
+
* - the provider asserts the address is verified (`emailVerified`);
|
|
23
|
+
* - the existing account's address is verified (`email_verified`).
|
|
24
|
+
*
|
|
25
|
+
* Without the second condition, an attacker could register the victim's
|
|
26
|
+
* address first (unverified) and keep a session into the account the
|
|
27
|
+
* victim later "recovers" (account pre-hijacking); without the first, a
|
|
28
|
+
* provider that does not verify addresses would open any account. On a
|
|
29
|
+
* link the account's existing sessions are signed out (see `sign-in.ts`),
|
|
30
|
+
* so nothing that held the account before the link keeps it.
|
|
31
|
+
*
|
|
32
|
+
* # Adoption
|
|
33
|
+
*
|
|
34
|
+
* Accounts created by this module before subject binding existed carry
|
|
35
|
+
* `custom:federated_provider` but no subject. The first sign-in through
|
|
36
|
+
* that SAME provider binds the subject without treating it as a link —
|
|
37
|
+
* no new party gains access, so no one is signed out.
|
|
38
|
+
*/
|
|
39
|
+
import type { FederatedProfile, FederatedProvider } from './types.js';
|
|
40
|
+
/**
|
|
41
|
+
* What to do when the provider's address belongs to an account the
|
|
42
|
+
* provider is not yet bound to (a password account, or one bound to
|
|
43
|
+
* another provider):
|
|
44
|
+
*
|
|
45
|
+
* - `'link-verified'` (default) — link when both sides proved the
|
|
46
|
+
* address (see module docs), otherwise refuse with 409
|
|
47
|
+
* `federated_link_unverified`.
|
|
48
|
+
* - `'reject'` — never link; refuse with 409 `federated_account_exists`.
|
|
49
|
+
* The app asks the user to sign in the way they registered.
|
|
50
|
+
* - `'link'` — deprecated alias of `'link-verified'`. It used to link
|
|
51
|
+
* unconditionally; it now applies the verified-address rule.
|
|
52
|
+
*/
|
|
53
|
+
export type ExistingPasswordAccountPolicy = 'link-verified' | 'reject' | 'link';
|
|
54
|
+
/** The facts about an existing Cognito account the decision needs. */
|
|
55
|
+
export interface ExistingFederatedAccount {
|
|
56
|
+
/** Cognito `email_verified`. */
|
|
57
|
+
emailVerified: boolean;
|
|
58
|
+
/** `custom:federated_provider` — the provider that created / first linked the account. */
|
|
59
|
+
federatedProvider: string | null;
|
|
60
|
+
/** `custom:<provider>Sub` for the provider signing in now. */
|
|
61
|
+
boundSubject: string | null;
|
|
62
|
+
}
|
|
63
|
+
export type FederatedRejectionCode = 'federated_account_exists' | 'federated_link_unverified' | 'federated_identity_mismatch';
|
|
64
|
+
export type FederatedSignInDecision =
|
|
65
|
+
/** No account: create one bound to this identity. */
|
|
66
|
+
{
|
|
67
|
+
kind: 'create';
|
|
68
|
+
}
|
|
69
|
+
/** The account is this identity's; `bindSubject` when adopting a legacy account. */
|
|
70
|
+
| {
|
|
71
|
+
kind: 'sign-in';
|
|
72
|
+
bindSubject: boolean;
|
|
73
|
+
}
|
|
74
|
+
/** Bind this identity to an account it was not bound to; sign the old sessions out. */
|
|
75
|
+
| {
|
|
76
|
+
kind: 'link';
|
|
77
|
+
} | {
|
|
78
|
+
kind: 'reject';
|
|
79
|
+
code: FederatedRejectionCode;
|
|
80
|
+
message: string;
|
|
81
|
+
};
|
|
82
|
+
/** The Cognito attribute holding a provider's subject. Declared by `federated: [...]` (core). */
|
|
83
|
+
export declare function federatedSubjectAttribute(provider: FederatedProvider): string;
|
|
84
|
+
export declare function decideFederatedSignIn(input: {
|
|
85
|
+
existing: ExistingFederatedAccount | null;
|
|
86
|
+
provider: FederatedProvider;
|
|
87
|
+
profile: Pick<FederatedProfile, 'externalId' | 'emailVerified'>;
|
|
88
|
+
policy?: ExistingPasswordAccountPolicy;
|
|
89
|
+
}): FederatedSignInDecision;
|
|
90
|
+
//# sourceMappingURL=account-linking.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|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CAAC,EAAE,6BAA6B,CAAC;CACxC,GAAG,uBAAuB,CAsC1B"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Account linking — who may enter which account through a federated
|
|
3
|
+
* sign-in. A pure decision over facts, so every rule is unit-tested
|
|
4
|
+
* without Cognito; `sign-in.ts` loads the facts and applies the decision.
|
|
5
|
+
*
|
|
6
|
+
* # The binding
|
|
7
|
+
*
|
|
8
|
+
* A Cognito account is entered through a provider by ONE identity at that
|
|
9
|
+
* provider: its stable subject (`profile.externalId`), recorded on the
|
|
10
|
+
* account as `custom:<provider>Sub` the first time. After that, the
|
|
11
|
+
* address alone opens nothing: a different identity at the same provider
|
|
12
|
+
* claiming the same address (a recycled mailbox, a provider account
|
|
13
|
+
* someone else registered) is refused.
|
|
14
|
+
*
|
|
15
|
+
* # Linking — the e-mail-recovery case
|
|
16
|
+
*
|
|
17
|
+
* A user who registered with an address and a password, and later signs
|
|
18
|
+
* in with a provider asserting that same address, may land in the same
|
|
19
|
+
* account — that is how a member who forgot their password recovers it
|
|
20
|
+
* through LinkedIn. Both sides must have PROVEN the address, though:
|
|
21
|
+
*
|
|
22
|
+
* - the provider asserts the address is verified (`emailVerified`);
|
|
23
|
+
* - the existing account's address is verified (`email_verified`).
|
|
24
|
+
*
|
|
25
|
+
* Without the second condition, an attacker could register the victim's
|
|
26
|
+
* address first (unverified) and keep a session into the account the
|
|
27
|
+
* victim later "recovers" (account pre-hijacking); without the first, a
|
|
28
|
+
* provider that does not verify addresses would open any account. On a
|
|
29
|
+
* link the account's existing sessions are signed out (see `sign-in.ts`),
|
|
30
|
+
* so nothing that held the account before the link keeps it.
|
|
31
|
+
*
|
|
32
|
+
* # Adoption
|
|
33
|
+
*
|
|
34
|
+
* Accounts created by this module before subject binding existed carry
|
|
35
|
+
* `custom:federated_provider` but no subject. The first sign-in through
|
|
36
|
+
* that SAME provider binds the subject without treating it as a link —
|
|
37
|
+
* no new party gains access, so no one is signed out.
|
|
38
|
+
*/
|
|
39
|
+
/** The Cognito attribute holding a provider's subject. Declared by `federated: [...]` (core). */
|
|
40
|
+
export function federatedSubjectAttribute(provider) {
|
|
41
|
+
return `custom:${provider}Sub`;
|
|
42
|
+
}
|
|
43
|
+
export function decideFederatedSignIn(input) {
|
|
44
|
+
const { existing, provider, profile } = input;
|
|
45
|
+
if (!existing)
|
|
46
|
+
return { kind: 'create' };
|
|
47
|
+
if (existing.boundSubject) {
|
|
48
|
+
return existing.boundSubject === profile.externalId
|
|
49
|
+
? { kind: 'sign-in', bindSubject: false }
|
|
50
|
+
: {
|
|
51
|
+
kind: 'reject',
|
|
52
|
+
code: 'federated_identity_mismatch',
|
|
53
|
+
message: `This e-mail address belongs to an account linked to a different ${provider} profile. ` +
|
|
54
|
+
'Sign in with that profile, or with your password.',
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
if (existing.federatedProvider === provider)
|
|
58
|
+
return { kind: 'sign-in', bindSubject: true };
|
|
59
|
+
if ((input.policy ?? 'link-verified') === 'reject') {
|
|
60
|
+
return {
|
|
61
|
+
kind: 'reject',
|
|
62
|
+
code: 'federated_account_exists',
|
|
63
|
+
message: 'An account with this e-mail address already exists. Sign in the way you registered, ' +
|
|
64
|
+
'then link this provider from your account settings.',
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
if (!profile.emailVerified || !existing.emailVerified) {
|
|
68
|
+
return {
|
|
69
|
+
kind: 'reject',
|
|
70
|
+
code: 'federated_link_unverified',
|
|
71
|
+
message: 'An account with this e-mail address already exists, and the address is not verified on ' +
|
|
72
|
+
(profile.emailVerified ? 'that account' : `your ${provider} profile`) +
|
|
73
|
+
'. Sign in the way you registered.',
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
return { kind: 'link' };
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=account-linking.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"account-linking.js","sourceRoot":"","sources":["../../../src/server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CAAC,cAAc,CAAC,CAAC,CAAC,QAAQ,QAAQ,UAAU,CAAC;gBACrE,mCAAmC;SACtC,CAAC;IACJ,CAAC;IACD,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;AAC1B,CAAC"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The OAuth Authorization Code legs: building the authorize URL and
|
|
3
|
+
* exchanging the returned code for a {@link FederatedProfile}.
|
|
4
|
+
*
|
|
5
|
+
* `id_token`s are received directly from the provider's token endpoint
|
|
6
|
+
* over TLS, on a back-channel call this server initiated, so OIDC Core
|
|
7
|
+
* §3.1.3.7 lets us skip the signature check — but NOT the claim checks:
|
|
8
|
+
* the token must be issued by the provider (`iss`), for THIS client
|
|
9
|
+
* (`aud` / `azp`), still valid (`exp`), and echo this transaction's
|
|
10
|
+
* `nonce`. Those are what stop a token minted for another application
|
|
11
|
+
* from being replayed here.
|
|
12
|
+
*
|
|
13
|
+
* Error messages carry the provider's OAuth `error` code
|
|
14
|
+
* (`invalid_grant`, `redirect_uri_mismatch`, …) but never its response
|
|
15
|
+
* body, which can echo request parameters.
|
|
16
|
+
*/
|
|
17
|
+
import { type OAuthTransaction } from './oauth-transaction.js';
|
|
18
|
+
import type { FederatedEnv, FederatedProfile, FederatedProvider } from './types.js';
|
|
19
|
+
export interface BuildAuthorizeUrlInput {
|
|
20
|
+
provider: FederatedProvider;
|
|
21
|
+
/**
|
|
22
|
+
* Where the IdP should redirect after auth. Must be a page on your
|
|
23
|
+
* SPA and must be registered as an allowed redirect URI in the IdP
|
|
24
|
+
* console — Google / Facebook reject mismatches.
|
|
25
|
+
*/
|
|
26
|
+
redirectUri: string;
|
|
27
|
+
/** From {@link createOAuthTransaction}; persist it with `serializeOAuthTransaction`. */
|
|
28
|
+
transaction: OAuthTransaction;
|
|
29
|
+
/** Override default scopes if you need extra IdP permissions. */
|
|
30
|
+
scopes?: string[];
|
|
31
|
+
/**
|
|
32
|
+
* Extra query parameters, e.g. `prompt=select_account` (Google) or
|
|
33
|
+
* `auth_type=rerequest` (Facebook re-consent). They cannot replace the
|
|
34
|
+
* parameters the flow's security rests on.
|
|
35
|
+
*/
|
|
36
|
+
extraParams?: Record<string, string>;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Build the IdP authorize URL the SPA navigates to after `start`.
|
|
40
|
+
*
|
|
41
|
+
* Loads the OAuth `client_id` from Secrets Manager (cached). The
|
|
42
|
+
* `client_secret` is NOT used here — it's only needed at token exchange.
|
|
43
|
+
*/
|
|
44
|
+
export declare function buildAuthorizeUrl(input: BuildAuthorizeUrlInput, env?: FederatedEnv): Promise<string>;
|
|
45
|
+
export interface ExchangeAuthorizationCodeInput {
|
|
46
|
+
provider: FederatedProvider;
|
|
47
|
+
/** The `code` query param the IdP appended to `redirectUri`. */
|
|
48
|
+
code: string;
|
|
49
|
+
/**
|
|
50
|
+
* Must match the `redirectUri` used in `buildAuthorizeUrl`. Both
|
|
51
|
+
* Google and Facebook compare these byte-for-byte and 400 on a
|
|
52
|
+
* mismatch.
|
|
53
|
+
*/
|
|
54
|
+
redirectUri: string;
|
|
55
|
+
/** The transaction `verifyOAuthTransaction` returned for this callback. */
|
|
56
|
+
transaction: OAuthTransaction;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Exchange an OAuth `code` for tokens at the IdP, then resolve the
|
|
60
|
+
* {@link FederatedProfile}. Throws {@link AuthError}
|
|
61
|
+
* (`federated_token_invalid`, HTTP 401) on any IdP or claim error.
|
|
62
|
+
*/
|
|
63
|
+
export declare function exchangeAuthorizationCode(input: ExchangeAuthorizationCodeInput, env?: FederatedEnv): Promise<FederatedProfile>;
|
|
64
|
+
export interface IdTokenExpectations {
|
|
65
|
+
/** Accepted `iss` values. */
|
|
66
|
+
issuers: readonly string[];
|
|
67
|
+
/** This application's OAuth client id. */
|
|
68
|
+
audience: string;
|
|
69
|
+
/** The transaction's nonce, when the provider echoes one. */
|
|
70
|
+
nonce?: string;
|
|
71
|
+
/** Clock override (tests). */
|
|
72
|
+
now?: Date;
|
|
73
|
+
/** Allowed clock skew in seconds (default 300). */
|
|
74
|
+
skewSeconds?: number;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Decode an `id_token` received from the provider's token endpoint and
|
|
78
|
+
* check its claims. Throws `federated_token_invalid` on any mismatch.
|
|
79
|
+
*/
|
|
80
|
+
export declare function validateIdTokenClaims(idToken: string, expected: IdTokenExpectations): Record<string, unknown>;
|
|
81
|
+
//# sourceMappingURL=authorization.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authorization.d.ts","sourceRoot":"","sources":["../../../src/server/federated/authorization.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAMH,OAAO,EAAiB,KAAK,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAE9E,OAAO,KAAK,EAAE,YAAY,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAMpF,MAAM,WAAW,sBAAsB;IACrC,QAAQ,EAAE,iBAAiB,CAAC;IAC5B;;;;OAIG;IACH,WAAW,EAAE,MAAM,CAAC;IACpB,wFAAwF;IACxF,WAAW,EAAE,gBAAgB,CAAC;IAC9B,iEAAiE;IACjE,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB;;;;OAIG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACtC;AA4BD;;;;;GAKG;AACH,wBAAsB,iBAAiB,CACrC,KAAK,EAAE,sBAAsB,EAC7B,GAAG,GAAE,YAA0B,GAC9B,OAAO,CAAC,MAAM,CAAC,CAuBjB;AAMD,MAAM,WAAW,8BAA8B;IAC7C,QAAQ,EAAE,iBAAiB,CAAC;IAC5B,gEAAgE;IAChE,IAAI,EAAE,MAAM,CAAC;IACb;;;;OAIG;IACH,WAAW,EAAE,MAAM,CAAC;IACpB,2EAA2E;IAC3E,WAAW,EAAE,gBAAgB,CAAC;CAC/B;AAYD;;;;GAIG;AACH,wBAAsB,yBAAyB,CAC7C,KAAK,EAAE,8BAA8B,EACrC,GAAG,GAAE,YAA0B,GAC9B,OAAO,CAAC,gBAAgB,CAAC,CAyB3B;AA4GD,MAAM,WAAW,mBAAmB;IAClC,6BAA6B;IAC7B,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;IAC3B,0CAA0C;IAC1C,QAAQ,EAAE,MAAM,CAAC;IACjB,6DAA6D;IAC7D,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,8BAA8B;IAC9B,GAAG,CAAC,EAAE,IAAI,CAAC;IACX,mDAAmD;IACnD,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,mBAAmB,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAiB7G"}
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The OAuth Authorization Code legs: building the authorize URL and
|
|
3
|
+
* exchanging the returned code for a {@link FederatedProfile}.
|
|
4
|
+
*
|
|
5
|
+
* `id_token`s are received directly from the provider's token endpoint
|
|
6
|
+
* over TLS, on a back-channel call this server initiated, so OIDC Core
|
|
7
|
+
* §3.1.3.7 lets us skip the signature check — but NOT the claim checks:
|
|
8
|
+
* the token must be issued by the provider (`iss`), for THIS client
|
|
9
|
+
* (`aud` / `azp`), still valid (`exp`), and echo this transaction's
|
|
10
|
+
* `nonce`. Those are what stop a token minted for another application
|
|
11
|
+
* from being replayed here.
|
|
12
|
+
*
|
|
13
|
+
* Error messages carry the provider's OAuth `error` code
|
|
14
|
+
* (`invalid_grant`, `redirect_uri_mismatch`, …) but never its response
|
|
15
|
+
* body, which can echo request parameters.
|
|
16
|
+
*/
|
|
17
|
+
import { createHmac } from 'node:crypto';
|
|
18
|
+
import { AuthError } from '../errors.js';
|
|
19
|
+
import { decodeJwtClaims } from '../token-utils.js';
|
|
20
|
+
import { loadFederatedProviderCredentials } from './credentials.js';
|
|
21
|
+
import { pkceChallenge } from './oauth-transaction.js';
|
|
22
|
+
import { providerDescriptor } from './providers.js';
|
|
23
|
+
/** Parameters the flow sets itself — `extraParams` may not override them. */
|
|
24
|
+
const RESERVED_AUTHORIZE_PARAMS = new Set([
|
|
25
|
+
'response_type',
|
|
26
|
+
'client_id',
|
|
27
|
+
'redirect_uri',
|
|
28
|
+
'scope',
|
|
29
|
+
'state',
|
|
30
|
+
'code_challenge',
|
|
31
|
+
'code_challenge_method',
|
|
32
|
+
'nonce',
|
|
33
|
+
]);
|
|
34
|
+
function assertTransactionFits(provider, transaction) {
|
|
35
|
+
const descriptor = providerDescriptor(provider);
|
|
36
|
+
if (transaction.provider !== provider) {
|
|
37
|
+
throw new AuthError('federated_transaction_invalid', `OAuth transaction was minted for ${transaction.provider}, not ${provider}`, 500);
|
|
38
|
+
}
|
|
39
|
+
if (descriptor.pkce && !transaction.codeVerifier) {
|
|
40
|
+
throw new AuthError('federated_transaction_invalid', `[${provider}] PKCE is required — mint the transaction with createOAuthTransaction()`, 500);
|
|
41
|
+
}
|
|
42
|
+
if (descriptor.nonce && !transaction.nonce) {
|
|
43
|
+
throw new AuthError('federated_transaction_invalid', `[${provider}] a nonce is required — mint the transaction with createOAuthTransaction()`, 500);
|
|
44
|
+
}
|
|
45
|
+
return descriptor;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Build the IdP authorize URL the SPA navigates to after `start`.
|
|
49
|
+
*
|
|
50
|
+
* Loads the OAuth `client_id` from Secrets Manager (cached). The
|
|
51
|
+
* `client_secret` is NOT used here — it's only needed at token exchange.
|
|
52
|
+
*/
|
|
53
|
+
export async function buildAuthorizeUrl(input, env = process.env) {
|
|
54
|
+
const { provider, redirectUri, transaction, scopes, extraParams } = input;
|
|
55
|
+
const descriptor = assertTransactionFits(provider, transaction);
|
|
56
|
+
for (const key of Object.keys(extraParams ?? {})) {
|
|
57
|
+
if (RESERVED_AUTHORIZE_PARAMS.has(key)) {
|
|
58
|
+
throw new AuthError('invalid_parameter', `extraParams may not set "${key}"`, 500);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
const { clientId } = await loadFederatedProviderCredentials(provider, env);
|
|
62
|
+
const url = new URL(descriptor.authorizeEndpoint);
|
|
63
|
+
for (const [k, v] of Object.entries(extraParams ?? {}))
|
|
64
|
+
url.searchParams.set(k, v);
|
|
65
|
+
url.searchParams.set('response_type', 'code');
|
|
66
|
+
url.searchParams.set('client_id', clientId);
|
|
67
|
+
url.searchParams.set('redirect_uri', redirectUri);
|
|
68
|
+
url.searchParams.set('scope', (scopes ?? descriptor.defaultScopes).join(' '));
|
|
69
|
+
url.searchParams.set('state', transaction.state);
|
|
70
|
+
if (transaction.codeVerifier) {
|
|
71
|
+
url.searchParams.set('code_challenge', pkceChallenge(transaction.codeVerifier));
|
|
72
|
+
url.searchParams.set('code_challenge_method', 'S256');
|
|
73
|
+
}
|
|
74
|
+
if (transaction.nonce)
|
|
75
|
+
url.searchParams.set('nonce', transaction.nonce);
|
|
76
|
+
return url.toString();
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Exchange an OAuth `code` for tokens at the IdP, then resolve the
|
|
80
|
+
* {@link FederatedProfile}. Throws {@link AuthError}
|
|
81
|
+
* (`federated_token_invalid`, HTTP 401) on any IdP or claim error.
|
|
82
|
+
*/
|
|
83
|
+
export async function exchangeAuthorizationCode(input, env = process.env) {
|
|
84
|
+
const { provider, code, redirectUri, transaction } = input;
|
|
85
|
+
const descriptor = assertTransactionFits(provider, transaction);
|
|
86
|
+
const { clientId, clientSecret } = await loadFederatedProviderCredentials(provider, env);
|
|
87
|
+
const ctx = { provider, descriptor, code, redirectUri, transaction, clientId, clientSecret };
|
|
88
|
+
switch (provider) {
|
|
89
|
+
case 'google':
|
|
90
|
+
case 'linkedin':
|
|
91
|
+
return exchangeOidc(ctx);
|
|
92
|
+
case 'facebook':
|
|
93
|
+
return exchangeFacebook(ctx);
|
|
94
|
+
case 'apple':
|
|
95
|
+
throw new AuthError('federated_provider_not_configured', 'Sign in with Apple requires a JWT-signed client_secret rotated ' +
|
|
96
|
+
'every 6 months — implement the Apple-specific exchange in your ' +
|
|
97
|
+
'application until VentureKit ships a built-in helper.', 500);
|
|
98
|
+
default: {
|
|
99
|
+
const _exhaustive = provider;
|
|
100
|
+
void _exhaustive;
|
|
101
|
+
throw new AuthError('federated_provider_not_configured', `Unknown federated provider: ${String(provider)}`, 500);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
const invalid = (message) => new AuthError('federated_token_invalid', message, 401);
|
|
106
|
+
/** `HTTP 400 (invalid_grant)` — the OAuth error code without the body around it. */
|
|
107
|
+
async function describeTokenFailure(res) {
|
|
108
|
+
let code = '';
|
|
109
|
+
try {
|
|
110
|
+
const body = (await res.json());
|
|
111
|
+
if (typeof body.error === 'string' && /^[a-z0-9_.-]{1,64}$/i.test(body.error))
|
|
112
|
+
code = ` (${body.error})`;
|
|
113
|
+
}
|
|
114
|
+
catch {
|
|
115
|
+
// Not JSON — the status alone is reported.
|
|
116
|
+
}
|
|
117
|
+
return `HTTP ${res.status}${code}`;
|
|
118
|
+
}
|
|
119
|
+
async function readTokenResponse(ctx, res) {
|
|
120
|
+
if (!res.ok)
|
|
121
|
+
throw invalid(`${ctx.provider} token exchange failed: ${await describeTokenFailure(res)}`);
|
|
122
|
+
return (await res.json());
|
|
123
|
+
}
|
|
124
|
+
/** Google / LinkedIn: form POST to the token endpoint, profile from the id_token. */
|
|
125
|
+
async function exchangeOidc(ctx) {
|
|
126
|
+
const body = new URLSearchParams({
|
|
127
|
+
code: ctx.code,
|
|
128
|
+
client_id: ctx.clientId,
|
|
129
|
+
client_secret: ctx.clientSecret,
|
|
130
|
+
redirect_uri: ctx.redirectUri,
|
|
131
|
+
grant_type: 'authorization_code',
|
|
132
|
+
});
|
|
133
|
+
if (ctx.transaction.codeVerifier)
|
|
134
|
+
body.set('code_verifier', ctx.transaction.codeVerifier);
|
|
135
|
+
const tokens = await readTokenResponse(ctx, await fetch(ctx.descriptor.tokenEndpoint, {
|
|
136
|
+
method: 'POST',
|
|
137
|
+
headers: { 'content-type': 'application/x-www-form-urlencoded' },
|
|
138
|
+
body,
|
|
139
|
+
}));
|
|
140
|
+
if (typeof tokens['id_token'] !== 'string') {
|
|
141
|
+
throw invalid(`${ctx.provider} token exchange returned no id_token — request the \`openid\` scope` +
|
|
142
|
+
(ctx.provider === 'linkedin' ? ' and enable "Sign In with LinkedIn using OpenID Connect" on the app' : ''));
|
|
143
|
+
}
|
|
144
|
+
const claims = validateIdTokenClaims(tokens['id_token'], {
|
|
145
|
+
issuers: ctx.descriptor.issuers,
|
|
146
|
+
audience: ctx.clientId,
|
|
147
|
+
nonce: ctx.transaction.nonce,
|
|
148
|
+
});
|
|
149
|
+
const sub = typeof claims['sub'] === 'string' ? claims['sub'] : null;
|
|
150
|
+
const email = typeof claims['email'] === 'string' ? claims['email'].toLowerCase() : null;
|
|
151
|
+
// LinkedIn has shipped `email_verified` as both `true` and `"true"`.
|
|
152
|
+
const emailVerified = claims['email_verified'] === true || claims['email_verified'] === 'true';
|
|
153
|
+
if (!sub || !email || !emailVerified) {
|
|
154
|
+
throw invalid(`${ctx.provider} id_token missing the required verified email claim — request the \`email\` scope`);
|
|
155
|
+
}
|
|
156
|
+
return {
|
|
157
|
+
externalId: sub,
|
|
158
|
+
email,
|
|
159
|
+
emailVerified,
|
|
160
|
+
...(typeof claims['name'] === 'string' ? { name: claims['name'] } : {}),
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Facebook: no id_token on the manual flow — the token response carries
|
|
165
|
+
* an access token and the profile comes from the Graph API. Meta does not
|
|
166
|
+
* say whether the address was verified, so the profile reports
|
|
167
|
+
* `emailVerified: false`: such an account is never linked to an existing
|
|
168
|
+
* one, and is created with an unverified address.
|
|
169
|
+
*/
|
|
170
|
+
async function exchangeFacebook(ctx) {
|
|
171
|
+
const tokenUrl = new URL(ctx.descriptor.tokenEndpoint);
|
|
172
|
+
tokenUrl.searchParams.set('code', ctx.code);
|
|
173
|
+
tokenUrl.searchParams.set('client_id', ctx.clientId);
|
|
174
|
+
tokenUrl.searchParams.set('client_secret', ctx.clientSecret);
|
|
175
|
+
tokenUrl.searchParams.set('redirect_uri', ctx.redirectUri);
|
|
176
|
+
if (ctx.transaction.codeVerifier)
|
|
177
|
+
tokenUrl.searchParams.set('code_verifier', ctx.transaction.codeVerifier);
|
|
178
|
+
const tokens = await readTokenResponse(ctx, await fetch(tokenUrl));
|
|
179
|
+
const accessToken = tokens['access_token'];
|
|
180
|
+
if (typeof accessToken !== 'string')
|
|
181
|
+
throw invalid('facebook token exchange returned no access_token');
|
|
182
|
+
// appsecret_proof = HMAC_SHA256(access_token, app_secret) — Meta
|
|
183
|
+
// requires it for sensitive scopes and recommends it for everything.
|
|
184
|
+
const proof = createHmac('sha256', ctx.clientSecret).update(accessToken).digest('hex');
|
|
185
|
+
const meUrl = new URL('https://graph.facebook.com/v18.0/me');
|
|
186
|
+
meUrl.searchParams.set('fields', 'id,email,name');
|
|
187
|
+
meUrl.searchParams.set('access_token', accessToken);
|
|
188
|
+
meUrl.searchParams.set('appsecret_proof', proof);
|
|
189
|
+
const meRes = await fetch(meUrl);
|
|
190
|
+
if (!meRes.ok)
|
|
191
|
+
throw invalid(`facebook /me failed: HTTP ${meRes.status}`);
|
|
192
|
+
const me = (await meRes.json());
|
|
193
|
+
if (typeof me.id !== 'string' || typeof me.email !== 'string') {
|
|
194
|
+
throw invalid('facebook profile missing id or email — request the `email` scope');
|
|
195
|
+
}
|
|
196
|
+
return {
|
|
197
|
+
externalId: me.id,
|
|
198
|
+
email: me.email.toLowerCase(),
|
|
199
|
+
emailVerified: false,
|
|
200
|
+
...(typeof me.name === 'string' ? { name: me.name } : {}),
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Decode an `id_token` received from the provider's token endpoint and
|
|
205
|
+
* check its claims. Throws `federated_token_invalid` on any mismatch.
|
|
206
|
+
*/
|
|
207
|
+
export function validateIdTokenClaims(idToken, expected) {
|
|
208
|
+
const claims = decodeJwtClaims(idToken);
|
|
209
|
+
if (!claims)
|
|
210
|
+
throw invalid('Malformed id_token');
|
|
211
|
+
const nowSec = Math.floor((expected.now ?? new Date()).getTime() / 1000);
|
|
212
|
+
const skew = expected.skewSeconds ?? 300;
|
|
213
|
+
if (typeof claims['iss'] !== 'string' || !expected.issuers.includes(claims['iss'])) {
|
|
214
|
+
throw invalid('id_token was not issued by the expected provider');
|
|
215
|
+
}
|
|
216
|
+
const aud = claims['aud'];
|
|
217
|
+
const audiences = Array.isArray(aud) ? aud : [aud];
|
|
218
|
+
if (!audiences.includes(expected.audience))
|
|
219
|
+
throw invalid('id_token was issued for another client');
|
|
220
|
+
// Several audiences: the authorized party must be us.
|
|
221
|
+
if (audiences.length > 1 && claims['azp'] !== expected.audience)
|
|
222
|
+
throw invalid('id_token authorized party mismatch');
|
|
223
|
+
if (typeof claims['exp'] !== 'number' || claims['exp'] + skew < nowSec)
|
|
224
|
+
throw invalid('id_token has expired');
|
|
225
|
+
if (expected.nonce !== undefined && claims['nonce'] !== expected.nonce)
|
|
226
|
+
throw invalid('id_token nonce mismatch');
|
|
227
|
+
return claims;
|
|
228
|
+
}
|
|
229
|
+
//# sourceMappingURL=authorization.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authorization.js","sourceRoot":"","sources":["../../../src/server/federated/authorization.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAA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B,CAAC,CAAC;IACjH,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OAuth client-credential resolution (env override → Secrets Manager),
|
|
3
|
+
* cached for the lifetime of the Lambda container.
|
|
4
|
+
*/
|
|
5
|
+
import type { FederatedEnv, FederatedProvider, FederatedProviderCredentials } from './types.js';
|
|
6
|
+
/**
|
|
7
|
+
* Read the OAuth client credentials for `provider`.
|
|
8
|
+
*
|
|
9
|
+
* Resolution order:
|
|
10
|
+
* 1. **Env var override** — `COGNITO_FEDERATED_<PROVIDER>_CLIENT_ID`
|
|
11
|
+
* and `COGNITO_FEDERATED_<PROVIDER>_CLIENT_SECRET`. Use this for
|
|
12
|
+
* local `vk dev` testing so you don't need Secrets Manager.
|
|
13
|
+
* 2. **Secrets Manager** — ARN from `COGNITO_FEDERATED_<PROVIDER>_SECRET_ARN`;
|
|
14
|
+
* the secret value is JSON `{"clientId":"…","clientSecret":"…"}`.
|
|
15
|
+
* This is the production path.
|
|
16
|
+
*
|
|
17
|
+
* Cached for the lifetime of the Lambda container.
|
|
18
|
+
*/
|
|
19
|
+
export declare function loadFederatedProviderCredentials(provider: FederatedProvider, env?: FederatedEnv): Promise<FederatedProviderCredentials>;
|
|
20
|
+
/** Test-only — drop the cached credentials between vitest runs. */
|
|
21
|
+
export declare function _resetFederatedCredentialsForTesting(): void;
|
|
22
|
+
//# sourceMappingURL=credentials.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"credentials.d.ts","sourceRoot":"","sources":["../../../src/server/federated/credentials.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAAE,YAAY,EAAE,iBAAiB,EAAE,4BAA4B,EAAE,MAAM,YAAY,CAAC;AAIhG;;;;;;;;;;;;GAYG;AACH,wBAAsB,gCAAgC,CACpD,QAAQ,EAAE,iBAAiB,EAC3B,GAAG,GAAE,YAA0B,GAC9B,OAAO,CAAC,4BAA4B,CAAC,CA+EvC;AAED,mEAAmE;AACnE,wBAAgB,oCAAoC,IAAI,IAAI,CAE3D"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OAuth client-credential resolution (env override → Secrets Manager),
|
|
3
|
+
* cached for the lifetime of the Lambda container.
|
|
4
|
+
*/
|
|
5
|
+
import { AuthError } from '../errors.js';
|
|
6
|
+
const credentialsCache = new Map();
|
|
7
|
+
/**
|
|
8
|
+
* Read the OAuth client credentials for `provider`.
|
|
9
|
+
*
|
|
10
|
+
* Resolution order:
|
|
11
|
+
* 1. **Env var override** — `COGNITO_FEDERATED_<PROVIDER>_CLIENT_ID`
|
|
12
|
+
* and `COGNITO_FEDERATED_<PROVIDER>_CLIENT_SECRET`. Use this for
|
|
13
|
+
* local `vk dev` testing so you don't need Secrets Manager.
|
|
14
|
+
* 2. **Secrets Manager** — ARN from `COGNITO_FEDERATED_<PROVIDER>_SECRET_ARN`;
|
|
15
|
+
* the secret value is JSON `{"clientId":"…","clientSecret":"…"}`.
|
|
16
|
+
* This is the production path.
|
|
17
|
+
*
|
|
18
|
+
* Cached for the lifetime of the Lambda container.
|
|
19
|
+
*/
|
|
20
|
+
export async function loadFederatedProviderCredentials(provider, env = process.env) {
|
|
21
|
+
const cached = credentialsCache.get(provider);
|
|
22
|
+
if (cached)
|
|
23
|
+
return cached;
|
|
24
|
+
// Dev mode shortcut — read credentials directly from env vars so you
|
|
25
|
+
// don't need Secrets Manager for local `vk dev` testing.
|
|
26
|
+
const clientIdVar = `COGNITO_FEDERATED_${provider.toUpperCase()}_CLIENT_ID`;
|
|
27
|
+
const clientSecretVar = `COGNITO_FEDERATED_${provider.toUpperCase()}_CLIENT_SECRET`;
|
|
28
|
+
const devClientId = env[clientIdVar];
|
|
29
|
+
const devClientSecret = env[clientSecretVar];
|
|
30
|
+
if (devClientId && devClientSecret) {
|
|
31
|
+
const creds = {
|
|
32
|
+
clientId: devClientId,
|
|
33
|
+
clientSecret: devClientSecret,
|
|
34
|
+
};
|
|
35
|
+
credentialsCache.set(provider, creds);
|
|
36
|
+
return creds;
|
|
37
|
+
}
|
|
38
|
+
const envVar = `COGNITO_FEDERATED_${provider.toUpperCase()}_SECRET_ARN`;
|
|
39
|
+
const arn = env[envVar];
|
|
40
|
+
if (!arn) {
|
|
41
|
+
throw new AuthError('federated_provider_not_configured', `[${provider}] missing env var ${envVar} — declare ` +
|
|
42
|
+
`\`federated: ['${provider}']\` on the auth intent in vk.config.ts ` +
|
|
43
|
+
`so VentureKit provisions the Secrets Manager placeholder, then ` +
|
|
44
|
+
`populate it with the OAuth client credentials from the IdP console.`, 500);
|
|
45
|
+
}
|
|
46
|
+
const { SecretsManagerClient, GetSecretValueCommand } = await import('@aws-sdk/client-secrets-manager');
|
|
47
|
+
const client = new SecretsManagerClient({
|
|
48
|
+
region: env['AWS_REGION'] ?? env['COGNITO_REGION'],
|
|
49
|
+
});
|
|
50
|
+
const res = await client.send(new GetSecretValueCommand({ SecretId: arn }));
|
|
51
|
+
if (!res.SecretString) {
|
|
52
|
+
throw new AuthError('federated_provider_not_configured', `[${provider}] Secrets Manager entry ${arn} is empty`, 500);
|
|
53
|
+
}
|
|
54
|
+
let parsed;
|
|
55
|
+
try {
|
|
56
|
+
parsed = JSON.parse(res.SecretString);
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
throw new AuthError('federated_provider_not_configured', `[${provider}] Secrets Manager entry ${arn} is not valid JSON`, 500);
|
|
60
|
+
}
|
|
61
|
+
if (!parsed.clientId ||
|
|
62
|
+
!parsed.clientSecret ||
|
|
63
|
+
parsed.clientId === 'PLACEHOLDER' ||
|
|
64
|
+
parsed.clientSecret === 'PLACEHOLDER') {
|
|
65
|
+
throw new AuthError('federated_provider_not_configured', `[${provider}] Secrets Manager entry ${arn} still holds the ` +
|
|
66
|
+
`placeholder. Populate it with the OAuth client id + secret ` +
|
|
67
|
+
`from the IdP console: aws secretsmanager put-secret-value ` +
|
|
68
|
+
`--secret-id ${arn} --secret-string '{"clientId":"…","clientSecret":"…"}'`, 500);
|
|
69
|
+
}
|
|
70
|
+
const creds = {
|
|
71
|
+
clientId: parsed.clientId,
|
|
72
|
+
clientSecret: parsed.clientSecret,
|
|
73
|
+
};
|
|
74
|
+
credentialsCache.set(provider, creds);
|
|
75
|
+
return creds;
|
|
76
|
+
}
|
|
77
|
+
/** Test-only — drop the cached credentials between vitest runs. */
|
|
78
|
+
export function _resetFederatedCredentialsForTesting() {
|
|
79
|
+
credentialsCache.clear();
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=credentials.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"credentials.js","sourceRoot":"","sources":["../../../src/server/federated/credentials.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAGzC,MAAM,gBAAgB,GAAG,IAAI,GAAG,EAAmD,CAAC;AAEpF;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,KAAK,UAAU,gCAAgC,CACpD,QAA2B,EAC3B,MAAoB,OAAO,CAAC,GAAG;IAE/B,MAAM,MAAM,GAAG,gBAAgB,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAC9C,IAAI,MAAM;QAAE,OAAO,MAAM,CAAC;IAE1B,qEAAqE;IACrE,yDAAyD;IACzD,MAAM,WAAW,GAAG,qBAAqB,QAAQ,CAAC,WAAW,EAAE,YAAY,CAAC;IAC5E,MAAM,eAAe,GAAG,qBAAqB,QAAQ,CAAC,WAAW,EAAE,gBAAgB,CAAC;IACpF,MAAM,WAAW,GAAG,GAAG,CAAC,WAAW,CAAC,CAAC;IACrC,MAAM,eAAe,GAAG,GAAG,CAAC,eAAe,CAAC,CAAC;IAC7C,IAAI,WAAW,IAAI,eAAe,EAAE,CAAC;QACnC,MAAM,KAAK,GAAiC;YAC1C,QAAQ,EAAE,WAAW;YACrB,YAAY,EAAE,e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