@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.
Files changed (118) hide show
  1. package/README.md +8 -7
  2. package/dist/index.d.ts +1 -2
  3. package/dist/index.d.ts.map +1 -1
  4. package/dist/index.js +1 -2
  5. package/dist/index.js.map +1 -1
  6. package/dist/migrations/vk_auth_006_verification_code_issuance.sql +29 -0
  7. package/dist/server/api-keys.d.ts +10 -5
  8. package/dist/server/api-keys.d.ts.map +1 -1
  9. package/dist/server/api-keys.js +24 -8
  10. package/dist/server/api-keys.js.map +1 -1
  11. package/dist/server/config.d.ts +6 -0
  12. package/dist/server/config.d.ts.map +1 -1
  13. package/dist/server/config.js +2 -0
  14. package/dist/server/config.js.map +1 -1
  15. package/dist/server/cookies.d.ts +9 -5
  16. package/dist/server/cookies.d.ts.map +1 -1
  17. package/dist/server/cookies.js +19 -6
  18. package/dist/server/cookies.js.map +1 -1
  19. package/dist/server/errors.d.ts +18 -2
  20. package/dist/server/errors.d.ts.map +1 -1
  21. package/dist/server/errors.js +46 -3
  22. package/dist/server/errors.js.map +1 -1
  23. package/dist/server/federated/account-linking.d.ts +90 -0
  24. package/dist/server/federated/account-linking.d.ts.map +1 -0
  25. package/dist/server/federated/account-linking.js +78 -0
  26. package/dist/server/federated/account-linking.js.map +1 -0
  27. package/dist/server/federated/authorization.d.ts +81 -0
  28. package/dist/server/federated/authorization.d.ts.map +1 -0
  29. package/dist/server/federated/authorization.js +229 -0
  30. package/dist/server/federated/authorization.js.map +1 -0
  31. package/dist/server/federated/credentials.d.ts +22 -0
  32. package/dist/server/federated/credentials.d.ts.map +1 -0
  33. package/dist/server/federated/credentials.js +81 -0
  34. package/dist/server/federated/credentials.js.map +1 -0
  35. package/dist/server/federated/oauth-transaction.d.ts +54 -0
  36. package/dist/server/federated/oauth-transaction.d.ts.map +1 -0
  37. package/dist/server/federated/oauth-transaction.js +92 -0
  38. package/dist/server/federated/oauth-transaction.js.map +1 -0
  39. package/dist/server/federated/providers.d.ts +34 -0
  40. package/dist/server/federated/providers.d.ts.map +1 -0
  41. package/dist/server/federated/providers.js +65 -0
  42. package/dist/server/federated/providers.js.map +1 -0
  43. package/dist/server/federated/sign-in.d.ts +81 -0
  44. package/dist/server/federated/sign-in.d.ts.map +1 -0
  45. package/dist/server/federated/sign-in.js +180 -0
  46. package/dist/server/federated/sign-in.js.map +1 -0
  47. package/dist/server/federated/types.d.ts +36 -0
  48. package/dist/server/federated/types.d.ts.map +1 -0
  49. package/dist/server/federated/types.js +5 -0
  50. package/dist/server/federated/types.js.map +1 -0
  51. package/dist/server/federated-routes.d.ts +15 -7
  52. package/dist/server/federated-routes.d.ts.map +1 -1
  53. package/dist/server/federated-routes.js +27 -16
  54. package/dist/server/federated-routes.js.map +1 -1
  55. package/dist/server/federated.d.ts +25 -196
  56. package/dist/server/federated.d.ts.map +1 -1
  57. package/dist/server/federated.js +19 -521
  58. package/dist/server/federated.js.map +1 -1
  59. package/dist/server/forgot-password.d.ts +4 -3
  60. package/dist/server/forgot-password.d.ts.map +1 -1
  61. package/dist/server/forgot-password.js +3 -5
  62. package/dist/server/forgot-password.js.map +1 -1
  63. package/dist/server/handoff-routes.d.ts +16 -5
  64. package/dist/server/handoff-routes.d.ts.map +1 -1
  65. package/dist/server/handoff-routes.js +23 -11
  66. package/dist/server/handoff-routes.js.map +1 -1
  67. package/dist/server/impersonation.d.ts +6 -3
  68. package/dist/server/impersonation.d.ts.map +1 -1
  69. package/dist/server/impersonation.js +11 -5
  70. package/dist/server/impersonation.js.map +1 -1
  71. package/dist/server/index.d.ts +5 -2
  72. package/dist/server/index.d.ts.map +1 -1
  73. package/dist/server/index.js +2 -1
  74. package/dist/server/index.js.map +1 -1
  75. package/dist/server/invitations.d.ts +6 -2
  76. package/dist/server/invitations.d.ts.map +1 -1
  77. package/dist/server/invitations.js +6 -3
  78. package/dist/server/invitations.js.map +1 -1
  79. package/dist/server/local-cognito.d.ts +19 -0
  80. package/dist/server/local-cognito.d.ts.map +1 -0
  81. package/dist/server/local-cognito.js +19 -0
  82. package/dist/server/local-cognito.js.map +1 -0
  83. package/dist/server/refresh.d.ts +23 -12
  84. package/dist/server/refresh.d.ts.map +1 -1
  85. package/dist/server/refresh.js +35 -19
  86. package/dist/server/refresh.js.map +1 -1
  87. package/dist/server/resource-scope.d.ts +19 -0
  88. package/dist/server/resource-scope.d.ts.map +1 -0
  89. package/dist/server/resource-scope.js +2 -0
  90. package/dist/server/resource-scope.js.map +1 -0
  91. package/dist/server/route-rate-limit.d.ts +50 -0
  92. package/dist/server/route-rate-limit.d.ts.map +1 -0
  93. package/dist/server/route-rate-limit.js +39 -0
  94. package/dist/server/route-rate-limit.js.map +1 -0
  95. package/dist/server/session-routes.d.ts +9 -2
  96. package/dist/server/session-routes.d.ts.map +1 -1
  97. package/dist/server/session-routes.js +6 -4
  98. package/dist/server/session-routes.js.map +1 -1
  99. package/dist/server/sign-up.d.ts +32 -17
  100. package/dist/server/sign-up.d.ts.map +1 -1
  101. package/dist/server/sign-up.js +30 -12
  102. package/dist/server/sign-up.js.map +1 -1
  103. package/dist/server/store/postgres.d.ts.map +1 -1
  104. package/dist/server/store/postgres.js +43 -27
  105. package/dist/server/store/postgres.js.map +1 -1
  106. package/dist/server/verification.d.ts +76 -33
  107. package/dist/server/verification.d.ts.map +1 -1
  108. package/dist/server/verification.js +68 -67
  109. package/dist/server/verification.js.map +1 -1
  110. package/dist/server/verify.d.ts.map +1 -1
  111. package/dist/server/verify.js +8 -3
  112. package/dist/server/verify.js.map +1 -1
  113. package/dist/session/index.d.ts +11 -13
  114. package/dist/session/index.d.ts.map +1 -1
  115. package/dist/session/index.js +13 -14
  116. package/dist/session/index.js.map +1 -1
  117. package/package.json +6 -6
  118. package/src/migrations/vk_auth_006_verification_code_issuance.sql +29 -0
@@ -0,0 +1,54 @@
1
+ /**
2
+ * The OAuth transaction: everything the `start` request must hand to the
3
+ * `callback` request through the user's browser, and nothing more.
4
+ *
5
+ * - `state` — CSRF binding. Echoed by the IdP in the redirect; the
6
+ * callback compares it (constant time) with the cookie copy.
7
+ * - `codeVerifier` — PKCE (RFC 7636). Its S256 challenge goes on the
8
+ * authorize URL; the verifier itself is only ever presented to the
9
+ * IdP's token endpoint, so an authorization code intercepted on the
10
+ * way back (logs, referrers, a malicious redirect handler) cannot be
11
+ * redeemed by anyone else.
12
+ * - `nonce` — OIDC replay protection: the `id_token` must echo it.
13
+ *
14
+ * The whole transaction travels in ONE HttpOnly cookie. Its value is the
15
+ * bare `state` when the provider uses neither PKCE nor `nonce`
16
+ * (byte-identical to the historical state cookie, so apps that read it
17
+ * themselves keep working), else `state.verifier.nonce`.
18
+ */
19
+ import type { FederatedProvider } from './types.js';
20
+ export interface OAuthTransaction {
21
+ provider: FederatedProvider;
22
+ state: string;
23
+ /** PKCE verifier, for providers that support PKCE. */
24
+ codeVerifier?: string;
25
+ /** OIDC nonce, for providers whose `id_token` echoes it. */
26
+ nonce?: string;
27
+ }
28
+ /**
29
+ * Generate a 32-byte URL-safe random string used as the OAuth `state`.
30
+ * Prefer {@link createOAuthTransaction}, which also mints PKCE / nonce
31
+ * values for the providers that use them.
32
+ */
33
+ export declare function generateOAuthState(): string;
34
+ /** Mint the transaction for one sign-in attempt with `provider`. */
35
+ export declare function createOAuthTransaction(provider: FederatedProvider): OAuthTransaction;
36
+ /** RFC 7636 S256 challenge for a verifier. */
37
+ export declare function pkceChallenge(codeVerifier: string): string;
38
+ /** Cookie value for a transaction (see module docs for the format). */
39
+ export declare function serializeOAuthTransaction(transaction: OAuthTransaction): string;
40
+ /** Parse a cookie value back into a transaction, or `null` when malformed. */
41
+ export declare function parseOAuthTransaction(provider: FederatedProvider, cookieValue: string | null | undefined): OAuthTransaction | null;
42
+ /**
43
+ * Constant-time equality check between the `state` echoed back by the
44
+ * IdP and the value that was set on the state cookie at `start` time.
45
+ * Returns `false` for any mismatch including length differences.
46
+ */
47
+ export declare function verifyOAuthState(fromQuery: string | undefined, fromCookie: string | undefined): boolean;
48
+ /**
49
+ * The callback's check: parse the cookie, compare its `state` with the
50
+ * one the IdP echoed (constant time), and return the transaction — or
51
+ * `null` when anything is missing, malformed or mismatched.
52
+ */
53
+ export declare function verifyOAuthTransaction(provider: FederatedProvider, stateFromQuery: string | undefined, cookieValue: string | null | undefined): OAuthTransaction | null;
54
+ //# sourceMappingURL=oauth-transaction.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"oauth-transaction.d.ts","sourceRoot":"","sources":["../../../src/server/federated/oauth-transaction.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAIH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAEpD,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,EAAE,iBAAiB,CAAC;IAC5B,KAAK,EAAE,MAAM,CAAC;IACd,sDAAsD;IACtD,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,4DAA4D;IAC5D,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAID;;;;GAIG;AACH,wBAAgB,kBAAkB,IAAI,MAAM,CAE3C;AAED,oEAAoE;AACpE,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,iBAAiB,GAAG,gBAAgB,CASpF;AAED,8CAA8C;AAC9C,wBAAgB,aAAa,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAE1D;AAED,uEAAuE;AACvE,wBAAgB,yBAAyB,CAAC,WAAW,EAAE,gBAAgB,GAAG,MAAM,CAG/E;AAID,8EAA8E;AAC9E,wBAAgB,qBAAqB,CACnC,QAAQ,EAAE,iBAAiB,EAC3B,WAAW,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GACrC,gBAAgB,GAAG,IAAI,CAYzB;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAC9B,SAAS,EAAE,MAAM,GAAG,SAAS,EAC7B,UAAU,EAAE,MAAM,GAAG,SAAS,GAC7B,OAAO,CAMT;AAED;;;;GAIG;AACH,wBAAgB,sBAAsB,CACpC,QAAQ,EAAE,iBAAiB,EAC3B,cAAc,EAAE,MAAM,GAAG,SAAS,EAClC,WAAW,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GACrC,gBAAgB,GAAG,IAAI,CAIzB"}
@@ -0,0 +1,92 @@
1
+ /**
2
+ * The OAuth transaction: everything the `start` request must hand to the
3
+ * `callback` request through the user's browser, and nothing more.
4
+ *
5
+ * - `state` — CSRF binding. Echoed by the IdP in the redirect; the
6
+ * callback compares it (constant time) with the cookie copy.
7
+ * - `codeVerifier` — PKCE (RFC 7636). Its S256 challenge goes on the
8
+ * authorize URL; the verifier itself is only ever presented to the
9
+ * IdP's token endpoint, so an authorization code intercepted on the
10
+ * way back (logs, referrers, a malicious redirect handler) cannot be
11
+ * redeemed by anyone else.
12
+ * - `nonce` — OIDC replay protection: the `id_token` must echo it.
13
+ *
14
+ * The whole transaction travels in ONE HttpOnly cookie. Its value is the
15
+ * bare `state` when the provider uses neither PKCE nor `nonce`
16
+ * (byte-identical to the historical state cookie, so apps that read it
17
+ * themselves keep working), else `state.verifier.nonce`.
18
+ */
19
+ import { createHash, randomBytes, timingSafeEqual } from 'node:crypto';
20
+ import { providerDescriptor } from './providers.js';
21
+ const random = (bytes) => randomBytes(bytes).toString('base64url');
22
+ /**
23
+ * Generate a 32-byte URL-safe random string used as the OAuth `state`.
24
+ * Prefer {@link createOAuthTransaction}, which also mints PKCE / nonce
25
+ * values for the providers that use them.
26
+ */
27
+ export function generateOAuthState() {
28
+ return random(32);
29
+ }
30
+ /** Mint the transaction for one sign-in attempt with `provider`. */
31
+ export function createOAuthTransaction(provider) {
32
+ const descriptor = providerDescriptor(provider);
33
+ return {
34
+ provider,
35
+ state: generateOAuthState(),
36
+ // 32 random bytes → 43 base64url chars, inside RFC 7636's 43–128.
37
+ ...(descriptor.pkce ? { codeVerifier: random(32) } : {}),
38
+ ...(descriptor.nonce ? { nonce: random(16) } : {}),
39
+ };
40
+ }
41
+ /** RFC 7636 S256 challenge for a verifier. */
42
+ export function pkceChallenge(codeVerifier) {
43
+ return createHash('sha256').update(codeVerifier).digest('base64url');
44
+ }
45
+ /** Cookie value for a transaction (see module docs for the format). */
46
+ export function serializeOAuthTransaction(transaction) {
47
+ if (!transaction.codeVerifier && !transaction.nonce)
48
+ return transaction.state;
49
+ return [transaction.state, transaction.codeVerifier ?? '', transaction.nonce ?? ''].join('.');
50
+ }
51
+ const SEGMENT = /^[A-Za-z0-9_-]*$/;
52
+ /** Parse a cookie value back into a transaction, or `null` when malformed. */
53
+ export function parseOAuthTransaction(provider, cookieValue) {
54
+ if (!cookieValue)
55
+ return null;
56
+ const [state, codeVerifier, nonce, ...rest] = cookieValue.split('.');
57
+ if (!state || rest.length > 0 || ![state, codeVerifier, nonce].every((s) => s === undefined || SEGMENT.test(s))) {
58
+ return null;
59
+ }
60
+ return {
61
+ provider,
62
+ state,
63
+ ...(codeVerifier ? { codeVerifier } : {}),
64
+ ...(nonce ? { nonce } : {}),
65
+ };
66
+ }
67
+ /**
68
+ * Constant-time equality check between the `state` echoed back by the
69
+ * IdP and the value that was set on the state cookie at `start` time.
70
+ * Returns `false` for any mismatch including length differences.
71
+ */
72
+ export function verifyOAuthState(fromQuery, fromCookie) {
73
+ if (!fromQuery || !fromCookie)
74
+ return false;
75
+ const a = Buffer.from(fromQuery);
76
+ const b = Buffer.from(fromCookie);
77
+ if (a.length !== b.length)
78
+ return false;
79
+ return timingSafeEqual(a, b);
80
+ }
81
+ /**
82
+ * The callback's check: parse the cookie, compare its `state` with the
83
+ * one the IdP echoed (constant time), and return the transaction — or
84
+ * `null` when anything is missing, malformed or mismatched.
85
+ */
86
+ export function verifyOAuthTransaction(provider, stateFromQuery, cookieValue) {
87
+ const transaction = parseOAuthTransaction(provider, cookieValue);
88
+ if (!transaction || !verifyOAuthState(stateFromQuery, transaction.state))
89
+ return null;
90
+ return transaction;
91
+ }
92
+ //# sourceMappingURL=oauth-transaction.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,IAAI,CAAC,UAAU,CAAC,CAAC;IAClC,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,MAAM;QAAE,OAAO,KAAK,CAAC;IACxC,OAAO,eAAe,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AAC/B,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,sBAAsB,CACpC,QAA2B,EAC3B,cAAkC,EAClC,WAAsC;IAEtC,MAAM,WAAW,GAAG,qBAAqB,CAAC,QAAQ,EAAE,WAAW,CAAC,CAAC;IACjE,IAAI,CAAC,WAAW,IAAI,CAAC,gBAAgB,CAAC,cAAc,EAAE,WAAW,CAAC,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IACtF,OAAO,WAAW,CAAC;AACrB,CAAC"}
@@ -0,0 +1,34 @@
1
+ /**
2
+ * What VentureKit knows about each identity provider.
3
+ *
4
+ * One descriptor per provider: endpoints, default scopes, the protocol
5
+ * features it supports (PKCE, OIDC `nonce`), and the issuer its
6
+ * `id_token`s carry. Everything provider-specific the flow needs is here,
7
+ * so adding a provider is adding a descriptor plus a profile resolver.
8
+ *
9
+ * Capabilities are only switched on where the provider documents them:
10
+ * - Google advertises `code_challenge_methods_supported: ["plain","S256"]`
11
+ * and echoes `nonce` (https://accounts.google.com/.well-known/openid-configuration).
12
+ * - Facebook Login accepts `code_challenge` / `code_verifier` on its
13
+ * manual flow (the official SDKs always send them) but issues no
14
+ * `id_token` on that flow, so there is no `nonce` to check.
15
+ * - LinkedIn's discovery document advertises neither PKCE nor `nonce`
16
+ * (https://www.linkedin.com/oauth/.well-known/openid-configuration);
17
+ * sending them would risk a rejected flow, so they stay off.
18
+ */
19
+ import type { FederatedProvider } from './types.js';
20
+ export interface ProviderDescriptor {
21
+ authorizeEndpoint: string;
22
+ tokenEndpoint: string;
23
+ /** Default OAuth scopes when the caller doesn't supply any. */
24
+ defaultScopes: readonly string[];
25
+ /** Send an S256 PKCE challenge and redeem the code with its verifier. */
26
+ pkce: boolean;
27
+ /** Send an OIDC `nonce` and require the `id_token` to echo it. */
28
+ nonce: boolean;
29
+ /** Accepted `iss` values of the provider's `id_token` (empty: no id_token). */
30
+ issuers: readonly string[];
31
+ }
32
+ export declare const PROVIDERS: Readonly<Record<FederatedProvider, ProviderDescriptor>>;
33
+ export declare function providerDescriptor(provider: FederatedProvider): ProviderDescriptor;
34
+ //# sourceMappingURL=providers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"providers.d.ts","sourceRoot":"","sources":["../../../src/server/federated/providers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAEpD,MAAM,WAAW,kBAAkB;IACjC,iBAAiB,EAAE,MAAM,CAAC;IAC1B,aAAa,EAAE,MAAM,CAAC;IACtB,+DAA+D;IAC/D,aAAa,EAAE,SAAS,MAAM,EAAE,CAAC;IACjC,yEAAyE;IACzE,IAAI,EAAE,OAAO,CAAC;IACd,kEAAkE;IAClE,KAAK,EAAE,OAAO,CAAC;IACf,+EAA+E;IAC/E,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;CAC5B;AAED,eAAO,MAAM,SAAS,EAAE,QAAQ,CAAC,MAAM,CAAC,iBAAiB,EAAE,kBAAkB,CAAC,CA0C5E,CAAC;AAEH,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,iBAAiB,GAAG,kBAAkB,CAElF"}
@@ -0,0 +1,65 @@
1
+ /**
2
+ * What VentureKit knows about each identity provider.
3
+ *
4
+ * One descriptor per provider: endpoints, default scopes, the protocol
5
+ * features it supports (PKCE, OIDC `nonce`), and the issuer its
6
+ * `id_token`s carry. Everything provider-specific the flow needs is here,
7
+ * so adding a provider is adding a descriptor plus a profile resolver.
8
+ *
9
+ * Capabilities are only switched on where the provider documents them:
10
+ * - Google advertises `code_challenge_methods_supported: ["plain","S256"]`
11
+ * and echoes `nonce` (https://accounts.google.com/.well-known/openid-configuration).
12
+ * - Facebook Login accepts `code_challenge` / `code_verifier` on its
13
+ * manual flow (the official SDKs always send them) but issues no
14
+ * `id_token` on that flow, so there is no `nonce` to check.
15
+ * - LinkedIn's discovery document advertises neither PKCE nor `nonce`
16
+ * (https://www.linkedin.com/oauth/.well-known/openid-configuration);
17
+ * sending them would risk a rejected flow, so they stay off.
18
+ */
19
+ export const PROVIDERS = Object.freeze({
20
+ google: {
21
+ authorizeEndpoint: 'https://accounts.google.com/o/oauth2/v2/auth',
22
+ tokenEndpoint: 'https://oauth2.googleapis.com/token',
23
+ // `openid email profile` returns an `id_token` carrying the profile.
24
+ defaultScopes: ['openid', 'email', 'profile'],
25
+ pkce: true,
26
+ nonce: true,
27
+ // Google documents both spellings.
28
+ issuers: ['https://accounts.google.com', 'accounts.google.com'],
29
+ },
30
+ facebook: {
31
+ authorizeEndpoint: 'https://www.facebook.com/v18.0/dialog/oauth',
32
+ tokenEndpoint: 'https://graph.facebook.com/v18.0/oauth/access_token',
33
+ // `email` is required to read the address; `public_profile` is
34
+ // implicit but listing it makes the consent screen explicit.
35
+ defaultScopes: ['email', 'public_profile'],
36
+ pkce: true,
37
+ nonce: false,
38
+ issuers: [],
39
+ },
40
+ apple: {
41
+ authorizeEndpoint: 'https://appleid.apple.com/auth/authorize',
42
+ tokenEndpoint: 'https://appleid.apple.com/auth/token',
43
+ // Apple wants `name email`; `response_mode=form_post` is required
44
+ // when scopes include `name`/`email` — callers should set it.
45
+ defaultScopes: ['name', 'email'],
46
+ pkce: false,
47
+ nonce: false,
48
+ issuers: ['https://appleid.apple.com'],
49
+ },
50
+ linkedin: {
51
+ // LinkedIn implements OpenID Connect: `openid` scopes return an
52
+ // id_token at the token endpoint carrying `sub`, `email`,
53
+ // `email_verified` and `name`.
54
+ authorizeEndpoint: 'https://www.linkedin.com/oauth/v2/authorization',
55
+ tokenEndpoint: 'https://www.linkedin.com/oauth/v2/accessToken',
56
+ defaultScopes: ['openid', 'profile', 'email'],
57
+ pkce: false,
58
+ nonce: false,
59
+ issuers: ['https://www.linkedin.com/oauth'],
60
+ },
61
+ });
62
+ export function providerDescriptor(provider) {
63
+ return PROVIDERS[provider];
64
+ }
65
+ //# sourceMappingURL=providers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"providers.js","sourceRoot":"","sources":["../../../src/server/federated/providers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAiBH,MAAM,CAAC,MAAM,SAAS,GAA4D,MAAM,CAAC,MAAM,CAAC;IAC9F,MAAM,EAAE;QACN,iBAAiB,EAAE,8CAA8C;QACjE,aAAa,EAAE,qCAAqC;QACpD,qEAAqE;QACrE,aAAa,EAAE,CAAC,QAAQ,EAAE,OAAO,EAAE,SAAS,CAAC;QAC7C,IAAI,EAAE,IAAI;QACV,KAAK,EAAE,IAAI;QACX,mCAAmC;QACnC,OAAO,EAAE,CAAC,6BAA6B,EAAE,qBAAqB,CAAC;KAChE;IACD,QAAQ,EAAE;QACR,iBAAiB,EAAE,6CAA6C;QAChE,aAAa,EAAE,qDAAqD;QACpE,+DAA+D;QAC/D,6DAA6D;QAC7D,aAAa,EAAE,CAAC,OAAO,EAAE,gBAAgB,CAAC;QAC1C,IAAI,EAAE,IAAI;QACV,KAAK,EAAE,KAAK;QACZ,OAAO,EAAE,EAAE;KACZ;IACD,KAAK,EAAE;QACL,iBAAiB,EAAE,0CAA0C;QAC7D,aAAa,EAAE,sCAAsC;QACrD,kEAAkE;QAClE,8DAA8D;QAC9D,aAAa,EAAE,CAAC,MAAM,EAAE,OAAO,CAAC;QAChC,IAAI,EAAE,KAAK;QACX,KAAK,EAAE,KAAK;QACZ,OAAO,EAAE,CAAC,2BAA2B,CAAC;KACvC;IACD,QAAQ,EAAE;QACR,gEAAgE;QAChE,0DAA0D;QAC1D,+BAA+B;QAC/B,iBAAiB,EAAE,iDAAiD;QACpE,aAAa,EAAE,+CAA+C;QAC9D,aAAa,EAAE,CAAC,QAAQ,EAAE,SAAS,EAAE,OAAO,CAAC;QAC7C,IAAI,EAAE,KAAK;QACX,KAAK,EAAE,KAAK;QACZ,OAAO,EAAE,CAAC,gCAAgC,CAAC;KAC5C;CACF,CAAC,CAAC;AAEH,MAAM,UAAU,kBAAkB,CAAC,QAA2B;IAC5D,OAAO,SAAS,CAAC,QAAQ,CAAC,CAAC;AAC7B,CAAC"}
@@ -0,0 +1,81 @@
1
+ /**
2
+ * Step 3 of the federated flow — enter (or create) the Cognito account
3
+ * for a federated identity and mint its session.
4
+ *
5
+ * Loads the facts about any existing account, asks
6
+ * {@link decideFederatedSignIn} what to do, and applies the decision:
7
+ *
8
+ * - `create` — `AdminCreateUser` bound to the identity
9
+ * (`custom:<provider>Sub`), with `email_verified` as the provider
10
+ * asserted it.
11
+ * - `sign-in` — the account is this identity's (binding the subject when
12
+ * adopting a legacy account).
13
+ * - `link` — bind the identity, mark the (doubly proven) address
14
+ * verified, and sign every existing session out
15
+ * (`AdminUserGlobalSignOut`) before minting the new one.
16
+ * - `reject` — 409 with the decision's code; nothing is changed.
17
+ *
18
+ * Cognito has no admin API that mints a session without a password, so
19
+ * every sign-in sets a fresh random password and authenticates with it
20
+ * (`ADMIN_USER_PASSWORD_AUTH`). Nobody knows a federation-managed
21
+ * account's password, so rotating it costs nothing; on a link it replaces
22
+ * the user's own password — the result says so (`accountLinked`), and the
23
+ * app must tell the user.
24
+ */
25
+ import { type AuthServerConfig } from '../config.js';
26
+ import { type SignInResult } from '../tokens.js';
27
+ import { type ExistingPasswordAccountPolicy } from './account-linking.js';
28
+ import type { FederatedProfile, FederatedProvider } from './types.js';
29
+ export interface SignInAsFederatedUserInput {
30
+ /** Profile from `exchangeAuthorizationCode` (or the app's own IdP call). */
31
+ profile: FederatedProfile;
32
+ /** Provider name — recorded as `custom:federated_provider` / `custom:<provider>Sub`. */
33
+ provider: FederatedProvider;
34
+ /**
35
+ * Standard Cognito attributes to set on first creation only — e.g.
36
+ * `{ phone_number: '+212…' }`. Ignored for existing users.
37
+ */
38
+ initialAttributes?: Record<string, string>;
39
+ /**
40
+ * Custom attributes to set on first creation only — keyed without
41
+ * the `custom:` prefix (the helper prepends it). The provider binding
42
+ * (`<provider>Sub`, `federated_provider`) is always the helper's.
43
+ */
44
+ initialCustomAttributes?: Record<string, string>;
45
+ /** See {@link ExistingPasswordAccountPolicy}. Default `'link-verified'`. */
46
+ onExistingPasswordAccount?: ExistingPasswordAccountPolicy;
47
+ }
48
+ /** {@link SignInResult} plus what the sign-in did to the account. */
49
+ export interface FederatedSignInResult extends SignInResult {
50
+ /**
51
+ * `true` when this call linked the identity to an account it was not
52
+ * bound to: the account's password was replaced and its other sessions
53
+ * were signed out. Tell the user.
54
+ */
55
+ accountLinked: boolean;
56
+ /** `true` when the Cognito user was created by this call. */
57
+ created: boolean;
58
+ }
59
+ /**
60
+ * Sign a federated identity in. Creates the Cognito user on first contact,
61
+ * enforces the identity binding and the linking rules of
62
+ * {@link decideFederatedSignIn}, and mints session tokens.
63
+ *
64
+ * Throws `AuthError` 409 (`federated_identity_mismatch`,
65
+ * `federated_link_unverified`, `federated_account_exists`) when the
66
+ * identity may not enter the account its address names.
67
+ *
68
+ * Needs `cognito-idp:AdminGetUser`, `AdminCreateUser`,
69
+ * `AdminUpdateUserAttributes`, `AdminSetUserPassword`,
70
+ * `AdminUserGlobalSignOut` and `AdminInitiateAuth`, and the pool must
71
+ * declare `custom:<provider>Sub` — `federated: ['<provider>']` on the auth
72
+ * intent does both.
73
+ */
74
+ export declare function signInAsFederatedUser(input: SignInAsFederatedUserInput, config?: AuthServerConfig): Promise<FederatedSignInResult>;
75
+ /**
76
+ * Generate a 32-char password that satisfies the strongest password
77
+ * policy VentureKit ships (`passwordStrength: 'strong'` — 12+ chars,
78
+ * upper, lower, digit, symbol). Shared with the invitations flow.
79
+ */
80
+ export declare function generateStrongPassword(): string;
81
+ //# sourceMappingURL=sign-in.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sign-in.d.ts","sourceRoot":"","sources":["../../../src/server/federated/sign-in.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAeH,OAAO,EAAwB,KAAK,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAE3E,OAAO,EAAuB,KAAK,YAAY,EAAE,MAAM,cAAc,CAAC;AACtE,OAAO,EAIL,KAAK,6BAA6B,EAEnC,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAEtE,MAAM,WAAW,0BAA0B;IACzC,4EAA4E;IAC5E,OAAO,EAAE,gBAAgB,CAAC;IAC1B,wFAAwF;IACxF,QAAQ,EAAE,iBAAiB,CAAC;IAC5B;;;OAGG;IACH,iBAAiB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC3C;;;;OAIG;IACH,uBAAuB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjD,4EAA4E;IAC5E,yBAAyB,CAAC,EAAE,6BAA6B,CAAC;CAC3D;AAED,qEAAqE;AACrE,MAAM,WAAW,qBAAsB,SAAQ,YAAY;IACzD;;;;OAIG;IACH,aAAa,EAAE,OAAO,CAAC;IACvB,6DAA6D;IAC7D,OAAO,EAAE,OAAO,CAAC;CAClB;AA6FD;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,qBAAqB,CACzC,KAAK,EAAE,0BAA0B,EACjC,MAAM,GAAE,gBAAyC,GAChD,OAAO,CAAC,qBAAqB,CAAC,CA0DhC;AAED;;;;GAIG;AACH,wBAAgB,sBAAsB,IAAI,MAAM,CAM/C"}
@@ -0,0 +1,180 @@
1
+ /**
2
+ * Step 3 of the federated flow — enter (or create) the Cognito account
3
+ * for a federated identity and mint its session.
4
+ *
5
+ * Loads the facts about any existing account, asks
6
+ * {@link decideFederatedSignIn} what to do, and applies the decision:
7
+ *
8
+ * - `create` — `AdminCreateUser` bound to the identity
9
+ * (`custom:<provider>Sub`), with `email_verified` as the provider
10
+ * asserted it.
11
+ * - `sign-in` — the account is this identity's (binding the subject when
12
+ * adopting a legacy account).
13
+ * - `link` — bind the identity, mark the (doubly proven) address
14
+ * verified, and sign every existing session out
15
+ * (`AdminUserGlobalSignOut`) before minting the new one.
16
+ * - `reject` — 409 with the decision's code; nothing is changed.
17
+ *
18
+ * Cognito has no admin API that mints a session without a password, so
19
+ * every sign-in sets a fresh random password and authenticates with it
20
+ * (`ADMIN_USER_PASSWORD_AUTH`). Nobody knows a federation-managed
21
+ * account's password, so rotating it costs nothing; on a link it replaces
22
+ * the user's own password — the result says so (`accountLinked`), and the
23
+ * app must tell the user.
24
+ */
25
+ import { AdminCreateUserCommand, AdminGetUserCommand, AdminInitiateAuthCommand, AdminSetUserPasswordCommand, AdminUpdateUserAttributesCommand, AdminUserGlobalSignOutCommand, } from '@aws-sdk/client-cognito-identity-provider';
26
+ import { randomBytes } from 'node:crypto';
27
+ import { getCognitoClient } from '../cognito-client.js';
28
+ import { loadAuthServerConfig } from '../config.js';
29
+ import { AuthError, mapProviderError } from '../errors.js';
30
+ import { extractSignInTokens } from '../tokens.js';
31
+ import { decideFederatedSignIn, federatedSubjectAttribute, } from './account-linking.js';
32
+ /** `custom:federated_provider` — set on every account this module creates or links. */
33
+ const FEDERATED_PROVIDER_ATTRIBUTE = 'custom:federated_provider';
34
+ const attribute = (attrs, name) => attrs?.find((a) => a.Name === name)?.Value || null;
35
+ async function loadExistingAccount(client, config, email, provider) {
36
+ try {
37
+ const user = await client.send(new AdminGetUserCommand({ UserPoolId: config.userPoolId, Username: email }));
38
+ return {
39
+ emailVerified: attribute(user.UserAttributes, 'email_verified') === 'true',
40
+ federatedProvider: attribute(user.UserAttributes, FEDERATED_PROVIDER_ATTRIBUTE),
41
+ boundSubject: attribute(user.UserAttributes, federatedSubjectAttribute(provider)),
42
+ };
43
+ }
44
+ catch (err) {
45
+ if (err.name === 'UserNotFoundException')
46
+ return null;
47
+ throw mapProviderError(err, 'federated_signin_failed');
48
+ }
49
+ }
50
+ async function send(promise) {
51
+ try {
52
+ return await promise;
53
+ }
54
+ catch (err) {
55
+ throw mapProviderError(err, 'federated_signin_failed');
56
+ }
57
+ }
58
+ /** Create the account; `false` when a concurrent sign-in created it first. */
59
+ async function createAccount(client, config, email, input, temporaryPassword) {
60
+ const binding = {
61
+ [FEDERATED_PROVIDER_ATTRIBUTE]: input.provider,
62
+ [federatedSubjectAttribute(input.provider)]: input.profile.externalId,
63
+ };
64
+ const attrs = [
65
+ { Name: 'email', Value: email },
66
+ { Name: 'email_verified', Value: String(input.profile.emailVerified) },
67
+ ...(input.profile.name ? [{ Name: 'name', Value: input.profile.name }] : []),
68
+ ];
69
+ for (const [k, v] of Object.entries(input.initialAttributes ?? {})) {
70
+ if (k !== 'email' && k !== 'email_verified' && k !== 'name')
71
+ attrs.push({ Name: k, Value: v });
72
+ }
73
+ for (const [k, v] of Object.entries(input.initialCustomAttributes ?? {})) {
74
+ if (!(`custom:${k}` in binding))
75
+ attrs.push({ Name: `custom:${k}`, Value: v });
76
+ }
77
+ for (const [Name, Value] of Object.entries(binding))
78
+ attrs.push({ Name, Value });
79
+ try {
80
+ await client.send(new AdminCreateUserCommand({
81
+ UserPoolId: config.userPoolId,
82
+ Username: email,
83
+ UserAttributes: attrs,
84
+ // The user just authenticated through the IdP — no Cognito welcome mail.
85
+ MessageAction: 'SUPPRESS',
86
+ TemporaryPassword: temporaryPassword,
87
+ }));
88
+ return true;
89
+ }
90
+ catch (err) {
91
+ if (err.name === 'UsernameExistsException')
92
+ return false;
93
+ throw mapProviderError(err, 'federated_signin_failed');
94
+ }
95
+ }
96
+ /** Attribute writes a `sign-in` / `link` decision implies (empty: none). */
97
+ function bindingUpdates(decision, existing, input) {
98
+ const updates = [];
99
+ const subject = { Name: federatedSubjectAttribute(input.provider), Value: input.profile.externalId };
100
+ if (decision.kind === 'sign-in' && decision.bindSubject)
101
+ updates.push(subject);
102
+ if (decision.kind === 'link') {
103
+ updates.push(subject, { Name: 'email_verified', Value: 'true' });
104
+ if (!existing.federatedProvider)
105
+ updates.push({ Name: FEDERATED_PROVIDER_ATTRIBUTE, Value: input.provider });
106
+ }
107
+ return updates;
108
+ }
109
+ /**
110
+ * Sign a federated identity in. Creates the Cognito user on first contact,
111
+ * enforces the identity binding and the linking rules of
112
+ * {@link decideFederatedSignIn}, and mints session tokens.
113
+ *
114
+ * Throws `AuthError` 409 (`federated_identity_mismatch`,
115
+ * `federated_link_unverified`, `federated_account_exists`) when the
116
+ * identity may not enter the account its address names.
117
+ *
118
+ * Needs `cognito-idp:AdminGetUser`, `AdminCreateUser`,
119
+ * `AdminUpdateUserAttributes`, `AdminSetUserPassword`,
120
+ * `AdminUserGlobalSignOut` and `AdminInitiateAuth`, and the pool must
121
+ * declare `custom:<provider>Sub` — `federated: ['<provider>']` on the auth
122
+ * intent does both.
123
+ */
124
+ export async function signInAsFederatedUser(input, config = loadAuthServerConfig()) {
125
+ const client = getCognitoClient(config.region, config.endpoint);
126
+ const email = input.profile.email.toLowerCase();
127
+ const password = generateStrongPassword();
128
+ let existing = await loadExistingAccount(client, config, email, input.provider);
129
+ let decision = decideFederatedSignIn({ existing, provider: input.provider, profile: input.profile, policy: input.onExistingPasswordAccount });
130
+ if (decision.kind === 'create' && !(await createAccount(client, config, email, input, password))) {
131
+ // A concurrent sign-in created the account between our read and our
132
+ // create: decide again over what it created (normally: this same
133
+ // identity, bound — a plain sign-in).
134
+ existing = await loadExistingAccount(client, config, email, input.provider);
135
+ decision = decideFederatedSignIn({ existing, provider: input.provider, profile: input.profile, policy: input.onExistingPasswordAccount });
136
+ }
137
+ if (decision.kind === 'reject')
138
+ throw new AuthError(decision.code, decision.message, 409);
139
+ if (existing && decision.kind !== 'create') {
140
+ const updates = bindingUpdates(decision, existing, input);
141
+ if (updates.length > 0) {
142
+ await send(client.send(new AdminUpdateUserAttributesCommand({ UserPoolId: config.userPoolId, Username: email, UserAttributes: updates })));
143
+ }
144
+ }
145
+ // `Permanent: true` also lifts a new account out of FORCE_CHANGE_PASSWORD.
146
+ await send(client.send(new AdminSetUserPasswordCommand({ UserPoolId: config.userPoolId, Username: email, Password: password, Permanent: true })));
147
+ // A link hands the account to a newly bound identity: end every session
148
+ // that held it before (including any planted by whoever registered the
149
+ // address first). Tokens minted below are issued after, so they survive.
150
+ if (decision.kind === 'link') {
151
+ await send(client.send(new AdminUserGlobalSignOutCommand({ UserPoolId: config.userPoolId, Username: email })));
152
+ }
153
+ const res = await send(client.send(new AdminInitiateAuthCommand({
154
+ UserPoolId: config.userPoolId,
155
+ ClientId: config.appClientId,
156
+ AuthFlow: 'ADMIN_USER_PASSWORD_AUTH',
157
+ AuthParameters: { USERNAME: email, PASSWORD: password },
158
+ })));
159
+ if (res.ChallengeName) {
160
+ throw new AuthError('federated_signin_failed', `Cognito returned an unexpected challenge after federated sign-in: ${res.ChallengeName}`, 500);
161
+ }
162
+ return {
163
+ ...extractSignInTokens(res.AuthenticationResult),
164
+ accountLinked: decision.kind === 'link',
165
+ created: decision.kind === 'create',
166
+ };
167
+ }
168
+ /**
169
+ * Generate a 32-char password that satisfies the strongest password
170
+ * policy VentureKit ships (`passwordStrength: 'strong'` — 12+ chars,
171
+ * upper, lower, digit, symbol). Shared with the invitations flow.
172
+ */
173
+ export function generateStrongPassword() {
174
+ const base = randomBytes(24)
175
+ .toString('base64')
176
+ .replace(/[^A-Za-z0-9]/g, '')
177
+ .slice(0, 28);
178
+ return `Aa1!${base}`;
179
+ }
180
+ //# sourceMappingURL=sign-in.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sign-in.js","sourceRoot":"","sources":["../../../src/server/federated/sign-in.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,EACL,sBAAsB,EACtB,mBAAmB,EACnB,wBAAwB,EACxB,2BAA2B,EAC3B,gCAAgC,EAChC,6BAA6B,GAI9B,MAAM,2CAA2C,CAAC;AACnD,OAAO,EAAE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C;QAC7B,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,6BAA6B,CAAC,EAAE,UAAU,EAAE,MAAM,CAAC,UAAU,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC;IACjH,CAAC;IAED,MAAM,GAAG,GAAmC,MAAM,IAAI,CACpD,MAAM,CAAC,IAAI,CACT,IAAI,wBAAwB,CAAC;QAC3B,UAAU,EAAE,MAAM,CAAC,UAAU;QAC7B,QAAQ,EAAE,MAAM,CAAC,WAAW;QAC5B,QAAQ,EAAE,0BAA0B;QACpC,cAAc,EAAE,EAAE,QAAQ,EAAE,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE;KACxD,CAAC,CACH,CACF,CAAC;IACF,IAAI,GAAG,CAAC,aAAa,EAAE,CAAC;QACtB,MAAM,IAAI,SAAS,CACjB,yBAAyB,EACzB,qEAAqE,GAAG,CAAC,aAAa,EAAE,EACxF,GAAG,CACJ,CAAC;IACJ,CAAC;IACD,OAAO;QACL,GAAG,mBAAmB,CAAC,GAAG,CAAC,oBAAoB,CAAC;QAChD,aAAa,EAAE,QAAQ,CAAC,IAAI,KAAK,MAAM;QACvC,OAAO,EAAE,QAAQ,CAAC,IAAI,KAAK,QAAQ;KACpC,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,sBAAsB;IACpC,MAAM,IAAI,GAAG,WAAW,CAAC,EAAE,CAAC;SACzB,QAAQ,CAAC,QAAQ,CAAC;SAClB,OAAO,CAAC,eAAe,EAAE,EAAE,CAAC;SAC5B,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IAChB,OAAO,OAAO,IAAI,EAAE,CAAC;AACvB,CAAC"}
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Shared types of the federated sign-in module.
3
+ */
4
+ export type FederatedProvider = 'google' | 'facebook' | 'apple' | 'linkedin';
5
+ /**
6
+ * Federated profile — the shape every IdP normalizes to after
7
+ * `exchangeAuthorizationCode` runs (or that an app builds itself from an
8
+ * IdP it calls directly).
9
+ */
10
+ export interface FederatedProfile {
11
+ /**
12
+ * Stable identifier of the user AT THE IdP (Google / LinkedIn `sub`,
13
+ * Facebook `id`). Bound to the Cognito account as `custom:<provider>Sub`
14
+ * on first sign-in, and required to match on every later one.
15
+ */
16
+ externalId: string;
17
+ /** E-mail address. Required — Cognito uses it as the username. */
18
+ email: string;
19
+ /**
20
+ * Whether the IdP asserts the user controls `email` (OIDC
21
+ * `email_verified`). Decides whether the account may be linked to an
22
+ * existing one and whether a new account is created with
23
+ * `email_verified=true`. Report what the IdP says — never `true` by
24
+ * default: Facebook, for one, gives no such guarantee.
25
+ */
26
+ emailVerified: boolean;
27
+ /** Optional display name, passed through to Cognito's `name` attr. */
28
+ name?: string;
29
+ }
30
+ export interface FederatedProviderCredentials {
31
+ clientId: string;
32
+ clientSecret: string;
33
+ }
34
+ /** Env bag the helpers read (defaults to `process.env`). */
35
+ export type FederatedEnv = NodeJS.ProcessEnv | Record<string, string | undefined>;
36
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/server/federated/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,MAAM,iBAAiB,GAAG,QAAQ,GAAG,UAAU,GAAG,OAAO,GAAG,UAAU,CAAC;AAE7E;;;;GAIG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;;;OAIG;IACH,UAAU,EAAE,MAAM,CAAC;IACnB,kEAAkE;IAClE,KAAK,EAAE,MAAM,CAAC;IACd;;;;;;OAMG;IACH,aAAa,EAAE,OAAO,CAAC;IACvB,sEAAsE;IACtE,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,4BAA4B;IAC3C,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,4DAA4D;AAC5D,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC"}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Shared types of the federated sign-in module.
3
+ */
4
+ export {};
5
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/server/federated/types.ts"],"names":[],"mappings":"AAAA;;GAEG"}