@aws-amplify/auth 6.16.0 → 6.16.1-unstable.5bf5685.0
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/dist/cjs/providers/cognito/apis/signInWithRedirect.js +14 -3
- package/dist/cjs/providers/cognito/apis/signInWithRedirect.js.map +1 -1
- package/dist/cjs/providers/cognito/tokenProvider/CognitoUserPoolsTokenProvider.js +5 -2
- package/dist/cjs/providers/cognito/tokenProvider/CognitoUserPoolsTokenProvider.js.map +1 -1
- package/dist/cjs/providers/cognito/tokenProvider/TokenOrchestrator.js +6 -1
- package/dist/cjs/providers/cognito/tokenProvider/TokenOrchestrator.js.map +1 -1
- package/dist/cjs/providers/cognito/utils/refreshAuthTokens.js +2 -1
- package/dist/cjs/providers/cognito/utils/refreshAuthTokens.js.map +1 -1
- package/dist/esm/providers/cognito/apis/signInWithRedirect.mjs +14 -3
- package/dist/esm/providers/cognito/apis/signInWithRedirect.mjs.map +1 -1
- package/dist/esm/providers/cognito/tokenProvider/CognitoUserPoolsTokenProvider.d.ts +3 -2
- package/dist/esm/providers/cognito/tokenProvider/CognitoUserPoolsTokenProvider.mjs +5 -2
- package/dist/esm/providers/cognito/tokenProvider/CognitoUserPoolsTokenProvider.mjs.map +1 -1
- package/dist/esm/providers/cognito/tokenProvider/TokenOrchestrator.d.ts +3 -1
- package/dist/esm/providers/cognito/tokenProvider/TokenOrchestrator.mjs +6 -1
- package/dist/esm/providers/cognito/tokenProvider/TokenOrchestrator.mjs.map +1 -1
- package/dist/esm/providers/cognito/tokenProvider/types.d.ts +5 -3
- package/dist/esm/providers/cognito/types/models.d.ts +1 -2
- package/dist/esm/providers/cognito/utils/refreshAuthTokens.d.ts +2 -0
- package/dist/esm/providers/cognito/utils/refreshAuthTokens.mjs +2 -1
- package/dist/esm/providers/cognito/utils/refreshAuthTokens.mjs.map +1 -1
- package/dist/esm/types/inputs.d.ts +4 -0
- package/package.json +111 -111
- package/src/providers/cognito/apis/signInWithRedirect.ts +15 -2
- package/src/providers/cognito/tokenProvider/CognitoUserPoolsTokenProvider.ts +9 -4
- package/src/providers/cognito/tokenProvider/TokenOrchestrator.ts +14 -1
- package/src/providers/cognito/tokenProvider/types.ts +7 -1
- package/src/providers/cognito/types/models.ts +1 -1
- package/src/providers/cognito/utils/refreshAuthTokens.ts +4 -0
- package/src/types/inputs.ts +4 -1
|
@@ -30,16 +30,21 @@ async function signInWithRedirect(input) {
|
|
|
30
30
|
await (0, signInHelpers_1.assertUserNotAuthenticated)();
|
|
31
31
|
}
|
|
32
32
|
let provider = 'COGNITO'; // Default
|
|
33
|
+
let idpIdentifier;
|
|
33
34
|
if (typeof input?.provider === 'string') {
|
|
34
35
|
provider = models_1.cognitoHostedUIIdentityProviderMap[input.provider];
|
|
35
36
|
}
|
|
36
37
|
else if (input?.provider?.custom) {
|
|
37
38
|
provider = input.provider.custom;
|
|
38
39
|
}
|
|
40
|
+
else if (input?.provider?.idpIdentifier) {
|
|
41
|
+
({ idpIdentifier } = input.provider);
|
|
42
|
+
}
|
|
39
43
|
return oauthSignIn({
|
|
40
44
|
oauthConfig: authConfig.loginWith.oauth,
|
|
41
45
|
clientId: authConfig.userPoolClientId,
|
|
42
46
|
provider,
|
|
47
|
+
idpIdentifier,
|
|
43
48
|
customState: input?.customState,
|
|
44
49
|
preferPrivateSession: input?.options?.preferPrivateSession,
|
|
45
50
|
options: {
|
|
@@ -51,7 +56,7 @@ async function signInWithRedirect(input) {
|
|
|
51
56
|
authSessionOpener: input?.options?.authSessionOpener,
|
|
52
57
|
});
|
|
53
58
|
}
|
|
54
|
-
const oauthSignIn = async ({ oauthConfig, provider, clientId, customState, preferPrivateSession, options, authSessionOpener, }) => {
|
|
59
|
+
const oauthSignIn = async ({ oauthConfig, provider, idpIdentifier, clientId, customState, preferPrivateSession, options, authSessionOpener, }) => {
|
|
55
60
|
const { domain, redirectSignIn, responseType, scopes } = oauthConfig;
|
|
56
61
|
const { loginHint, lang, nonce, prompt } = options ?? {};
|
|
57
62
|
const randomState = (0, oauth_1.generateState)();
|
|
@@ -75,9 +80,15 @@ const oauthSignIn = async ({ oauthConfig, provider, clientId, customState, prefe
|
|
|
75
80
|
['redirect_uri', redirectUri],
|
|
76
81
|
['response_type', responseType],
|
|
77
82
|
['client_id', clientId],
|
|
78
|
-
['identity_provider', provider],
|
|
79
|
-
['scope', scopes.join(' ')],
|
|
80
83
|
]);
|
|
84
|
+
// Add either identity_provider or idp_identifier, but not both
|
|
85
|
+
if (idpIdentifier) {
|
|
86
|
+
params.append('idp_identifier', idpIdentifier);
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
params.append('identity_provider', provider);
|
|
90
|
+
}
|
|
91
|
+
params.append('scope', scopes.join(' '));
|
|
81
92
|
loginHint && params.append('login_hint', loginHint);
|
|
82
93
|
lang && params.append('lang', lang);
|
|
83
94
|
nonce && params.append('nonce', nonce);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signInWithRedirect.js","sources":["../../../../../src/providers/cognito/apis/signInWithRedirect.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.signInWithRedirect = signInWithRedirect;\nconst core_1 = require(\"@aws-amplify/core\");\nconst utils_1 = require(\"@aws-amplify/core/internals/utils\");\nrequire(\"../utils/oauth/enableOAuthListener\");\nconst models_1 = require(\"../types/models\");\nconst utils_2 = require(\"../../../utils\");\nconst signInHelpers_1 = require(\"../utils/signInHelpers\");\nconst oauth_1 = require(\"../utils/oauth\");\nconst createOAuthError_1 = require(\"../utils/oauth/createOAuthError\");\nconst cancelOAuthFlow_1 = require(\"../utils/oauth/cancelOAuthFlow\");\n/**\n * Signs in a user with OAuth. Redirects the application to an Identity Provider.\n *\n * @param input - The SignInWithRedirectInput object, if empty it will redirect to Cognito HostedUI\n *\n * @throws AuthTokenConfigException - Thrown when the user pool config is invalid.\n * @throws OAuthNotConfigureException - Thrown when the oauth config is invalid.\n */\nasync function signInWithRedirect(input) {\n const authConfig = core_1.Amplify.getConfig().Auth?.Cognito;\n (0, utils_1.assertTokenProviderConfig)(authConfig);\n (0, utils_1.assertOAuthConfig)(authConfig);\n oauth_1.oAuthStore.setAuthConfig(authConfig);\n if (!input?.options?.prompt) {\n await (0, signInHelpers_1.assertUserNotAuthenticated)();\n }\n let provider = 'COGNITO'; // Default\n if (typeof input?.provider === 'string') {\n provider = models_1.cognitoHostedUIIdentityProviderMap[input.provider];\n }\n else if (input?.provider?.custom) {\n provider = input.provider.custom;\n }\n return oauthSignIn({\n oauthConfig: authConfig.loginWith.oauth,\n clientId: authConfig.userPoolClientId,\n provider,\n customState: input?.customState,\n preferPrivateSession: input?.options?.preferPrivateSession,\n options: {\n loginHint: input?.options?.loginHint,\n lang: input?.options?.lang,\n nonce: input?.options?.nonce,\n prompt: input?.options?.prompt,\n },\n authSessionOpener: input?.options?.authSessionOpener,\n });\n}\nconst oauthSignIn = async ({ oauthConfig, provider, clientId, customState, preferPrivateSession, options, authSessionOpener, }) => {\n const { domain, redirectSignIn, responseType, scopes } = oauthConfig;\n const { loginHint, lang, nonce, prompt } = options ?? {};\n const randomState = (0, oauth_1.generateState)();\n const openAuthSession = authSessionOpener || utils_2.openAuthSession;\n /* encodeURIComponent is not URL safe, use urlSafeEncode instead. Cognito\n single-encodes/decodes url on first sign in and double-encodes/decodes url\n when user already signed in. Using encodeURIComponent, Base32, Base64 add\n characters % or = which on further encoding becomes unsafe. '=' create issue\n for parsing query params.\n Refer: https://github.com/aws-amplify/amplify-js/issues/5218 */\n const state = customState\n ? `${randomState}-${(0, utils_1.urlSafeEncode)(customState)}`\n : randomState;\n const { value, method, toCodeChallenge } = (0, oauth_1.generateCodeVerifier)(128);\n const redirectUri = (0, oauth_1.getRedirectUrl)(oauthConfig.redirectSignIn);\n if ((0, utils_1.isBrowser)())\n oauth_1.oAuthStore.storeOAuthInFlight(true);\n oauth_1.oAuthStore.storeOAuthState(state);\n oauth_1.oAuthStore.storePKCE(value);\n const params = new URLSearchParams([\n ['redirect_uri', redirectUri],\n ['response_type', responseType],\n ['client_id', clientId],\n ['identity_provider', provider],\n ['scope', scopes.join(' ')],\n ]);\n loginHint && params.append('login_hint', loginHint);\n lang && params.append('lang', lang);\n nonce && params.append('nonce', nonce);\n prompt && params.append('prompt', prompt.toLowerCase());\n params.append('state', state);\n if (responseType === 'code') {\n params.append('code_challenge', toCodeChallenge());\n params.append('code_challenge_method', method);\n }\n // Using URL object is not supported in React Native as the `search` property is read-only\n // See: https://github.com/facebook/react-native/blob/main/packages/react-native/Libraries/Blob/URL.js\n const oAuthUrl = `https://${domain}/oauth2/authorize?${params.toString()}`;\n // this will only take effect in the following scenarios:\n // 1. the user cancels the OAuth flow on web via back button, and\n // 2. when bfcache is enabled\n (0, cancelOAuthFlow_1.listenForOAuthFlowCancellation)(oauth_1.oAuthStore);\n // the following is effective only in react-native as openAuthSession resolves only in react-native\n const { type, error, url } = (await openAuthSession(oAuthUrl, redirectSignIn, preferPrivateSession)) ??\n {};\n try {\n if (type === 'error') {\n throw (0, createOAuthError_1.createOAuthError)(String(error));\n }\n if (type === 'canceled') {\n throw (0, createOAuthError_1.createOAuthError)(String(type));\n }\n if (type === 'success' && url) {\n await (0, oauth_1.completeOAuthFlow)({\n currentUrl: url,\n clientId,\n domain,\n redirectUri,\n responseType,\n userAgentValue: (0, utils_2.getAuthUserAgentValue)(utils_1.AuthAction.SignInWithRedirect),\n preferPrivateSession,\n });\n }\n }\n catch (err) {\n await (0, oauth_1.handleFailure)(err);\n // rethrow the error so it can be caught by `await signInWithRedirect()` in react-native\n throw err;\n }\n};\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AAC7D,OAAO,CAAC,kBAAkB,GAAG,kBAAkB;AA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AAG,CAAC;AAC7C;AACA,QAAQ,MAAM,GAAG;AACjB,IAAI;AACJ,CAAC;;"}
|
|
1
|
+
{"version":3,"file":"signInWithRedirect.js","sources":["../../../../../src/providers/cognito/apis/signInWithRedirect.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.signInWithRedirect = signInWithRedirect;\nconst core_1 = require(\"@aws-amplify/core\");\nconst utils_1 = require(\"@aws-amplify/core/internals/utils\");\nrequire(\"../utils/oauth/enableOAuthListener\");\nconst models_1 = require(\"../types/models\");\nconst utils_2 = require(\"../../../utils\");\nconst signInHelpers_1 = require(\"../utils/signInHelpers\");\nconst oauth_1 = require(\"../utils/oauth\");\nconst createOAuthError_1 = require(\"../utils/oauth/createOAuthError\");\nconst cancelOAuthFlow_1 = require(\"../utils/oauth/cancelOAuthFlow\");\n/**\n * Signs in a user with OAuth. Redirects the application to an Identity Provider.\n *\n * @param input - The SignInWithRedirectInput object, if empty it will redirect to Cognito HostedUI\n *\n * @throws AuthTokenConfigException - Thrown when the user pool config is invalid.\n * @throws OAuthNotConfigureException - Thrown when the oauth config is invalid.\n */\nasync function signInWithRedirect(input) {\n const authConfig = core_1.Amplify.getConfig().Auth?.Cognito;\n (0, utils_1.assertTokenProviderConfig)(authConfig);\n (0, utils_1.assertOAuthConfig)(authConfig);\n oauth_1.oAuthStore.setAuthConfig(authConfig);\n if (!input?.options?.prompt) {\n await (0, signInHelpers_1.assertUserNotAuthenticated)();\n }\n let provider = 'COGNITO'; // Default\n let idpIdentifier;\n if (typeof input?.provider === 'string') {\n provider = models_1.cognitoHostedUIIdentityProviderMap[input.provider];\n }\n else if (input?.provider?.custom) {\n provider = input.provider.custom;\n }\n else if (input?.provider?.idpIdentifier) {\n ({ idpIdentifier } = input.provider);\n }\n return oauthSignIn({\n oauthConfig: authConfig.loginWith.oauth,\n clientId: authConfig.userPoolClientId,\n provider,\n idpIdentifier,\n customState: input?.customState,\n preferPrivateSession: input?.options?.preferPrivateSession,\n options: {\n loginHint: input?.options?.loginHint,\n lang: input?.options?.lang,\n nonce: input?.options?.nonce,\n prompt: input?.options?.prompt,\n },\n authSessionOpener: input?.options?.authSessionOpener,\n });\n}\nconst oauthSignIn = async ({ oauthConfig, provider, idpIdentifier, clientId, customState, preferPrivateSession, options, authSessionOpener, }) => {\n const { domain, redirectSignIn, responseType, scopes } = oauthConfig;\n const { loginHint, lang, nonce, prompt } = options ?? {};\n const randomState = (0, oauth_1.generateState)();\n const openAuthSession = authSessionOpener || utils_2.openAuthSession;\n /* encodeURIComponent is not URL safe, use urlSafeEncode instead. Cognito\n single-encodes/decodes url on first sign in and double-encodes/decodes url\n when user already signed in. Using encodeURIComponent, Base32, Base64 add\n characters % or = which on further encoding becomes unsafe. '=' create issue\n for parsing query params.\n Refer: https://github.com/aws-amplify/amplify-js/issues/5218 */\n const state = customState\n ? `${randomState}-${(0, utils_1.urlSafeEncode)(customState)}`\n : randomState;\n const { value, method, toCodeChallenge } = (0, oauth_1.generateCodeVerifier)(128);\n const redirectUri = (0, oauth_1.getRedirectUrl)(oauthConfig.redirectSignIn);\n if ((0, utils_1.isBrowser)())\n oauth_1.oAuthStore.storeOAuthInFlight(true);\n oauth_1.oAuthStore.storeOAuthState(state);\n oauth_1.oAuthStore.storePKCE(value);\n const params = new URLSearchParams([\n ['redirect_uri', redirectUri],\n ['response_type', responseType],\n ['client_id', clientId],\n ]);\n // Add either identity_provider or idp_identifier, but not both\n if (idpIdentifier) {\n params.append('idp_identifier', idpIdentifier);\n }\n else {\n params.append('identity_provider', provider);\n }\n params.append('scope', scopes.join(' '));\n loginHint && params.append('login_hint', loginHint);\n lang && params.append('lang', lang);\n nonce && params.append('nonce', nonce);\n prompt && params.append('prompt', prompt.toLowerCase());\n params.append('state', state);\n if (responseType === 'code') {\n params.append('code_challenge', toCodeChallenge());\n params.append('code_challenge_method', method);\n }\n // Using URL object is not supported in React Native as the `search` property is read-only\n // See: https://github.com/facebook/react-native/blob/main/packages/react-native/Libraries/Blob/URL.js\n const oAuthUrl = `https://${domain}/oauth2/authorize?${params.toString()}`;\n // this will only take effect in the following scenarios:\n // 1. the user cancels the OAuth flow on web via back button, and\n // 2. when bfcache is enabled\n (0, cancelOAuthFlow_1.listenForOAuthFlowCancellation)(oauth_1.oAuthStore);\n // the following is effective only in react-native as openAuthSession resolves only in react-native\n const { type, error, url } = (await openAuthSession(oAuthUrl, redirectSignIn, preferPrivateSession)) ??\n {};\n try {\n if (type === 'error') {\n throw (0, createOAuthError_1.createOAuthError)(String(error));\n }\n if (type === 'canceled') {\n throw (0, createOAuthError_1.createOAuthError)(String(type));\n }\n if (type === 'success' && url) {\n await (0, oauth_1.completeOAuthFlow)({\n currentUrl: url,\n clientId,\n domain,\n redirectUri,\n responseType,\n userAgentValue: (0, utils_2.getAuthUserAgentValue)(utils_1.AuthAction.SignInWithRedirect),\n preferPrivateSession,\n });\n }\n }\n catch (err) {\n await (0, oauth_1.handleFailure)(err);\n // rethrow the error so it can be caught by `await signInWithRedirect()` in react-native\n throw err;\n }\n};\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AAC7D,OAAO,CAAC,kBAAkB,GAAG,kBAAkB;AAC/C,MAAM,MAAM,GAAG,OAAO,CAAC,mBAAmB,CAAC;AAC3C,MAAM,OAAO,GAAG,OAAO,CAAC,mCAAmC,CAAC;AAC5D,OAAO,CAAC,oCAAoC,CAAC;AAC7C,MAAM,QAAQ,GAAG,OAAO,CAAC,iBAAiB,CAAC;AAC3C,MAAM,OAAO,GAAG,OAAO,CAAC,gBAAgB,CAAC;AACzC,MAAM,eAAe,GAAG,OAAO,CAAC,wBAAwB,CAAC;AACzD,MAAM,OAAO,GAAG,OAAO,CAAC,gBAAgB,CAAC;AACzC,MAA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,EAAE,GAAG,CAAC;AAC7C;AACA,QAAQ,MAAM,GAAG;AACjB,IAAI;AACJ,CAAC;;"}
|
|
@@ -16,12 +16,15 @@ class CognitoUserPoolsTokenProvider {
|
|
|
16
16
|
this.tokenOrchestrator.setAuthTokenStore(this.authTokenStore);
|
|
17
17
|
this.tokenOrchestrator.setTokenRefresher(refreshAuthTokens_1.refreshAuthTokens);
|
|
18
18
|
}
|
|
19
|
-
getTokens(
|
|
20
|
-
return this.tokenOrchestrator.getTokens(
|
|
19
|
+
getTokens(options = {}) {
|
|
20
|
+
return this.tokenOrchestrator.getTokens(options);
|
|
21
21
|
}
|
|
22
22
|
setKeyValueStorage(keyValueStorage) {
|
|
23
23
|
this.authTokenStore.setKeyValueStorage(keyValueStorage);
|
|
24
24
|
}
|
|
25
|
+
setClientMetadataProvider(clientMetadataProvider) {
|
|
26
|
+
this.tokenOrchestrator.setClientMetadataProvider(clientMetadataProvider);
|
|
27
|
+
}
|
|
25
28
|
setAuthConfig(authConfig) {
|
|
26
29
|
this.authTokenStore.setAuthConfig(authConfig);
|
|
27
30
|
this.tokenOrchestrator.setAuthConfig(authConfig);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CognitoUserPoolsTokenProvider.js","sources":["../../../../../src/providers/cognito/tokenProvider/CognitoUserPoolsTokenProvider.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.CognitoUserPoolsTokenProvider = void 0;\nconst core_1 = require(\"@aws-amplify/core\");\nconst refreshAuthTokens_1 = require(\"../utils/refreshAuthTokens\");\nconst TokenStore_1 = require(\"./TokenStore\");\nconst TokenOrchestrator_1 = require(\"./TokenOrchestrator\");\nclass CognitoUserPoolsTokenProvider {\n constructor() {\n this.authTokenStore = new TokenStore_1.DefaultTokenStore();\n this.authTokenStore.setKeyValueStorage(core_1.defaultStorage);\n this.tokenOrchestrator = new TokenOrchestrator_1.TokenOrchestrator();\n this.tokenOrchestrator.setAuthTokenStore(this.authTokenStore);\n this.tokenOrchestrator.setTokenRefresher(refreshAuthTokens_1.refreshAuthTokens);\n }\n getTokens(
|
|
1
|
+
{"version":3,"file":"CognitoUserPoolsTokenProvider.js","sources":["../../../../../src/providers/cognito/tokenProvider/CognitoUserPoolsTokenProvider.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.CognitoUserPoolsTokenProvider = void 0;\nconst core_1 = require(\"@aws-amplify/core\");\nconst refreshAuthTokens_1 = require(\"../utils/refreshAuthTokens\");\nconst TokenStore_1 = require(\"./TokenStore\");\nconst TokenOrchestrator_1 = require(\"./TokenOrchestrator\");\nclass CognitoUserPoolsTokenProvider {\n constructor() {\n this.authTokenStore = new TokenStore_1.DefaultTokenStore();\n this.authTokenStore.setKeyValueStorage(core_1.defaultStorage);\n this.tokenOrchestrator = new TokenOrchestrator_1.TokenOrchestrator();\n this.tokenOrchestrator.setAuthTokenStore(this.authTokenStore);\n this.tokenOrchestrator.setTokenRefresher(refreshAuthTokens_1.refreshAuthTokens);\n }\n getTokens(options = {}) {\n return this.tokenOrchestrator.getTokens(options);\n }\n setKeyValueStorage(keyValueStorage) {\n this.authTokenStore.setKeyValueStorage(keyValueStorage);\n }\n setClientMetadataProvider(clientMetadataProvider) {\n this.tokenOrchestrator.setClientMetadataProvider(clientMetadataProvider);\n }\n setAuthConfig(authConfig) {\n this.authTokenStore.setAuthConfig(authConfig);\n this.tokenOrchestrator.setAuthConfig(authConfig);\n }\n}\nexports.CognitoUserPoolsTokenProvider = CognitoUserPoolsTokenProvider;\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC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IAAI;AACJ;AACA,OAAO,CAAC,6BAA6B,GAAG,6BAA6B;;"}
|
|
@@ -60,6 +60,9 @@ class TokenOrchestrator {
|
|
|
60
60
|
}
|
|
61
61
|
return this.tokenRefresher;
|
|
62
62
|
}
|
|
63
|
+
setClientMetadataProvider(clientMetadataProvider) {
|
|
64
|
+
this.clientMetadataProvider = clientMetadataProvider;
|
|
65
|
+
}
|
|
63
66
|
async getTokens(options) {
|
|
64
67
|
let tokens;
|
|
65
68
|
try {
|
|
@@ -89,6 +92,7 @@ class TokenOrchestrator {
|
|
|
89
92
|
tokens = await this.refreshTokens({
|
|
90
93
|
tokens,
|
|
91
94
|
username,
|
|
95
|
+
clientMetadata: options?.clientMetadata ?? (await this.clientMetadataProvider?.()),
|
|
92
96
|
});
|
|
93
97
|
if (tokens === null) {
|
|
94
98
|
return null;
|
|
@@ -100,13 +104,14 @@ class TokenOrchestrator {
|
|
|
100
104
|
signInDetails: tokens?.signInDetails,
|
|
101
105
|
};
|
|
102
106
|
}
|
|
103
|
-
async refreshTokens({ tokens, username, }) {
|
|
107
|
+
async refreshTokens({ tokens, username, clientMetadata, }) {
|
|
104
108
|
try {
|
|
105
109
|
const { signInDetails } = tokens;
|
|
106
110
|
const newTokens = await this.getTokenRefresher()({
|
|
107
111
|
tokens,
|
|
108
112
|
authConfig: this.authConfig,
|
|
109
113
|
username,
|
|
114
|
+
clientMetadata,
|
|
110
115
|
});
|
|
111
116
|
newTokens.signInDetails = signInDetails;
|
|
112
117
|
await this.setTokens({ tokens: newTokens });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TokenOrchestrator.js","sources":["../../../../../src/providers/cognito/tokenProvider/TokenOrchestrator.ts"],"sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.TokenOrchestrator = void 0;\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nconst core_1 = require(\"@aws-amplify/core\");\nconst utils_1 = require(\"@aws-amplify/core/internals/utils\");\nconst assertServiceError_1 = require(\"../../../errors/utils/assertServiceError\");\nconst AuthError_1 = require(\"../../../errors/AuthError\");\nconst oAuthStore_1 = require(\"../utils/oauth/oAuthStore\");\nconst inflightPromise_1 = require(\"../utils/oauth/inflightPromise\");\nclass TokenOrchestrator {\n constructor() {\n this.waitForInflightOAuth = (0, utils_1.isBrowser)()\n ? async () => {\n if (!(await oAuthStore_1.oAuthStore.loadOAuthInFlight())) {\n return;\n }\n if (this.inflightPromise) {\n return this.inflightPromise;\n }\n // when there is valid oauth config and there is an inflight oauth flow, try\n // to block async calls that require fetching tokens before the oauth flow completes\n // e.g. getCurrentUser, fetchAuthSession etc.\n this.inflightPromise = new Promise((resolve, _reject) => {\n (0, inflightPromise_1.addInflightPromise)(resolve);\n });\n return this.inflightPromise;\n }\n : async () => {\n // no-op for non-browser environments\n };\n }\n setAuthConfig(authConfig) {\n oAuthStore_1.oAuthStore.setAuthConfig(authConfig.Cognito);\n this.authConfig = authConfig;\n }\n setTokenRefresher(tokenRefresher) {\n this.tokenRefresher = tokenRefresher;\n }\n setAuthTokenStore(tokenStore) {\n this.tokenStore = tokenStore;\n }\n getTokenStore() {\n if (!this.tokenStore) {\n throw new AuthError_1.AuthError({\n name: 'EmptyTokenStoreException',\n message: 'TokenStore not set',\n });\n }\n return this.tokenStore;\n }\n getTokenRefresher() {\n if (!this.tokenRefresher) {\n throw new AuthError_1.AuthError({\n name: 'EmptyTokenRefresherException',\n message: 'TokenRefresher not set',\n });\n }\n return this.tokenRefresher;\n }\n async getTokens(options) {\n let tokens;\n try {\n (0, utils_1.assertTokenProviderConfig)(this.authConfig?.Cognito);\n }\n catch (_err) {\n // Token provider not configured\n return null;\n }\n await this.waitForInflightOAuth();\n this.inflightPromise = undefined;\n tokens = await this.getTokenStore().loadTokens();\n const username = await this.getTokenStore().getLastAuthUser();\n if (tokens === null) {\n return null;\n }\n const idTokenExpired = !!tokens?.idToken &&\n (0, utils_1.isTokenExpired)({\n expiresAt: (tokens.idToken?.payload?.exp ?? 0) * 1000,\n clockDrift: tokens.clockDrift ?? 0,\n });\n const accessTokenExpired = (0, utils_1.isTokenExpired)({\n expiresAt: (tokens.accessToken?.payload?.exp ?? 0) * 1000,\n clockDrift: tokens.clockDrift ?? 0,\n });\n if (options?.forceRefresh || idTokenExpired || accessTokenExpired) {\n tokens = await this.refreshTokens({\n tokens,\n username,\n });\n if (tokens === null) {\n return null;\n }\n }\n return {\n accessToken: tokens?.accessToken,\n idToken: tokens?.idToken,\n signInDetails: tokens?.signInDetails,\n };\n }\n async refreshTokens({ tokens, username, }) {\n try {\n const { signInDetails } = tokens;\n const newTokens = await this.getTokenRefresher()({\n tokens,\n authConfig: this.authConfig,\n username,\n });\n newTokens.signInDetails = signInDetails;\n await this.setTokens({ tokens: newTokens });\n core_1.Hub.dispatch('auth', { event: 'tokenRefresh' }, 'Auth', utils_1.AMPLIFY_SYMBOL);\n return newTokens;\n }\n catch (err) {\n return this.handleErrors(err);\n }\n }\n handleErrors(err) {\n (0, assertServiceError_1.assertServiceError)(err);\n if (err.name !== utils_1.AmplifyErrorCode.NetworkError) {\n // TODO(v6): Check errors on client\n this.clearTokens();\n }\n core_1.Hub.dispatch('auth', {\n event: 'tokenRefresh_failure',\n data: { error: err },\n }, 'Auth', utils_1.AMPLIFY_SYMBOL);\n if (err.name.startsWith('NotAuthorizedException')) {\n return null;\n }\n throw err;\n }\n async setTokens({ tokens }) {\n return this.getTokenStore().storeTokens(tokens);\n }\n async clearTokens() {\n return this.getTokenStore().clearTokens();\n }\n getDeviceMetadata(username) {\n return this.getTokenStore().getDeviceMetadata(username);\n }\n clearDeviceMetadata(username) {\n return this.getTokenStore().clearDeviceMetadata(username);\n }\n setOAuthMetadata(metadata) {\n return this.getTokenStore().setOAuthMetadata(metadata);\n }\n getOAuthMetadata() {\n return this.getTokenStore().getOAuthMetadata();\n }\n}\nexports.TokenOrchestrator = TokenOrchestrator;\n"],"names":[],"mapp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AAa,EAAE,CAAC,WAAW,CAAC,MAAM,CAAC;AACvD,IAAI;AACJ,IAAI,MAAM,WAAW,GAAG;AACxB,QAAQ,OAAO,IAAI,CAAC,aAAa,EAAE,CAAC,WAAW,EAAE;AACjD,IAAI;AACJ,IAAI,iBAAiB,CAAC,QAAQ,EAAE;AAChC,QAAQ,OAAO,IAAI,CAAC,aAAa,EAAE,CAAC,iBAAiB,CAAC,QAAQ,CAAC;AAC/D,IAAI;AACJ,IAAI,mBAAmB,CAAC,QAAQ,EAAE;AAClC,QAAQ,OAAO,IAAI,CAAC,aAAa,EAAE,CAAC,mBAAmB,CAAC,QAAQ,CAAC;AACjE,IAAI;AACJ,IAAI,gBAAgB,CAAC,QAAQ,EAAE;AAC/B,QAAQ,OAAO,IAAI,CAAC,aAAa,EAAE,CAAC,gBAAgB,CAAC,QAAQ,CAAC;AAC9D,IAAI;AACJ,IAAI,gBAAgB,GAAG;AACvB,QAAQ,OAAO,IAAI,CAAC,aAAa,EAAE,CAAC,gBAAgB,EAAE;AACtD,IAAI;AACJ;AACA,OAAO,CAAC,iBAAiB,GAAG,iBAAiB;;"}
|
|
1
|
+
{"version":3,"file":"TokenOrchestrator.js","sources":["../../../../../src/providers/cognito/tokenProvider/TokenOrchestrator.ts"],"sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.TokenOrchestrator = void 0;\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nconst core_1 = require(\"@aws-amplify/core\");\nconst utils_1 = require(\"@aws-amplify/core/internals/utils\");\nconst assertServiceError_1 = require(\"../../../errors/utils/assertServiceError\");\nconst AuthError_1 = require(\"../../../errors/AuthError\");\nconst oAuthStore_1 = require(\"../utils/oauth/oAuthStore\");\nconst inflightPromise_1 = require(\"../utils/oauth/inflightPromise\");\nclass TokenOrchestrator {\n constructor() {\n this.waitForInflightOAuth = (0, utils_1.isBrowser)()\n ? async () => {\n if (!(await oAuthStore_1.oAuthStore.loadOAuthInFlight())) {\n return;\n }\n if (this.inflightPromise) {\n return this.inflightPromise;\n }\n // when there is valid oauth config and there is an inflight oauth flow, try\n // to block async calls that require fetching tokens before the oauth flow completes\n // e.g. getCurrentUser, fetchAuthSession etc.\n this.inflightPromise = new Promise((resolve, _reject) => {\n (0, inflightPromise_1.addInflightPromise)(resolve);\n });\n return this.inflightPromise;\n }\n : async () => {\n // no-op for non-browser environments\n };\n }\n setAuthConfig(authConfig) {\n oAuthStore_1.oAuthStore.setAuthConfig(authConfig.Cognito);\n this.authConfig = authConfig;\n }\n setTokenRefresher(tokenRefresher) {\n this.tokenRefresher = tokenRefresher;\n }\n setAuthTokenStore(tokenStore) {\n this.tokenStore = tokenStore;\n }\n getTokenStore() {\n if (!this.tokenStore) {\n throw new AuthError_1.AuthError({\n name: 'EmptyTokenStoreException',\n message: 'TokenStore not set',\n });\n }\n return this.tokenStore;\n }\n getTokenRefresher() {\n if (!this.tokenRefresher) {\n throw new AuthError_1.AuthError({\n name: 'EmptyTokenRefresherException',\n message: 'TokenRefresher not set',\n });\n }\n return this.tokenRefresher;\n }\n setClientMetadataProvider(clientMetadataProvider) {\n this.clientMetadataProvider = clientMetadataProvider;\n }\n async getTokens(options) {\n let tokens;\n try {\n (0, utils_1.assertTokenProviderConfig)(this.authConfig?.Cognito);\n }\n catch (_err) {\n // Token provider not configured\n return null;\n }\n await this.waitForInflightOAuth();\n this.inflightPromise = undefined;\n tokens = await this.getTokenStore().loadTokens();\n const username = await this.getTokenStore().getLastAuthUser();\n if (tokens === null) {\n return null;\n }\n const idTokenExpired = !!tokens?.idToken &&\n (0, utils_1.isTokenExpired)({\n expiresAt: (tokens.idToken?.payload?.exp ?? 0) * 1000,\n clockDrift: tokens.clockDrift ?? 0,\n });\n const accessTokenExpired = (0, utils_1.isTokenExpired)({\n expiresAt: (tokens.accessToken?.payload?.exp ?? 0) * 1000,\n clockDrift: tokens.clockDrift ?? 0,\n });\n if (options?.forceRefresh || idTokenExpired || accessTokenExpired) {\n tokens = await this.refreshTokens({\n tokens,\n username,\n clientMetadata: options?.clientMetadata ?? (await this.clientMetadataProvider?.()),\n });\n if (tokens === null) {\n return null;\n }\n }\n return {\n accessToken: tokens?.accessToken,\n idToken: tokens?.idToken,\n signInDetails: tokens?.signInDetails,\n };\n }\n async refreshTokens({ tokens, username, clientMetadata, }) {\n try {\n const { signInDetails } = tokens;\n const newTokens = await this.getTokenRefresher()({\n tokens,\n authConfig: this.authConfig,\n username,\n clientMetadata,\n });\n newTokens.signInDetails = signInDetails;\n await this.setTokens({ tokens: newTokens });\n core_1.Hub.dispatch('auth', { event: 'tokenRefresh' }, 'Auth', utils_1.AMPLIFY_SYMBOL);\n return newTokens;\n }\n catch (err) {\n return this.handleErrors(err);\n }\n }\n handleErrors(err) {\n (0, assertServiceError_1.assertServiceError)(err);\n if (err.name !== utils_1.AmplifyErrorCode.NetworkError) {\n // TODO(v6): Check errors on client\n this.clearTokens();\n }\n core_1.Hub.dispatch('auth', {\n event: 'tokenRefresh_failure',\n data: { error: err },\n }, 'Auth', utils_1.AMPLIFY_SYMBOL);\n if (err.name.startsWith('NotAuthorizedException')) {\n return null;\n }\n throw err;\n }\n async setTokens({ tokens }) {\n return this.getTokenStore().storeTokens(tokens);\n }\n async clearTokens() {\n return this.getTokenStore().clearTokens();\n }\n getDeviceMetadata(username) {\n return this.getTokenStore().getDeviceMetadata(username);\n }\n clearDeviceMetadata(username) {\n return this.getTokenStore().clearDeviceMetadata(username);\n }\n setOAuthMetadata(metadata) {\n return this.getTokenStore().setOAuthMetadata(metadata);\n }\n getOAuthMetadata() {\n return this.getTokenStore().getOAuthMetadata();\n }\n}\nexports.TokenOrchestrator = TokenOrchestrator;\n"],"names":[],"mappings":";;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AAC7D,OAAO,CAAC,iBAAiB,GAAG,MAAM;AAClC;AACA;AAC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AI,MAAM,SAAS,CAAC,EAAE,MAAM,EAAE,EAAE;AAChC,QAAQ,OAAO,IAAI,CAAC,aAAa,EAAE,CAAC,WAAW,CAAC,MAAM,CAAC;AACvD,IAAI;AACJ,IAAI,MAAM,WAAW,GAAG;AACxB,QAAQ,OAAO,IAAI,CAAC,aAAa,EAAE,CAAC,WAAW,EAAE;AACjD,IAAI;AACJ,IAAI,iBAAiB,CAAC,QAAQ,EAAE;AAChC,QAAQ,OAAO,IAAI,CAAC,aAAa,EAAE,CAAC,iBAAiB,CAAC,QAAQ,CAAC;AAC/D,IAAI;AACJ,IAAI,mBAAmB,CAAC,QAAQ,EAAE;AAClC,QAAQ,OAAO,IAAI,CAAC,aAAa,EAAE,CAAC,mBAAmB,CAAC,QAAQ,CAAC;AACjE,IAAI;AACJ,IAAI,gBAAgB,CAAC,QAAQ,EAAE;AAC/B,QAAQ,OAAO,IAAI,CAAC,aAAa,EAAE,CAAC,gBAAgB,CAAC,QAAQ,CAAC;AAC9D,IAAI;AACJ,IAAI,gBAAgB,GAAG;AACvB,QAAQ,OAAO,IAAI,CAAC,aAAa,EAAE,CAAC,gBAAgB,EAAE;AACtD,IAAI;AACJ;AACA,OAAO,CAAC,iBAAiB,GAAG,iBAAiB;;"}
|
|
@@ -10,7 +10,7 @@ const types_1 = require("../utils/types");
|
|
|
10
10
|
const AuthError_1 = require("../../../errors/AuthError");
|
|
11
11
|
const factories_1 = require("../factories");
|
|
12
12
|
const cognitoIdentityProvider_1 = require("../../../foundation/factories/serviceClients/cognitoIdentityProvider");
|
|
13
|
-
const refreshAuthTokensFunction = async ({ tokens, authConfig, username, }) => {
|
|
13
|
+
const refreshAuthTokensFunction = async ({ tokens, authConfig, username, clientMetadata, }) => {
|
|
14
14
|
(0, utils_1.assertTokenProviderConfig)(authConfig?.Cognito);
|
|
15
15
|
const { userPoolId, userPoolClientId, userPoolEndpoint } = authConfig.Cognito;
|
|
16
16
|
const region = (0, parsers_1.getRegionFromUserPoolId)(userPoolId);
|
|
@@ -24,6 +24,7 @@ const refreshAuthTokensFunction = async ({ tokens, authConfig, username, }) => {
|
|
|
24
24
|
ClientId: userPoolClientId,
|
|
25
25
|
RefreshToken: tokens.refreshToken,
|
|
26
26
|
DeviceKey: tokens.deviceMetadata?.deviceKey,
|
|
27
|
+
ClientMetadata: clientMetadata,
|
|
27
28
|
});
|
|
28
29
|
const accessToken = (0, utils_1.decodeJWT)(AuthenticationResult?.AccessToken ?? '');
|
|
29
30
|
const idToken = AuthenticationResult?.IdToken
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"refreshAuthTokens.js","sources":["../../../../../src/providers/cognito/utils/refreshAuthTokens.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.refreshAuthTokensWithoutDedupe = exports.refreshAuthTokens = void 0;\nconst utils_1 = require(\"@aws-amplify/core/internals/utils\");\nconst parsers_1 = require(\"../../../foundation/parsers\");\nconst types_1 = require(\"../utils/types\");\nconst AuthError_1 = require(\"../../../errors/AuthError\");\nconst factories_1 = require(\"../factories\");\nconst cognitoIdentityProvider_1 = require(\"../../../foundation/factories/serviceClients/cognitoIdentityProvider\");\nconst refreshAuthTokensFunction = async ({ tokens, authConfig, username, }) => {\n (0, utils_1.assertTokenProviderConfig)(authConfig?.Cognito);\n const { userPoolId, userPoolClientId, userPoolEndpoint } = authConfig.Cognito;\n const region = (0, parsers_1.getRegionFromUserPoolId)(userPoolId);\n (0, types_1.assertAuthTokensWithRefreshToken)(tokens);\n const getTokensFromRefreshToken = (0, cognitoIdentityProvider_1.createGetTokensFromRefreshTokenClient)({\n endpointResolver: (0, factories_1.createCognitoUserPoolEndpointResolver)({\n endpointOverride: userPoolEndpoint,\n }),\n });\n const { AuthenticationResult } = await getTokensFromRefreshToken({ region }, {\n ClientId: userPoolClientId,\n RefreshToken: tokens.refreshToken,\n DeviceKey: tokens.deviceMetadata?.deviceKey,\n });\n const accessToken = (0, utils_1.decodeJWT)(AuthenticationResult?.AccessToken ?? '');\n const idToken = AuthenticationResult?.IdToken\n ? (0, utils_1.decodeJWT)(AuthenticationResult.IdToken)\n : undefined;\n const { iat } = accessToken.payload;\n // This should never happen. If it does, it's a bug from the service.\n if (!iat) {\n throw new AuthError_1.AuthError({\n name: 'iatNotFoundException',\n message: 'iat not found in access token',\n });\n }\n const clockDrift = iat * 1000 - new Date().getTime();\n return {\n accessToken,\n idToken,\n clockDrift,\n refreshToken: AuthenticationResult?.RefreshToken ?? tokens.refreshToken,\n username,\n };\n};\nexports.refreshAuthTokens = (0, utils_1.deDupeAsyncFunction)(refreshAuthTokensFunction);\nexports.refreshAuthTokensWithoutDedupe = refreshAuthTokensFunction;\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AAC7D,OAAO,CAAC,8BAA8B,GAAG,OAAO,CAAC,iBAAiB,GAAG,MAAM;AAC3E,MAAM,OAAO,GAAG,OAAO,CAAC,mCAAmC,CAAC;AAC5D,MAAM,SAAS,GAAG,OAAO,CAAC,6BAA6B,CAAC;AACxD,MAAM,OAAO,GAAG,OAAO,CAAC,gBAAgB,CAAC;AACzC,MAAM,WAAW,GAAG,OAAO,CAAC,2BAA2B,CAAC;AACxD,MAAM,WAAW,GAAG,OAAO,CAAC,cAAc,CAAC;AAC3C,MAAM,yBAAyB,GAAG,OAAO,CAAC,sEAAsE,CAAC;AACjH,MAAM,yBAAyB,GAAG,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,QAAQ,GAAG,KAAK;AAC/
|
|
1
|
+
{"version":3,"file":"refreshAuthTokens.js","sources":["../../../../../src/providers/cognito/utils/refreshAuthTokens.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.refreshAuthTokensWithoutDedupe = exports.refreshAuthTokens = void 0;\nconst utils_1 = require(\"@aws-amplify/core/internals/utils\");\nconst parsers_1 = require(\"../../../foundation/parsers\");\nconst types_1 = require(\"../utils/types\");\nconst AuthError_1 = require(\"../../../errors/AuthError\");\nconst factories_1 = require(\"../factories\");\nconst cognitoIdentityProvider_1 = require(\"../../../foundation/factories/serviceClients/cognitoIdentityProvider\");\nconst refreshAuthTokensFunction = async ({ tokens, authConfig, username, clientMetadata, }) => {\n (0, utils_1.assertTokenProviderConfig)(authConfig?.Cognito);\n const { userPoolId, userPoolClientId, userPoolEndpoint } = authConfig.Cognito;\n const region = (0, parsers_1.getRegionFromUserPoolId)(userPoolId);\n (0, types_1.assertAuthTokensWithRefreshToken)(tokens);\n const getTokensFromRefreshToken = (0, cognitoIdentityProvider_1.createGetTokensFromRefreshTokenClient)({\n endpointResolver: (0, factories_1.createCognitoUserPoolEndpointResolver)({\n endpointOverride: userPoolEndpoint,\n }),\n });\n const { AuthenticationResult } = await getTokensFromRefreshToken({ region }, {\n ClientId: userPoolClientId,\n RefreshToken: tokens.refreshToken,\n DeviceKey: tokens.deviceMetadata?.deviceKey,\n ClientMetadata: clientMetadata,\n });\n const accessToken = (0, utils_1.decodeJWT)(AuthenticationResult?.AccessToken ?? '');\n const idToken = AuthenticationResult?.IdToken\n ? (0, utils_1.decodeJWT)(AuthenticationResult.IdToken)\n : undefined;\n const { iat } = accessToken.payload;\n // This should never happen. If it does, it's a bug from the service.\n if (!iat) {\n throw new AuthError_1.AuthError({\n name: 'iatNotFoundException',\n message: 'iat not found in access token',\n });\n }\n const clockDrift = iat * 1000 - new Date().getTime();\n return {\n accessToken,\n idToken,\n clockDrift,\n refreshToken: AuthenticationResult?.RefreshToken ?? tokens.refreshToken,\n username,\n };\n};\nexports.refreshAuthTokens = (0, utils_1.deDupeAsyncFunction)(refreshAuthTokensFunction);\nexports.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gB;AAClC,QAAQ,YAAY,EAAE,MAAM,CAAC,YAAY;AACzC,QAAQ,SAAS,EAAE,MAAM,CAAC,cAAc,EAAE,SAAS;AACnD,QAAQ,cAAc,EAAE,cAAc;AACtC,KAAK,CAAC;AACN,IAAI,MAAM,WAAW,GAAG,IAAI,OAAO,CAAC,SAAS,EAAE,oBAAoB,EAAE,WAAW,IAAI,EAAE,CAAC;AACvF,IAAI,MAAM,OAAO,GAAG,oBAAoB,EAAE;AAC1C,UAAU,IAAI,OAAO,CAAC,SAAS,EAAE,oBAAoB,CAAC,OAAO;AAC7D,UAAU,SAAS;AACnB,IAAI,MAAM,EAAE,GAAG,EAAE,GAAG,WAAW,CAAC,OAAO;AACvC;AACA,IAAI,IAAI,CAAC,GAAG,EAAE;AACd,QAAQ,MAAM,IAAI,WAAW,CAAC,SAAS,CAAC;AACxC,YAAY,IAAI,EAAE,sBAAsB;AACxC,YAAY,OAAO,EAAE,+BAA+B;AACpD,SAAS,CAAC;AACV,IAAI;AACJ,IAAI,MAAM,UAAU,GAAG,GAAG,GAAG,IAAI,GAAG,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE;AACxD,IAAI,OAAO;AACX,QAAQ,WAAW;AACnB,QAAQ,OAAO;AACf,QAAQ,UAAU;AAClB,QAAQ,YAAY,EAAE,oBAAoB,EAAE,YAAY,IAAI,MAAM,CAAC,YAAY;AAC/E,QAAQ,QAAQ;AAChB,KAAK;AACL,CAAC;AACD,OAAO,CAAC,iBAAiB,GAAG,IAAI,OAAO,CAAC,mBAAmB,EAAE,yBAAyB,CAAC;AACvF,OAAO,CAAC,8BAA8B,GAAG,yBAAyB;;"}
|
|
@@ -37,16 +37,21 @@ async function signInWithRedirect(input) {
|
|
|
37
37
|
await assertUserNotAuthenticated();
|
|
38
38
|
}
|
|
39
39
|
let provider = 'COGNITO'; // Default
|
|
40
|
+
let idpIdentifier;
|
|
40
41
|
if (typeof input?.provider === 'string') {
|
|
41
42
|
provider = cognitoHostedUIIdentityProviderMap[input.provider];
|
|
42
43
|
}
|
|
43
44
|
else if (input?.provider?.custom) {
|
|
44
45
|
provider = input.provider.custom;
|
|
45
46
|
}
|
|
47
|
+
else if (input?.provider?.idpIdentifier) {
|
|
48
|
+
({ idpIdentifier } = input.provider);
|
|
49
|
+
}
|
|
46
50
|
return oauthSignIn({
|
|
47
51
|
oauthConfig: authConfig.loginWith.oauth,
|
|
48
52
|
clientId: authConfig.userPoolClientId,
|
|
49
53
|
provider,
|
|
54
|
+
idpIdentifier,
|
|
50
55
|
customState: input?.customState,
|
|
51
56
|
preferPrivateSession: input?.options?.preferPrivateSession,
|
|
52
57
|
options: {
|
|
@@ -58,7 +63,7 @@ async function signInWithRedirect(input) {
|
|
|
58
63
|
authSessionOpener: input?.options?.authSessionOpener,
|
|
59
64
|
});
|
|
60
65
|
}
|
|
61
|
-
const oauthSignIn = async ({ oauthConfig, provider, clientId, customState, preferPrivateSession, options, authSessionOpener, }) => {
|
|
66
|
+
const oauthSignIn = async ({ oauthConfig, provider, idpIdentifier, clientId, customState, preferPrivateSession, options, authSessionOpener, }) => {
|
|
62
67
|
const { domain, redirectSignIn, responseType, scopes } = oauthConfig;
|
|
63
68
|
const { loginHint, lang, nonce, prompt } = options ?? {};
|
|
64
69
|
const randomState = generateState();
|
|
@@ -82,9 +87,15 @@ const oauthSignIn = async ({ oauthConfig, provider, clientId, customState, prefe
|
|
|
82
87
|
['redirect_uri', redirectUri],
|
|
83
88
|
['response_type', responseType],
|
|
84
89
|
['client_id', clientId],
|
|
85
|
-
['identity_provider', provider],
|
|
86
|
-
['scope', scopes.join(' ')],
|
|
87
90
|
]);
|
|
91
|
+
// Add either identity_provider or idp_identifier, but not both
|
|
92
|
+
if (idpIdentifier) {
|
|
93
|
+
params.append('idp_identifier', idpIdentifier);
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
params.append('identity_provider', provider);
|
|
97
|
+
}
|
|
98
|
+
params.append('scope', scopes.join(' '));
|
|
88
99
|
loginHint && params.append('login_hint', loginHint);
|
|
89
100
|
lang && params.append('lang', lang);
|
|
90
101
|
nonce && params.append('nonce', nonce);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signInWithRedirect.mjs","sources":["../../../../../src/providers/cognito/apis/signInWithRedirect.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { Amplify } from '@aws-amplify/core';\nimport { AuthAction, assertOAuthConfig, assertTokenProviderConfig, isBrowser, urlSafeEncode, } from '@aws-amplify/core/internals/utils';\nimport '../utils/oauth/enableOAuthListener';\nimport { cognitoHostedUIIdentityProviderMap } from '../types/models';\nimport { openAuthSession as _openAuthSession, getAuthUserAgentValue, } from '../../../utils';\nimport { assertUserNotAuthenticated } from '../utils/signInHelpers';\nimport { completeOAuthFlow, generateCodeVerifier, generateState, getRedirectUrl, handleFailure, oAuthStore, } from '../utils/oauth';\nimport { createOAuthError } from '../utils/oauth/createOAuthError';\nimport { listenForOAuthFlowCancellation } from '../utils/oauth/cancelOAuthFlow';\n/**\n * Signs in a user with OAuth. Redirects the application to an Identity Provider.\n *\n * @param input - The SignInWithRedirectInput object, if empty it will redirect to Cognito HostedUI\n *\n * @throws AuthTokenConfigException - Thrown when the user pool config is invalid.\n * @throws OAuthNotConfigureException - Thrown when the oauth config is invalid.\n */\nexport async function signInWithRedirect(input) {\n const authConfig = Amplify.getConfig().Auth?.Cognito;\n assertTokenProviderConfig(authConfig);\n assertOAuthConfig(authConfig);\n oAuthStore.setAuthConfig(authConfig);\n if (!input?.options?.prompt) {\n await assertUserNotAuthenticated();\n }\n let provider = 'COGNITO'; // Default\n if (typeof input?.provider === 'string') {\n provider = cognitoHostedUIIdentityProviderMap[input.provider];\n }\n else if (input?.provider?.custom) {\n provider = input.provider.custom;\n }\n return oauthSignIn({\n oauthConfig: authConfig.loginWith.oauth,\n clientId: authConfig.userPoolClientId,\n provider,\n customState: input?.customState,\n preferPrivateSession: input?.options?.preferPrivateSession,\n options: {\n loginHint: input?.options?.loginHint,\n lang: input?.options?.lang,\n nonce: input?.options?.nonce,\n prompt: input?.options?.prompt,\n },\n authSessionOpener: input?.options?.authSessionOpener,\n });\n}\nconst oauthSignIn = async ({ oauthConfig, provider, clientId, customState, preferPrivateSession, options, authSessionOpener, }) => {\n const { domain, redirectSignIn, responseType, scopes } = oauthConfig;\n const { loginHint, lang, nonce, prompt } = options ?? {};\n const randomState = generateState();\n const openAuthSession = authSessionOpener || _openAuthSession;\n /* encodeURIComponent is not URL safe, use urlSafeEncode instead. Cognito\n single-encodes/decodes url on first sign in and double-encodes/decodes url\n when user already signed in. Using encodeURIComponent, Base32, Base64 add\n characters % or = which on further encoding becomes unsafe. '=' create issue\n for parsing query params.\n Refer: https://github.com/aws-amplify/amplify-js/issues/5218 */\n const state = customState\n ? `${randomState}-${urlSafeEncode(customState)}`\n : randomState;\n const { value, method, toCodeChallenge } = generateCodeVerifier(128);\n const redirectUri = getRedirectUrl(oauthConfig.redirectSignIn);\n if (isBrowser())\n oAuthStore.storeOAuthInFlight(true);\n oAuthStore.storeOAuthState(state);\n oAuthStore.storePKCE(value);\n const params = new URLSearchParams([\n ['redirect_uri', redirectUri],\n ['response_type', responseType],\n ['client_id', clientId],\n ['identity_provider', provider],\n ['scope', scopes.join(' ')],\n ]);\n loginHint && params.append('login_hint', loginHint);\n lang && params.append('lang', lang);\n nonce && params.append('nonce', nonce);\n prompt && params.append('prompt', prompt.toLowerCase());\n params.append('state', state);\n if (responseType === 'code') {\n params.append('code_challenge', toCodeChallenge());\n params.append('code_challenge_method', method);\n }\n // Using URL object is not supported in React Native as the `search` property is read-only\n // See: https://github.com/facebook/react-native/blob/main/packages/react-native/Libraries/Blob/URL.js\n const oAuthUrl = `https://${domain}/oauth2/authorize?${params.toString()}`;\n // this will only take effect in the following scenarios:\n // 1. the user cancels the OAuth flow on web via back button, and\n // 2. when bfcache is enabled\n listenForOAuthFlowCancellation(oAuthStore);\n // the following is effective only in react-native as openAuthSession resolves only in react-native\n const { type, error, url } = (await openAuthSession(oAuthUrl, redirectSignIn, preferPrivateSession)) ??\n {};\n try {\n if (type === 'error') {\n throw createOAuthError(String(error));\n }\n if (type === 'canceled') {\n throw createOAuthError(String(type));\n }\n if (type === 'success' && url) {\n await completeOAuthFlow({\n currentUrl: url,\n clientId,\n domain,\n redirectUri,\n responseType,\n userAgentValue: getAuthUserAgentValue(AuthAction.SignInWithRedirect),\n preferPrivateSession,\n });\n }\n }\n catch (err) {\n await handleFailure(err);\n // rethrow the error so it can be caught by `await signInWithRedirect()` in react-native\n throw err;\n }\n};\n"],"names":["openAuthSession","_openAuthSession"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AACA;AAUA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,eAAe,kBAAkB,CAAC,KAAK,EAAE;AAChD,IAAI,MAAM,UAAU,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC,IAAI,EAAE,OAAO;AACxD,IAAI,yBAAyB,CAAC,UAAU,CAAC;AACzC,IAAI,iBAAiB,CAAC,UAAU,CAAC;AACjC,IAAI,UAAU,CAAC,aAAa,CAAC,UAAU,CAAC;AACxC,IAAI,IAAI,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE;AACjC,QAAQ,MAAM,0BAA0B,EAAE;AAC1C,IAAI;AACJ,IAAI,IAAI,QAAQ,GAAG,SAAS,CAAC;AAC7B,IAAI,IAAI,OAAO,KAAK,EAAE,QAAQ,KAAK,QAAQ,EAAE;AAC7C,QAAQ,QAAQ,GAAG,kCAAkC,CAAC,KAAK,CAAC,QAAQ,CAAC;AACrE,IAAI;AACJ,SAAS,IAAI,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE;AACtC,QAAQ,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAAC,MAAM;AACxC,IAAI;AACJ,IAAI,OAAO,WAAW,CAAC;AACvB,QAAQ,WAAW,EAAE,UAAU,CAAC,SAAS,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B,CAAC,UAAU,CAAC;AAC9C;AACA,IAAI,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,EAAE,GAAG,CAAC,MAAMD,iBAAe,CAAC,QAAQ,EAAE,cAAc,EAAE,oBAAoB,CAAC;AACvG,QAAQ,EAAE;AACV,IAAI,IAAI;AACR,QAAQ,IAAI,IAAI,KAAK,OAAO,EAAE;AAC9B,YAAY,MAAM,gBAAgB,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AACjD,QAAQ;AACR,QAAQ,IAAI,IAAI,KAAK,UAAU,EAAE;AACjC,YAAY,MAAM,gBAAgB,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;AAChD,QAAQ;AACR,QAAQ,IAAI,IAAI,KAAK,SAAS,IAAI,GAAG,EAAE;AACvC,YAAY,MAAM,iBAAiB,CAAC;AACpC,gBAAgB,UAAU,EAAE,GAAG;AAC/B,gBAAgB,QAAQ;AACxB,gBAAgB,MAAM;AACtB,gBAAgB,WAAW;AAC3B,gBAAgB,YAAY;AAC5B,gBAAgB,cAAc,EAAE,qBAAqB,CAAC,UAAU,CAAC,kBAAkB,CAAC;AACpF,gBAAgB,oBAAoB;AACpC,aAAa,CAAC;AACd,QAAQ;AACR,IAAI;AACJ,IAAI,OAAO,GAAG,EAAE;AAChB,QAAQ,MAAM,aAAa,CAAC,GAAG,CAAC;AAChC;AACA,QAAQ,MAAM,GAAG;AACjB,IAAI;AACJ,CAAC;;;;"}
|
|
1
|
+
{"version":3,"file":"signInWithRedirect.mjs","sources":["../../../../../src/providers/cognito/apis/signInWithRedirect.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { Amplify } from '@aws-amplify/core';\nimport { AuthAction, assertOAuthConfig, assertTokenProviderConfig, isBrowser, urlSafeEncode, } from '@aws-amplify/core/internals/utils';\nimport '../utils/oauth/enableOAuthListener';\nimport { cognitoHostedUIIdentityProviderMap } from '../types/models';\nimport { openAuthSession as _openAuthSession, getAuthUserAgentValue, } from '../../../utils';\nimport { assertUserNotAuthenticated } from '../utils/signInHelpers';\nimport { completeOAuthFlow, generateCodeVerifier, generateState, getRedirectUrl, handleFailure, oAuthStore, } from '../utils/oauth';\nimport { createOAuthError } from '../utils/oauth/createOAuthError';\nimport { listenForOAuthFlowCancellation } from '../utils/oauth/cancelOAuthFlow';\n/**\n * Signs in a user with OAuth. Redirects the application to an Identity Provider.\n *\n * @param input - The SignInWithRedirectInput object, if empty it will redirect to Cognito HostedUI\n *\n * @throws AuthTokenConfigException - Thrown when the user pool config is invalid.\n * @throws OAuthNotConfigureException - Thrown when the oauth config is invalid.\n */\nexport async function signInWithRedirect(input) {\n const authConfig = Amplify.getConfig().Auth?.Cognito;\n assertTokenProviderConfig(authConfig);\n assertOAuthConfig(authConfig);\n oAuthStore.setAuthConfig(authConfig);\n if (!input?.options?.prompt) {\n await assertUserNotAuthenticated();\n }\n let provider = 'COGNITO'; // Default\n let idpIdentifier;\n if (typeof input?.provider === 'string') {\n provider = cognitoHostedUIIdentityProviderMap[input.provider];\n }\n else if (input?.provider?.custom) {\n provider = input.provider.custom;\n }\n else if (input?.provider?.idpIdentifier) {\n ({ idpIdentifier } = input.provider);\n }\n return oauthSignIn({\n oauthConfig: authConfig.loginWith.oauth,\n clientId: authConfig.userPoolClientId,\n provider,\n idpIdentifier,\n customState: input?.customState,\n preferPrivateSession: input?.options?.preferPrivateSession,\n options: {\n loginHint: input?.options?.loginHint,\n lang: input?.options?.lang,\n nonce: input?.options?.nonce,\n prompt: input?.options?.prompt,\n },\n authSessionOpener: input?.options?.authSessionOpener,\n });\n}\nconst oauthSignIn = async ({ oauthConfig, provider, idpIdentifier, clientId, customState, preferPrivateSession, options, authSessionOpener, }) => {\n const { domain, redirectSignIn, responseType, scopes } = oauthConfig;\n const { loginHint, lang, nonce, prompt } = options ?? {};\n const randomState = generateState();\n const openAuthSession = authSessionOpener || _openAuthSession;\n /* encodeURIComponent is not URL safe, use urlSafeEncode instead. Cognito\n single-encodes/decodes url on first sign in and double-encodes/decodes url\n when user already signed in. Using encodeURIComponent, Base32, Base64 add\n characters % or = which on further encoding becomes unsafe. '=' create issue\n for parsing query params.\n Refer: https://github.com/aws-amplify/amplify-js/issues/5218 */\n const state = customState\n ? `${randomState}-${urlSafeEncode(customState)}`\n : randomState;\n const { value, method, toCodeChallenge } = generateCodeVerifier(128);\n const redirectUri = getRedirectUrl(oauthConfig.redirectSignIn);\n if (isBrowser())\n oAuthStore.storeOAuthInFlight(true);\n oAuthStore.storeOAuthState(state);\n oAuthStore.storePKCE(value);\n const params = new URLSearchParams([\n ['redirect_uri', redirectUri],\n ['response_type', responseType],\n ['client_id', clientId],\n ]);\n // Add either identity_provider or idp_identifier, but not both\n if (idpIdentifier) {\n params.append('idp_identifier', idpIdentifier);\n }\n else {\n params.append('identity_provider', provider);\n }\n params.append('scope', scopes.join(' '));\n loginHint && params.append('login_hint', loginHint);\n lang && params.append('lang', lang);\n nonce && params.append('nonce', nonce);\n prompt && params.append('prompt', prompt.toLowerCase());\n params.append('state', state);\n if (responseType === 'code') {\n params.append('code_challenge', toCodeChallenge());\n params.append('code_challenge_method', method);\n }\n // Using URL object is not supported in React Native as the `search` property is read-only\n // See: https://github.com/facebook/react-native/blob/main/packages/react-native/Libraries/Blob/URL.js\n const oAuthUrl = `https://${domain}/oauth2/authorize?${params.toString()}`;\n // this will only take effect in the following scenarios:\n // 1. the user cancels the OAuth flow on web via back button, and\n // 2. when bfcache is enabled\n listenForOAuthFlowCancellation(oAuthStore);\n // the following is effective only in react-native as openAuthSession resolves only in react-native\n const { type, error, url } = (await openAuthSession(oAuthUrl, redirectSignIn, preferPrivateSession)) ??\n {};\n try {\n if (type === 'error') {\n throw createOAuthError(String(error));\n }\n if (type === 'canceled') {\n throw createOAuthError(String(type));\n }\n if (type === 'success' && url) {\n await completeOAuthFlow({\n currentUrl: url,\n clientId,\n domain,\n redirectUri,\n responseType,\n userAgentValue: getAuthUserAgentValue(AuthAction.SignInWithRedirect),\n preferPrivateSession,\n });\n }\n }\n catch (err) {\n await handleFailure(err);\n // rethrow the error so it can be caught by `await signInWithRedirect()` in react-native\n throw err;\n }\n};\n"],"names":["openAuthSession","_openAuthSession"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AACA;AAUA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,eAAe,kBAAkB,CAAC,KAAK,EAAE;AAChD,IAAI,MAAM,UAAU,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC,IAAI,EAAE,OAAO;AACxD,IAAI,yBAAyB,CAAC,UAAU,CAAC;AACzC,IAAI,iBAAiB,CAAC,UAAU,CAAC;AACjC,IAAI,UAAU,CAAC,aAAa,CAAC,UAAU,CAAC;AACxC,IAAI,IAAI,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE;AACjC,QAAQ,MAAM,0BAA0B,EAAE;AAC1C,IAAI;AACJ,IAAI,IAAI,QAAQ,GAAG,SAAS,CAAC;AAC7B,IAAI,IAAI,aAAa;AACrB,IAAI,IAAI,OAAO,KAAK,EAAE,QAAQ,KAAK,QAAQ,EAAE;AAC7C,QAAQ,QAAQ,GAAG,kCAAkC,CAAC,KAAK,CAAC,QAAQ,CAAC;AACrE,IAAI;AACJ,SAAS,IAAI,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE;AACtC,QAAQ,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAAC,MAAM;AACxC,IAAI;AACJ,SAAS,IAAI,KAAK,EAAE,QAAQ,EAAE,aAAa,EAAE;AAC7C,QAAQ,CAAC,EAAE,aAAa,EAAE,GAAG,KAAK,CAAC,QAAQ;AAC3C,IAAI;AACJ,IAAI,OAAO,WAAW,CAAC;AACvB,QAAQ,WAAW,EAAE,UAAU,CAAC,SAAS,CAAC,KAAK;AAC/C,QAAQ,QAAQ,EAAE,UAAU,CAAC,gBAAgB;AAC7C,QAAQ,QAAQ;AAChB,QAAQ,aAAa;AACr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MAAM,CAAC,kBAAkB,EAAE,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAC;AAC9E;AACA;AACA;AACA,IAAI,8BAA8B,CAAC,UAAU,CAAC;AAC9C;AACA,IAAI,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,EAAE,GAAG,CAAC,MAAMD,iBAAe,CAAC,QAAQ,EAAE,cAAc,EAAE,oBAAoB,CAAC;AACvG,QAAQ,EAAE;AACV,IAAI,IAAI;AACR,QAAQ,IAAI,IAAI,KAAK,OAAO,EAAE;AAC9B,YAAY,MAAM,gBAAgB,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AACjD,QAAQ;AACR,QAAQ,IAAI,IAAI,KAAK,UAAU,EAAE;AACjC,YAAY,MAAM,gBAAgB,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;AAChD,QAAQ;AACR,QAAQ,IAAI,IAAI,KAAK,SAAS,IAAI,GAAG,EAAE;AACvC,YAAY,MAAM,iBAAiB,CAAC;AACpC,gBAAgB,UAAU,EAAE,GAAG;AAC/B,gBAAgB,QAAQ;AACxB,gBAAgB,MAAM;AACtB,gBAAgB,WAAW;AAC3B,gBAAgB,YAAY;AAC5B,gBAAgB,cAAc,EAAE,qBAAqB,CAAC,UAAU,CAAC,kBAAkB,CAAC;AACpF,gBAAgB,oBAAoB;AACpC,aAAa,CAAC;AACd,QAAQ;AACR,IAAI;AACJ,IAAI,OAAO,GAAG,EAAE;AAChB,QAAQ,MAAM,aAAa,CAAC,GAAG,CAAC;AAChC;AACA,QAAQ,MAAM,GAAG;AACjB,IAAI;AACJ,CAAC;;;;"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AuthConfig, AuthTokens, FetchAuthSessionOptions, KeyValueStorageInterface } from '@aws-amplify/core';
|
|
1
|
+
import { AuthConfig, AuthTokens, ClientMetadataProvider, FetchAuthSessionOptions, KeyValueStorageInterface } from '@aws-amplify/core';
|
|
2
2
|
import { DefaultTokenStore } from './TokenStore';
|
|
3
3
|
import { TokenOrchestrator } from './TokenOrchestrator';
|
|
4
4
|
import { CognitoUserPoolTokenProviderType } from './types';
|
|
@@ -6,7 +6,8 @@ export declare class CognitoUserPoolsTokenProvider implements CognitoUserPoolTok
|
|
|
6
6
|
authTokenStore: DefaultTokenStore;
|
|
7
7
|
tokenOrchestrator: TokenOrchestrator;
|
|
8
8
|
constructor();
|
|
9
|
-
getTokens(
|
|
9
|
+
getTokens(options?: FetchAuthSessionOptions): Promise<AuthTokens | null>;
|
|
10
10
|
setKeyValueStorage(keyValueStorage: KeyValueStorageInterface): void;
|
|
11
|
+
setClientMetadataProvider(clientMetadataProvider: ClientMetadataProvider): void;
|
|
11
12
|
setAuthConfig(authConfig: AuthConfig): void;
|
|
12
13
|
}
|
|
@@ -13,12 +13,15 @@ class CognitoUserPoolsTokenProvider {
|
|
|
13
13
|
this.tokenOrchestrator.setAuthTokenStore(this.authTokenStore);
|
|
14
14
|
this.tokenOrchestrator.setTokenRefresher(refreshAuthTokens);
|
|
15
15
|
}
|
|
16
|
-
getTokens(
|
|
17
|
-
return this.tokenOrchestrator.getTokens(
|
|
16
|
+
getTokens(options = {}) {
|
|
17
|
+
return this.tokenOrchestrator.getTokens(options);
|
|
18
18
|
}
|
|
19
19
|
setKeyValueStorage(keyValueStorage) {
|
|
20
20
|
this.authTokenStore.setKeyValueStorage(keyValueStorage);
|
|
21
21
|
}
|
|
22
|
+
setClientMetadataProvider(clientMetadataProvider) {
|
|
23
|
+
this.tokenOrchestrator.setClientMetadataProvider(clientMetadataProvider);
|
|
24
|
+
}
|
|
22
25
|
setAuthConfig(authConfig) {
|
|
23
26
|
this.authTokenStore.setAuthConfig(authConfig);
|
|
24
27
|
this.tokenOrchestrator.setAuthConfig(authConfig);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CognitoUserPoolsTokenProvider.mjs","sources":["../../../../../src/providers/cognito/tokenProvider/CognitoUserPoolsTokenProvider.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { defaultStorage, } from '@aws-amplify/core';\nimport { refreshAuthTokens } from '../utils/refreshAuthTokens';\nimport { DefaultTokenStore } from './TokenStore';\nimport { TokenOrchestrator } from './TokenOrchestrator';\nexport class CognitoUserPoolsTokenProvider {\n constructor() {\n this.authTokenStore = new DefaultTokenStore();\n this.authTokenStore.setKeyValueStorage(defaultStorage);\n this.tokenOrchestrator = new TokenOrchestrator();\n this.tokenOrchestrator.setAuthTokenStore(this.authTokenStore);\n this.tokenOrchestrator.setTokenRefresher(refreshAuthTokens);\n }\n getTokens(
|
|
1
|
+
{"version":3,"file":"CognitoUserPoolsTokenProvider.mjs","sources":["../../../../../src/providers/cognito/tokenProvider/CognitoUserPoolsTokenProvider.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { defaultStorage, } from '@aws-amplify/core';\nimport { refreshAuthTokens } from '../utils/refreshAuthTokens';\nimport { DefaultTokenStore } from './TokenStore';\nimport { TokenOrchestrator } from './TokenOrchestrator';\nexport class CognitoUserPoolsTokenProvider {\n constructor() {\n this.authTokenStore = new DefaultTokenStore();\n this.authTokenStore.setKeyValueStorage(defaultStorage);\n this.tokenOrchestrator = new TokenOrchestrator();\n this.tokenOrchestrator.setAuthTokenStore(this.authTokenStore);\n this.tokenOrchestrator.setTokenRefresher(refreshAuthTokens);\n }\n getTokens(options = {}) {\n return this.tokenOrchestrator.getTokens(options);\n }\n setKeyValueStorage(keyValueStorage) {\n this.authTokenStore.setKeyValueStorage(keyValueStorage);\n }\n setClientMetadataProvider(clientMetadataProvider) {\n this.tokenOrchestrator.setClientMetadataProvider(clientMetadataProvider);\n }\n setAuthConfig(authConfig) {\n this.authTokenStore.setAuthConfig(authConfig);\n this.tokenOrchestrator.setAuthConfig(authConfig);\n }\n}\n"],"names":[],"mappings":";;;;;AAAA;AACA;AAKO,MAAM,6BAA6B,CAAC;AAC3C,IAAI,WAAW,GAAG;AAClB,QAAQ,IAAI,CAAC,cAAc,GAAG,IAAI,iBAAiB,EAAE;AACrD,QAAQ,IAAI,CAAC,cAAc,CAAC,kBAAkB,CAAC,cAAc,CAAC;AAC9D,QAAQ,IAAI,CAAC,iBAAiB,GAAG,IAAI,iBAAiB,EAAE;AACxD,QAAQ,IAAI,CAAC,iBAAiB,CAAC,iBAAiB,CAAC,IAAI,CAAC,cAAc,CAAC;AACrE,QAAQ,IAAI,CAAC,iBAAiB,CAAC,iBAAiB,CAAC,iBAAiB,CAAC;AACnE,IAAI;AACJ,IAAI,SAAS,CAAC,OAAO,GAAG,EAAE,EAAE;AAC5B,QAAQ,OAAO,IAAI,CAAC,iBAAiB,CAAC,SAAS,CAAC,OAAO,CAAC;AACxD,IAAI;AACJ,IAAI,kBAAkB,CAAC,eAAe,EAAE;AACxC,QAAQ,IAAI,CAAC,cAAc,CAAC,kBAAkB,CAAC,eAAe,CAAC;AAC/D,IAAI;AACJ,IAAI,yBAAyB,CAAC,sBAAsB,EAAE;AACtD,QAAQ,IAAI,CAAC,iBAAiB,CAAC,yBAAyB,CAAC,sBAAsB,CAAC;AAChF,IAAI;AACJ,IAAI,aAAa,CAAC,UAAU,EAAE;AAC9B,QAAQ,IAAI,CAAC,cAAc,CAAC,aAAa,CAAC,UAAU,CAAC;AACrD,QAAQ,IAAI,CAAC,iBAAiB,CAAC,aAAa,CAAC,UAAU,CAAC;AACxD,IAAI;AACJ;;;;"}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { AuthConfig, AuthTokens, FetchAuthSessionOptions } from '@aws-amplify/core';
|
|
1
|
+
import { AuthConfig, AuthTokens, ClientMetadataProvider, FetchAuthSessionOptions } from '@aws-amplify/core';
|
|
2
2
|
import { CognitoAuthSignInDetails } from '../types';
|
|
3
3
|
import { AuthTokenOrchestrator, AuthTokenStore, CognitoAuthTokens, DeviceMetadata, OAuthMetadata, TokenRefresher } from './types';
|
|
4
4
|
export declare class TokenOrchestrator implements AuthTokenOrchestrator {
|
|
5
5
|
private authConfig?;
|
|
6
|
+
clientMetadataProvider?: ClientMetadataProvider;
|
|
6
7
|
tokenStore?: AuthTokenStore;
|
|
7
8
|
tokenRefresher?: TokenRefresher;
|
|
8
9
|
inflightPromise: Promise<void> | undefined;
|
|
@@ -12,6 +13,7 @@ export declare class TokenOrchestrator implements AuthTokenOrchestrator {
|
|
|
12
13
|
setAuthTokenStore(tokenStore: AuthTokenStore): void;
|
|
13
14
|
getTokenStore(): AuthTokenStore;
|
|
14
15
|
getTokenRefresher(): TokenRefresher;
|
|
16
|
+
setClientMetadataProvider(clientMetadataProvider: ClientMetadataProvider): void;
|
|
15
17
|
getTokens(options?: FetchAuthSessionOptions): Promise<(AuthTokens & {
|
|
16
18
|
signInDetails?: CognitoAuthSignInDetails;
|
|
17
19
|
}) | null>;
|
|
@@ -57,6 +57,9 @@ class TokenOrchestrator {
|
|
|
57
57
|
}
|
|
58
58
|
return this.tokenRefresher;
|
|
59
59
|
}
|
|
60
|
+
setClientMetadataProvider(clientMetadataProvider) {
|
|
61
|
+
this.clientMetadataProvider = clientMetadataProvider;
|
|
62
|
+
}
|
|
60
63
|
async getTokens(options) {
|
|
61
64
|
let tokens;
|
|
62
65
|
try {
|
|
@@ -86,6 +89,7 @@ class TokenOrchestrator {
|
|
|
86
89
|
tokens = await this.refreshTokens({
|
|
87
90
|
tokens,
|
|
88
91
|
username,
|
|
92
|
+
clientMetadata: options?.clientMetadata ?? (await this.clientMetadataProvider?.()),
|
|
89
93
|
});
|
|
90
94
|
if (tokens === null) {
|
|
91
95
|
return null;
|
|
@@ -97,13 +101,14 @@ class TokenOrchestrator {
|
|
|
97
101
|
signInDetails: tokens?.signInDetails,
|
|
98
102
|
};
|
|
99
103
|
}
|
|
100
|
-
async refreshTokens({ tokens, username, }) {
|
|
104
|
+
async refreshTokens({ tokens, username, clientMetadata, }) {
|
|
101
105
|
try {
|
|
102
106
|
const { signInDetails } = tokens;
|
|
103
107
|
const newTokens = await this.getTokenRefresher()({
|
|
104
108
|
tokens,
|
|
105
109
|
authConfig: this.authConfig,
|
|
106
110
|
username,
|
|
111
|
+
clientMetadata,
|
|
107
112
|
});
|
|
108
113
|
newTokens.signInDetails = signInDetails;
|
|
109
114
|
await this.setTokens({ tokens: newTokens });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TokenOrchestrator.mjs","sources":["../../../../../src/providers/cognito/tokenProvider/TokenOrchestrator.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { Hub, } from '@aws-amplify/core';\nimport { AMPLIFY_SYMBOL, AmplifyErrorCode, assertTokenProviderConfig, isBrowser, isTokenExpired, } from '@aws-amplify/core/internals/utils';\nimport { assertServiceError } from '../../../errors/utils/assertServiceError';\nimport { AuthError } from '../../../errors/AuthError';\nimport { oAuthStore } from '../utils/oauth/oAuthStore';\nimport { addInflightPromise } from '../utils/oauth/inflightPromise';\nexport class TokenOrchestrator {\n constructor() {\n this.waitForInflightOAuth = isBrowser()\n ? async () => {\n if (!(await oAuthStore.loadOAuthInFlight())) {\n return;\n }\n if (this.inflightPromise) {\n return this.inflightPromise;\n }\n // when there is valid oauth config and there is an inflight oauth flow, try\n // to block async calls that require fetching tokens before the oauth flow completes\n // e.g. getCurrentUser, fetchAuthSession etc.\n this.inflightPromise = new Promise((resolve, _reject) => {\n addInflightPromise(resolve);\n });\n return this.inflightPromise;\n }\n : async () => {\n // no-op for non-browser environments\n };\n }\n setAuthConfig(authConfig) {\n oAuthStore.setAuthConfig(authConfig.Cognito);\n this.authConfig = authConfig;\n }\n setTokenRefresher(tokenRefresher) {\n this.tokenRefresher = tokenRefresher;\n }\n setAuthTokenStore(tokenStore) {\n this.tokenStore = tokenStore;\n }\n getTokenStore() {\n if (!this.tokenStore) {\n throw new AuthError({\n name: 'EmptyTokenStoreException',\n message: 'TokenStore not set',\n });\n }\n return this.tokenStore;\n }\n getTokenRefresher() {\n if (!this.tokenRefresher) {\n throw new AuthError({\n name: 'EmptyTokenRefresherException',\n message: 'TokenRefresher not set',\n });\n }\n return this.tokenRefresher;\n }\n async getTokens(options) {\n let tokens;\n try {\n assertTokenProviderConfig(this.authConfig?.Cognito);\n }\n catch (_err) {\n // Token provider not configured\n return null;\n }\n await this.waitForInflightOAuth();\n this.inflightPromise = undefined;\n tokens = await this.getTokenStore().loadTokens();\n const username = await this.getTokenStore().getLastAuthUser();\n if (tokens === null) {\n return null;\n }\n const idTokenExpired = !!tokens?.idToken &&\n isTokenExpired({\n expiresAt: (tokens.idToken?.payload?.exp ?? 0) * 1000,\n clockDrift: tokens.clockDrift ?? 0,\n });\n const accessTokenExpired = isTokenExpired({\n expiresAt: (tokens.accessToken?.payload?.exp ?? 0) * 1000,\n clockDrift: tokens.clockDrift ?? 0,\n });\n if (options?.forceRefresh || idTokenExpired || accessTokenExpired) {\n tokens = await this.refreshTokens({\n tokens,\n username,\n });\n if (tokens === null) {\n return null;\n }\n }\n return {\n accessToken: tokens?.accessToken,\n idToken: tokens?.idToken,\n signInDetails: tokens?.signInDetails,\n };\n }\n async refreshTokens({ tokens, username, }) {\n try {\n const { signInDetails } = tokens;\n const newTokens = await this.getTokenRefresher()({\n tokens,\n authConfig: this.authConfig,\n username,\n });\n newTokens.signInDetails = signInDetails;\n await this.setTokens({ tokens: newTokens });\n Hub.dispatch('auth', { event: 'tokenRefresh' }, 'Auth', AMPLIFY_SYMBOL);\n return newTokens;\n }\n catch (err) {\n return this.handleErrors(err);\n }\n }\n handleErrors(err) {\n assertServiceError(err);\n if (err.name !== AmplifyErrorCode.NetworkError) {\n // TODO(v6): Check errors on client\n this.clearTokens();\n }\n Hub.dispatch('auth', {\n event: 'tokenRefresh_failure',\n data: { error: err },\n }, 'Auth', AMPLIFY_SYMBOL);\n if (err.name.startsWith('NotAuthorizedException')) {\n return null;\n }\n throw err;\n }\n async setTokens({ tokens }) {\n return this.getTokenStore().storeTokens(tokens);\n }\n async clearTokens() {\n return this.getTokenStore().clearTokens();\n }\n getDeviceMetadata(username) {\n return this.getTokenStore().getDeviceMetadata(username);\n }\n clearDeviceMetadata(username) {\n return this.getTokenStore().clearDeviceMetadata(username);\n }\n setOAuthMetadata(metadata) {\n return this.getTokenStore().setOAuthMetadata(metadata);\n }\n getOAuthMetadata() {\n return this.getTokenStore().getOAuthMetadata();\n }\n}\n"],"names":[],"mappings":";;;;;;;AAAA;AACA;AAOO,MAAM,iBAAiB,CAAC;AAC/B,IAAI,WAAW,GAAG;AAClB,QAAQ,IAAI,CAAC,oBAAoB,GAAG,SAAS;AAC7C,cAAc,YAAY;AAC1B,gBAAgB,IAAI,EAAE,MAAM,UAAU,CAAC,iBAAiB,EAAE,CAAC,EAAE;AAC7D,oBAAoB;AACpB,gBAAgB;AAChB,gBAAgB,IAAI,IAAI,CAAC,eAAe,EAAE;AAC1C,oBAAoB,OAAO,IAAI,CAAC,eAAe;AAC/C,gBAAgB;AAChB;AACA;AACA;AACA,gBAAgB,IAAI,CAAC,eAAe,GAAG,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,OAAO,KAAK;AACzE,oBAAoB,kBAAkB,CAAC,OAAO,CAAC;AAC/C,gBAAgB,CAAC,CAAC;AAClB,gBAAgB,OAAO,IAAI,CAAC,eAAe;AAC3C,YAAY;AACZ,cAAc,YAAY;AAC1B;AACA,YAAY,CAAC;AACb,IAAI;AACJ,IAAI,aAAa,CAAC,UAAU,EAAE;AAC9B,QAAQ,UAAU,CAAC,aAAa,CAAC,UAAU,CAAC,OAAO,CAAC;AACpD,QAAQ,IAAI,CAAC,UAAU,GAAG,UAAU;AACpC,IAAI;AACJ,IAAI,iBAAiB,CAAC,cAAc,EAAE;AACtC,QAAQ,IAAI,CAAC,cAAc,GAAG,cAAc;AAC5C,IAAI;AACJ,IAAI,iBAAiB,CAAC,UAAU,EAAE;AAClC,QAAQ,IAAI,CAAC,UAAU,GA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E,CAAC,mBAAmB,CAAC,QAAQ,CAAC;AACjE,IAAI;AACJ,IAAI,gBAAgB,CAAC,QAAQ,EAAE;AAC/B,QAAQ,OAAO,IAAI,CAAC,aAAa,EAAE,CAAC,gBAAgB,CAAC,QAAQ,CAAC;AAC9D,IAAI;AACJ,IAAI,gBAAgB,GAAG;AACvB,QAAQ,OAAO,IAAI,CAAC,aAAa,EAAE,CAAC,gBAAgB,EAAE;AACtD,IAAI;AACJ;;;;"}
|
|
1
|
+
{"version":3,"file":"TokenOrchestrator.mjs","sources":["../../../../../src/providers/cognito/tokenProvider/TokenOrchestrator.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { Hub, } from '@aws-amplify/core';\nimport { AMPLIFY_SYMBOL, AmplifyErrorCode, assertTokenProviderConfig, isBrowser, isTokenExpired, } from '@aws-amplify/core/internals/utils';\nimport { assertServiceError } from '../../../errors/utils/assertServiceError';\nimport { AuthError } from '../../../errors/AuthError';\nimport { oAuthStore } from '../utils/oauth/oAuthStore';\nimport { addInflightPromise } from '../utils/oauth/inflightPromise';\nexport class TokenOrchestrator {\n constructor() {\n this.waitForInflightOAuth = isBrowser()\n ? async () => {\n if (!(await oAuthStore.loadOAuthInFlight())) {\n return;\n }\n if (this.inflightPromise) {\n return this.inflightPromise;\n }\n // when there is valid oauth config and there is an inflight oauth flow, try\n // to block async calls that require fetching tokens before the oauth flow completes\n // e.g. getCurrentUser, fetchAuthSession etc.\n this.inflightPromise = new Promise((resolve, _reject) => {\n addInflightPromise(resolve);\n });\n return this.inflightPromise;\n }\n : async () => {\n // no-op for non-browser environments\n };\n }\n setAuthConfig(authConfig) {\n oAuthStore.setAuthConfig(authConfig.Cognito);\n this.authConfig = authConfig;\n }\n setTokenRefresher(tokenRefresher) {\n this.tokenRefresher = tokenRefresher;\n }\n setAuthTokenStore(tokenStore) {\n this.tokenStore = tokenStore;\n }\n getTokenStore() {\n if (!this.tokenStore) {\n throw new AuthError({\n name: 'EmptyTokenStoreException',\n message: 'TokenStore not set',\n });\n }\n return this.tokenStore;\n }\n getTokenRefresher() {\n if (!this.tokenRefresher) {\n throw new AuthError({\n name: 'EmptyTokenRefresherException',\n message: 'TokenRefresher not set',\n });\n }\n return this.tokenRefresher;\n }\n setClientMetadataProvider(clientMetadataProvider) {\n this.clientMetadataProvider = clientMetadataProvider;\n }\n async getTokens(options) {\n let tokens;\n try {\n assertTokenProviderConfig(this.authConfig?.Cognito);\n }\n catch (_err) {\n // Token provider not configured\n return null;\n }\n await this.waitForInflightOAuth();\n this.inflightPromise = undefined;\n tokens = await this.getTokenStore().loadTokens();\n const username = await this.getTokenStore().getLastAuthUser();\n if (tokens === null) {\n return null;\n }\n const idTokenExpired = !!tokens?.idToken &&\n isTokenExpired({\n expiresAt: (tokens.idToken?.payload?.exp ?? 0) * 1000,\n clockDrift: tokens.clockDrift ?? 0,\n });\n const accessTokenExpired = isTokenExpired({\n expiresAt: (tokens.accessToken?.payload?.exp ?? 0) * 1000,\n clockDrift: tokens.clockDrift ?? 0,\n });\n if (options?.forceRefresh || idTokenExpired || accessTokenExpired) {\n tokens = await this.refreshTokens({\n tokens,\n username,\n clientMetadata: options?.clientMetadata ?? (await this.clientMetadataProvider?.()),\n });\n if (tokens === null) {\n return null;\n }\n }\n return {\n accessToken: tokens?.accessToken,\n idToken: tokens?.idToken,\n signInDetails: tokens?.signInDetails,\n };\n }\n async refreshTokens({ tokens, username, clientMetadata, }) {\n try {\n const { signInDetails } = tokens;\n const newTokens = await this.getTokenRefresher()({\n tokens,\n authConfig: this.authConfig,\n username,\n clientMetadata,\n });\n newTokens.signInDetails = signInDetails;\n await this.setTokens({ tokens: newTokens });\n Hub.dispatch('auth', { event: 'tokenRefresh' }, 'Auth', AMPLIFY_SYMBOL);\n return newTokens;\n }\n catch (err) {\n return this.handleErrors(err);\n }\n }\n handleErrors(err) {\n assertServiceError(err);\n if (err.name !== AmplifyErrorCode.NetworkError) {\n // TODO(v6): Check errors on client\n this.clearTokens();\n }\n Hub.dispatch('auth', {\n event: 'tokenRefresh_failure',\n data: { error: err },\n }, 'Auth', AMPLIFY_SYMBOL);\n if (err.name.startsWith('NotAuthorizedException')) {\n return null;\n }\n throw err;\n }\n async setTokens({ tokens }) {\n return this.getTokenStore().storeTokens(tokens);\n }\n async clearTokens() {\n return this.getTokenStore().clearTokens();\n }\n getDeviceMetadata(username) {\n return this.getTokenStore().getDeviceMetadata(username);\n }\n clearDeviceMetadata(username) {\n return this.getTokenStore().clearDeviceMetadata(username);\n }\n setOAuthMetadata(metadata) {\n return this.getTokenStore().setOAuthMetadata(metadata);\n }\n getOAuthMetadata() {\n return this.getTokenStore().getOAuthMetadata();\n }\n}\n"],"names":[],"mappings":";;;;;;;AAAA;AACA;AAOO,MAAM,iBAAiB,CAAC;AAC/B,IAAI,WAAW,GAAG;AAClB,QAAQ,IAAI,CAAC,oBAAoB,GAAG,SAAS;AAC7C,cAAc,YAAY;AAC1B,gBAAgB,IAAI,EAAE,MAAM,UAAU,CAAC,iBAAiB,EAAE,CAAC,EAAE;AAC7D,oBAAoB;AACpB,gBAAgB;AAChB,gBAAgB,IAAI,IAAI,CAAC,eAAe,EAAE;AAC1C,oBAAoB,OAAO,IAAI,CAAC,eAAe;AAC/C,gBAAgB;AAChB;AACA;AACA;AACA,gBAAgB,IAAI,CAAC,eAAe,GAAG,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,OAAO,KAAK;AACzE,oBAAoB,kBAAkB,CAAC,OAAO,CAAC;AAC/C,gBAAgB,CAAC,CAAC;AAClB,gBAAgB,OAAO,IAAI,CAAC,eAAe;AAC3C,YAAY;AACZ,cAAc,YAAY;AAC1B;AACA,YAAY,CAAC;AACb,IAAI;AACJ,IAAI,aAAa,CAAC,UAAU,EAAE;AAC9B,QAAQ,UAAU,CAAC,aAAa,CAAC,UAAU,CAAC,OAAO,CAAC;AACpD,QAAQ,IAAI,CAAC,UAAU,GAAG,UAAU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EAAE;AAChC,QAAQ,OAAO,IAAI,CAAC,aAAa,EAAE,CAAC,WAAW,CAAC,MAAM,CAAC;AACvD,IAAI;AACJ,IAAI,MAAM,WAAW,GAAG;AACxB,QAAQ,OAAO,IAAI,CAAC,aAAa,EAAE,CAAC,WAAW,EAAE;AACjD,IAAI;AACJ,IAAI,iBAAiB,CAAC,QAAQ,EAAE;AAChC,QAAQ,OAAO,IAAI,CAAC,aAAa,EAAE,CAAC,iBAAiB,CAAC,QAAQ,CAAC;AAC/D,IAAI;AACJ,IAAI,mBAAmB,CAAC,QAAQ,EAAE;AAClC,QAAQ,OAAO,IAAI,CAAC,aAAa,EAAE,CAAC,mBAAmB,CAAC,QAAQ,CAAC;AACjE,IAAI;AACJ,IAAI,gBAAgB,CAAC,QAAQ,EAAE;AAC/B,QAAQ,OAAO,IAAI,CAAC,aAAa,EAAE,CAAC,gBAAgB,CAAC,QAAQ,CAAC;AAC9D,IAAI;AACJ,IAAI,gBAAgB,GAAG;AACvB,QAAQ,OAAO,IAAI,CAAC,aAAa,EAAE,CAAC,gBAAgB,EAAE;AACtD,IAAI;AACJ;;;;"}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { AuthConfig, AuthTokens, FetchAuthSessionOptions, KeyValueStorageInterface, TokenProvider } from '@aws-amplify/core';
|
|
2
|
-
import { CognitoAuthSignInDetails } from '../types';
|
|
3
|
-
export type TokenRefresher = ({ tokens, authConfig, username, }: {
|
|
1
|
+
import { AuthConfig, AuthTokens, ClientMetadataProvider, FetchAuthSessionOptions, KeyValueStorageInterface, TokenProvider } from '@aws-amplify/core';
|
|
2
|
+
import { ClientMetadata, CognitoAuthSignInDetails } from '../types';
|
|
3
|
+
export type TokenRefresher = ({ tokens, authConfig, username, clientMetadata, }: {
|
|
4
4
|
tokens: CognitoAuthTokens;
|
|
5
5
|
authConfig?: AuthConfig;
|
|
6
6
|
username: string;
|
|
7
|
+
clientMetadata?: ClientMetadata;
|
|
7
8
|
}) => Promise<CognitoAuthTokens>;
|
|
8
9
|
export type AuthKeys<AuthKey extends string> = Record<AuthKey, string>;
|
|
9
10
|
export declare const AuthTokenStorageKeys: {
|
|
@@ -47,6 +48,7 @@ export interface AuthTokenOrchestrator {
|
|
|
47
48
|
export interface CognitoUserPoolTokenProviderType extends TokenProvider {
|
|
48
49
|
setKeyValueStorage(keyValueStorage: KeyValueStorageInterface): void;
|
|
49
50
|
setAuthConfig(authConfig: AuthConfig): void;
|
|
51
|
+
setClientMetadataProvider(clientMetadataProvider: ClientMetadataProvider): void;
|
|
50
52
|
}
|
|
51
53
|
export type CognitoAuthTokens = AuthTokens & {
|
|
52
54
|
refreshToken?: string;
|
|
@@ -12,7 +12,7 @@ export declare const cognitoHostedUIIdentityProviderMap: Record<AuthProvider, st
|
|
|
12
12
|
/**
|
|
13
13
|
* Arbitrary key/value pairs that may be passed as part of certain Cognito requests
|
|
14
14
|
*/
|
|
15
|
-
export type ClientMetadata
|
|
15
|
+
export type { ClientMetadata } from '@aws-amplify/core';
|
|
16
16
|
/**
|
|
17
17
|
* Allowed values for preferredChallenge
|
|
18
18
|
*/
|
|
@@ -70,4 +70,3 @@ export interface AuthUser extends AWSAuthUser {
|
|
|
70
70
|
* Holds data describing the dispatch of a confirmation code.
|
|
71
71
|
*/
|
|
72
72
|
export type CodeDeliveryDetails<CognitoUserAttributeKey extends UserAttributeKey = UserAttributeKey> = AuthCodeDeliveryDetails<CognitoUserAttributeKey>;
|
|
73
|
-
export {};
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { AuthConfig } from '@aws-amplify/core';
|
|
2
2
|
import { CognitoAuthTokens, TokenRefresher } from '../tokenProvider/types';
|
|
3
|
+
import { ClientMetadata } from '../types';
|
|
3
4
|
export declare const refreshAuthTokens: (args_0: {
|
|
4
5
|
tokens: CognitoAuthTokens;
|
|
5
6
|
authConfig?: AuthConfig;
|
|
6
7
|
username: string;
|
|
8
|
+
clientMetadata?: ClientMetadata;
|
|
7
9
|
}) => Promise<CognitoAuthTokens>;
|
|
8
10
|
export declare const refreshAuthTokensWithoutDedupe: TokenRefresher;
|
|
@@ -15,7 +15,7 @@ import '../types/errors.mjs';
|
|
|
15
15
|
|
|
16
16
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
17
17
|
// SPDX-License-Identifier: Apache-2.0
|
|
18
|
-
const refreshAuthTokensFunction = async ({ tokens, authConfig, username, }) => {
|
|
18
|
+
const refreshAuthTokensFunction = async ({ tokens, authConfig, username, clientMetadata, }) => {
|
|
19
19
|
assertTokenProviderConfig(authConfig?.Cognito);
|
|
20
20
|
const { userPoolId, userPoolClientId, userPoolEndpoint } = authConfig.Cognito;
|
|
21
21
|
const region = getRegionFromUserPoolId(userPoolId);
|
|
@@ -29,6 +29,7 @@ const refreshAuthTokensFunction = async ({ tokens, authConfig, username, }) => {
|
|
|
29
29
|
ClientId: userPoolClientId,
|
|
30
30
|
RefreshToken: tokens.refreshToken,
|
|
31
31
|
DeviceKey: tokens.deviceMetadata?.deviceKey,
|
|
32
|
+
ClientMetadata: clientMetadata,
|
|
32
33
|
});
|
|
33
34
|
const accessToken = decodeJWT(AuthenticationResult?.AccessToken ?? '');
|
|
34
35
|
const idToken = AuthenticationResult?.IdToken
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"refreshAuthTokens.mjs","sources":["../../../../../src/providers/cognito/utils/refreshAuthTokens.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { assertTokenProviderConfig, deDupeAsyncFunction, decodeJWT, } from '@aws-amplify/core/internals/utils';\nimport { getRegionFromUserPoolId } from '../../../foundation/parsers';\nimport { assertAuthTokensWithRefreshToken } from '../utils/types';\nimport { AuthError } from '../../../errors/AuthError';\nimport { createCognitoUserPoolEndpointResolver } from '../factories';\nimport { createGetTokensFromRefreshTokenClient } from '../../../foundation/factories/serviceClients/cognitoIdentityProvider';\nconst refreshAuthTokensFunction = async ({ tokens, authConfig, username, }) => {\n assertTokenProviderConfig(authConfig?.Cognito);\n const { userPoolId, userPoolClientId, userPoolEndpoint } = authConfig.Cognito;\n const region = getRegionFromUserPoolId(userPoolId);\n assertAuthTokensWithRefreshToken(tokens);\n const getTokensFromRefreshToken = createGetTokensFromRefreshTokenClient({\n endpointResolver: createCognitoUserPoolEndpointResolver({\n endpointOverride: userPoolEndpoint,\n }),\n });\n const { AuthenticationResult } = await getTokensFromRefreshToken({ region }, {\n ClientId: userPoolClientId,\n RefreshToken: tokens.refreshToken,\n DeviceKey: tokens.deviceMetadata?.deviceKey,\n });\n const accessToken = decodeJWT(AuthenticationResult?.AccessToken ?? '');\n const idToken = AuthenticationResult?.IdToken\n ? decodeJWT(AuthenticationResult.IdToken)\n : undefined;\n const { iat } = accessToken.payload;\n // This should never happen. If it does, it's a bug from the service.\n if (!iat) {\n throw new AuthError({\n name: 'iatNotFoundException',\n message: 'iat not found in access token',\n });\n }\n const clockDrift = iat * 1000 - new Date().getTime();\n return {\n accessToken,\n idToken,\n clockDrift,\n refreshToken: AuthenticationResult?.RefreshToken ?? tokens.refreshToken,\n username,\n };\n};\nexport const refreshAuthTokens = deDupeAsyncFunction(refreshAuthTokensFunction);\nexport const refreshAuthTokensWithoutDedupe = refreshAuthTokensFunction;\n"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA;AACA;AAOA,MAAM,yBAAyB,GAAG,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,QAAQ,GAAG,KAAK;AAC/
|
|
1
|
+
{"version":3,"file":"refreshAuthTokens.mjs","sources":["../../../../../src/providers/cognito/utils/refreshAuthTokens.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { assertTokenProviderConfig, deDupeAsyncFunction, decodeJWT, } from '@aws-amplify/core/internals/utils';\nimport { getRegionFromUserPoolId } from '../../../foundation/parsers';\nimport { assertAuthTokensWithRefreshToken } from '../utils/types';\nimport { AuthError } from '../../../errors/AuthError';\nimport { createCognitoUserPoolEndpointResolver } from '../factories';\nimport { createGetTokensFromRefreshTokenClient } from '../../../foundation/factories/serviceClients/cognitoIdentityProvider';\nconst refreshAuthTokensFunction = async ({ tokens, authConfig, username, clientMetadata, }) => {\n assertTokenProviderConfig(authConfig?.Cognito);\n const { userPoolId, userPoolClientId, userPoolEndpoint } = authConfig.Cognito;\n const region = getRegionFromUserPoolId(userPoolId);\n assertAuthTokensWithRefreshToken(tokens);\n const getTokensFromRefreshToken = createGetTokensFromRefreshTokenClient({\n endpointResolver: createCognitoUserPoolEndpointResolver({\n endpointOverride: userPoolEndpoint,\n }),\n });\n const { AuthenticationResult } = await getTokensFromRefreshToken({ region }, {\n ClientId: userPoolClientId,\n RefreshToken: tokens.refreshToken,\n DeviceKey: tokens.deviceMetadata?.deviceKey,\n ClientMetadata: clientMetadata,\n });\n const accessToken = decodeJWT(AuthenticationResult?.AccessToken ?? '');\n const idToken = AuthenticationResult?.IdToken\n ? decodeJWT(AuthenticationResult.IdToken)\n : undefined;\n const { iat } = accessToken.payload;\n // This should never happen. If it does, it's a bug from the service.\n if (!iat) {\n throw new AuthError({\n name: 'iatNotFoundException',\n message: 'iat not found in access token',\n });\n }\n const clockDrift = iat * 1000 - new Date().getTime();\n return {\n accessToken,\n idToken,\n clockDrift,\n refreshToken: AuthenticationResult?.RefreshToken ?? tokens.refreshToken,\n username,\n };\n};\nexport const refreshAuthTokens = deDupeAsyncFunction(refreshAuthTokensFunction);\nexport const refreshAuthTokensWithoutDedupe = refreshAuthTokensFunction;\n"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA;AACA;AAOA,MAAM,yBAAyB,GAAG,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,cAAc,GAAG,KAAK;AAC/F,IAAI,yBAAyB,CAAC,UAAU,EAAE,OAAO,CAAC;AAClD,IAAI,MAAM,EAAE,UAAU,EAAE,gBAAgB,EAAE,gBA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QAAQ;AAChB,KAAK;AACL,CAAC;AACW,MAAC,iBAAiB,GAAG,mBAAmB,CAAC,yBAAyB;AAClE,MAAC,8BAA8B,GAAG;;;;"}
|
|
@@ -47,6 +47,10 @@ export type AuthPrompt = 'NONE' | 'LOGIN' | 'CONSENT' | 'SELECT_ACCOUNT';
|
|
|
47
47
|
export interface AuthSignInWithRedirectInput {
|
|
48
48
|
provider?: AuthProvider | {
|
|
49
49
|
custom: string;
|
|
50
|
+
idpIdentifier?: never;
|
|
51
|
+
} | {
|
|
52
|
+
idpIdentifier: string;
|
|
53
|
+
custom?: never;
|
|
50
54
|
};
|
|
51
55
|
customState?: string;
|
|
52
56
|
options?: {
|
package/package.json
CHANGED
|
@@ -1,113 +1,113 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
2
|
+
"name": "@aws-amplify/auth",
|
|
3
|
+
"version": "6.16.1-unstable.5bf5685.0+5bf5685",
|
|
4
|
+
"description": "Auth category of aws-amplify",
|
|
5
|
+
"main": "./dist/cjs/index.js",
|
|
6
|
+
"module": "./dist/esm/index.mjs",
|
|
7
|
+
"typings": "./dist/esm/index.d.ts",
|
|
8
|
+
"react-native": "./dist/cjs/index.js",
|
|
9
|
+
"sideEffects": [
|
|
10
|
+
"./dist/cjs/providers/cognito/apis/signInWithRedirect.js",
|
|
11
|
+
"./dist/esm/providers/cognito/apis/signInWithRedirect.mjs",
|
|
12
|
+
"./dist/cjs/providers/cognito/utils/oauth/enableOAuthListener.js",
|
|
13
|
+
"./dist/esm/providers/cognito/utils/oauth/enableOAuthListener.mjs"
|
|
14
|
+
],
|
|
15
|
+
"publishConfig": {
|
|
16
|
+
"access": "public"
|
|
17
|
+
},
|
|
18
|
+
"scripts": {
|
|
19
|
+
"test": "yarn lint --fix && jest -w 1 --coverage --logHeapUsage",
|
|
20
|
+
"build-with-test": "npm test && npm run build",
|
|
21
|
+
"build:umd": "webpack && webpack --config ./webpack.config.dev.js",
|
|
22
|
+
"build:esm-cjs": "rollup --forceExit -c rollup.config.mjs",
|
|
23
|
+
"build:watch": "npm run build:esm-cjs -- --watch",
|
|
24
|
+
"build": "npm run clean && npm run build:esm-cjs && npm run build:umd",
|
|
25
|
+
"clean": "npm run clean:size && rimraf lib-esm lib dist",
|
|
26
|
+
"clean:size": "rimraf dual-publish-tmp tmp*",
|
|
27
|
+
"format": "echo \"Not implemented\"",
|
|
28
|
+
"lint": "eslint '**/*.{ts,tsx}' && npm run ts-coverage",
|
|
29
|
+
"lint:fix": "eslint '**/*.{ts,tsx}' --fix",
|
|
30
|
+
"ts-coverage": "typescript-coverage-report -p ./tsconfig.build.json -t 91.18"
|
|
31
|
+
},
|
|
32
|
+
"typesVersions": {
|
|
33
|
+
">=4.2": {
|
|
34
|
+
"cognito": [
|
|
35
|
+
"./dist/esm/providers/cognito/index.d.ts"
|
|
36
|
+
],
|
|
37
|
+
"cognito/server": [
|
|
38
|
+
"./dist/esm/providers/cognito/apis/server/index.d.ts"
|
|
39
|
+
],
|
|
40
|
+
"server": [
|
|
41
|
+
"./dist/esm/server.d.ts"
|
|
42
|
+
]
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
"exports": {
|
|
46
|
+
".": {
|
|
47
|
+
"react-native": "./dist/cjs/index.js",
|
|
48
|
+
"types": "./dist/esm/index.d.ts",
|
|
49
|
+
"import": "./dist/esm/index.mjs",
|
|
50
|
+
"require": "./dist/cjs/index.js"
|
|
51
|
+
},
|
|
52
|
+
"./cognito": {
|
|
53
|
+
"react-native": "./dist/cjs/providers/cognito/index.js",
|
|
54
|
+
"types": "./dist/esm/providers/cognito/index.d.ts",
|
|
55
|
+
"import": "./dist/esm/providers/cognito/index.mjs",
|
|
56
|
+
"require": "./dist/cjs/providers/cognito/index.js"
|
|
57
|
+
},
|
|
58
|
+
"./cognito/server": {
|
|
59
|
+
"types": "./dist/esm/providers/cognito/apis/server/index.d.ts",
|
|
60
|
+
"import": "./dist/esm/providers/cognito/apis/server/index.mjs",
|
|
61
|
+
"require": "./dist/cjs/providers/cognito/apis/server/index.js"
|
|
62
|
+
},
|
|
63
|
+
"./server": {
|
|
64
|
+
"types": "./dist/esm/server.d.ts",
|
|
65
|
+
"import": "./dist/esm/server.mjs",
|
|
66
|
+
"require": "./dist/cjs/server.js"
|
|
67
|
+
},
|
|
68
|
+
"./enable-oauth-listener": {
|
|
69
|
+
"types": "./dist/esm/providers/cognito/utils/oauth/enableOAuthListener.d.ts",
|
|
70
|
+
"import": "./dist/esm/providers/cognito/utils/oauth/enableOAuthListener.mjs",
|
|
71
|
+
"require": "./dist/cjs/providers/cognito/utils/oauth/enableOAuthListener.js"
|
|
72
|
+
},
|
|
73
|
+
"./package.json": "./package.json"
|
|
74
|
+
},
|
|
75
|
+
"repository": {
|
|
76
|
+
"type": "git",
|
|
77
|
+
"url": "https://github.com/aws-amplify/amplify-js.git"
|
|
78
|
+
},
|
|
79
|
+
"author": "Amazon Web Services",
|
|
80
|
+
"license": "Apache-2.0",
|
|
81
|
+
"bugs": {
|
|
82
|
+
"url": "https://github.com/aws/aws-amplify/issues"
|
|
83
|
+
},
|
|
84
|
+
"homepage": "https://aws-amplify.github.io/",
|
|
85
|
+
"files": [
|
|
86
|
+
"dist/cjs",
|
|
87
|
+
"dist/esm",
|
|
88
|
+
"src",
|
|
89
|
+
"cognito",
|
|
90
|
+
"server",
|
|
91
|
+
"enable-oauth-listener"
|
|
92
|
+
],
|
|
93
|
+
"dependencies": {
|
|
94
|
+
"@aws-crypto/sha256-js": "5.2.0",
|
|
95
|
+
"@smithy/types": "^3.3.0",
|
|
96
|
+
"tslib": "^2.5.0"
|
|
97
|
+
},
|
|
98
|
+
"peerDependencies": {
|
|
99
|
+
"@aws-amplify/core": "6.13.4-unstable.5bf5685.0+5bf5685",
|
|
100
|
+
"@aws-amplify/react-native": "^1.1.10"
|
|
101
|
+
},
|
|
102
|
+
"peerDependenciesMeta": {
|
|
103
|
+
"@aws-amplify/react-native": {
|
|
104
|
+
"optional": true
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
|
+
"devDependencies": {
|
|
108
|
+
"@aws-amplify/core": "6.13.4-unstable.5bf5685.0+5bf5685",
|
|
109
|
+
"@aws-amplify/react-native": "1.2.1-unstable.5bf5685.0+5bf5685",
|
|
110
|
+
"@jest/test-sequencer": "^29.7.0"
|
|
111
|
+
},
|
|
112
|
+
"gitHead": "5bf5685e1876bbb16550678bda9cfa3953831685"
|
|
113
113
|
}
|
|
@@ -51,17 +51,21 @@ export async function signInWithRedirect(
|
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
let provider = 'COGNITO'; // Default
|
|
54
|
+
let idpIdentifier: string | undefined;
|
|
54
55
|
|
|
55
56
|
if (typeof input?.provider === 'string') {
|
|
56
57
|
provider = cognitoHostedUIIdentityProviderMap[input.provider];
|
|
57
58
|
} else if (input?.provider?.custom) {
|
|
58
59
|
provider = input.provider.custom;
|
|
60
|
+
} else if (input?.provider?.idpIdentifier) {
|
|
61
|
+
({ idpIdentifier } = input.provider);
|
|
59
62
|
}
|
|
60
63
|
|
|
61
64
|
return oauthSignIn({
|
|
62
65
|
oauthConfig: authConfig.loginWith.oauth,
|
|
63
66
|
clientId: authConfig.userPoolClientId,
|
|
64
67
|
provider,
|
|
68
|
+
idpIdentifier,
|
|
65
69
|
customState: input?.customState,
|
|
66
70
|
preferPrivateSession: input?.options?.preferPrivateSession,
|
|
67
71
|
options: {
|
|
@@ -77,6 +81,7 @@ export async function signInWithRedirect(
|
|
|
77
81
|
const oauthSignIn = async ({
|
|
78
82
|
oauthConfig,
|
|
79
83
|
provider,
|
|
84
|
+
idpIdentifier,
|
|
80
85
|
clientId,
|
|
81
86
|
customState,
|
|
82
87
|
preferPrivateSession,
|
|
@@ -85,6 +90,7 @@ const oauthSignIn = async ({
|
|
|
85
90
|
}: {
|
|
86
91
|
oauthConfig: OAuthConfig;
|
|
87
92
|
provider: string;
|
|
93
|
+
idpIdentifier?: string;
|
|
88
94
|
clientId: string;
|
|
89
95
|
customState?: string;
|
|
90
96
|
preferPrivateSession?: boolean;
|
|
@@ -117,10 +123,17 @@ const oauthSignIn = async ({
|
|
|
117
123
|
['redirect_uri', redirectUri],
|
|
118
124
|
['response_type', responseType],
|
|
119
125
|
['client_id', clientId],
|
|
120
|
-
['identity_provider', provider],
|
|
121
|
-
['scope', scopes.join(' ')],
|
|
122
126
|
]);
|
|
123
127
|
|
|
128
|
+
// Add either identity_provider or idp_identifier, but not both
|
|
129
|
+
if (idpIdentifier) {
|
|
130
|
+
params.append('idp_identifier', idpIdentifier);
|
|
131
|
+
} else {
|
|
132
|
+
params.append('identity_provider', provider);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
params.append('scope', scopes.join(' '));
|
|
136
|
+
|
|
124
137
|
loginHint && params.append('login_hint', loginHint);
|
|
125
138
|
lang && params.append('lang', lang);
|
|
126
139
|
nonce && params.append('nonce', nonce);
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
import {
|
|
5
5
|
AuthConfig,
|
|
6
6
|
AuthTokens,
|
|
7
|
+
ClientMetadataProvider,
|
|
7
8
|
FetchAuthSessionOptions,
|
|
8
9
|
KeyValueStorageInterface,
|
|
9
10
|
defaultStorage,
|
|
@@ -28,16 +29,20 @@ export class CognitoUserPoolsTokenProvider
|
|
|
28
29
|
this.tokenOrchestrator.setTokenRefresher(refreshAuthTokens);
|
|
29
30
|
}
|
|
30
31
|
|
|
31
|
-
getTokens(
|
|
32
|
-
|
|
33
|
-
): Promise<AuthTokens | null> {
|
|
34
|
-
return this.tokenOrchestrator.getTokens({ forceRefresh });
|
|
32
|
+
getTokens(options: FetchAuthSessionOptions = {}): Promise<AuthTokens | null> {
|
|
33
|
+
return this.tokenOrchestrator.getTokens(options);
|
|
35
34
|
}
|
|
36
35
|
|
|
37
36
|
setKeyValueStorage(keyValueStorage: KeyValueStorageInterface): void {
|
|
38
37
|
this.authTokenStore.setKeyValueStorage(keyValueStorage);
|
|
39
38
|
}
|
|
40
39
|
|
|
40
|
+
setClientMetadataProvider(
|
|
41
|
+
clientMetadataProvider: ClientMetadataProvider,
|
|
42
|
+
): void {
|
|
43
|
+
this.tokenOrchestrator.setClientMetadataProvider(clientMetadataProvider);
|
|
44
|
+
}
|
|
45
|
+
|
|
41
46
|
setAuthConfig(authConfig: AuthConfig) {
|
|
42
47
|
this.authTokenStore.setAuthConfig(authConfig);
|
|
43
48
|
this.tokenOrchestrator.setAuthConfig(authConfig);
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
import {
|
|
4
4
|
AuthConfig,
|
|
5
5
|
AuthTokens,
|
|
6
|
+
ClientMetadataProvider,
|
|
6
7
|
CognitoUserPoolConfig,
|
|
7
8
|
FetchAuthSessionOptions,
|
|
8
9
|
Hub,
|
|
@@ -19,7 +20,7 @@ import { assertServiceError } from '../../../errors/utils/assertServiceError';
|
|
|
19
20
|
import { AuthError } from '../../../errors/AuthError';
|
|
20
21
|
import { oAuthStore } from '../utils/oauth/oAuthStore';
|
|
21
22
|
import { addInflightPromise } from '../utils/oauth/inflightPromise';
|
|
22
|
-
import { CognitoAuthSignInDetails } from '../types';
|
|
23
|
+
import { ClientMetadata, CognitoAuthSignInDetails } from '../types';
|
|
23
24
|
|
|
24
25
|
import {
|
|
25
26
|
AuthTokenOrchestrator,
|
|
@@ -32,6 +33,7 @@ import {
|
|
|
32
33
|
|
|
33
34
|
export class TokenOrchestrator implements AuthTokenOrchestrator {
|
|
34
35
|
private authConfig?: AuthConfig;
|
|
36
|
+
clientMetadataProvider?: ClientMetadataProvider;
|
|
35
37
|
tokenStore?: AuthTokenStore;
|
|
36
38
|
tokenRefresher?: TokenRefresher;
|
|
37
39
|
inflightPromise: Promise<void> | undefined;
|
|
@@ -94,6 +96,12 @@ export class TokenOrchestrator implements AuthTokenOrchestrator {
|
|
|
94
96
|
return this.tokenRefresher;
|
|
95
97
|
}
|
|
96
98
|
|
|
99
|
+
setClientMetadataProvider(
|
|
100
|
+
clientMetadataProvider: ClientMetadataProvider,
|
|
101
|
+
): void {
|
|
102
|
+
this.clientMetadataProvider = clientMetadataProvider;
|
|
103
|
+
}
|
|
104
|
+
|
|
97
105
|
async getTokens(
|
|
98
106
|
options?: FetchAuthSessionOptions,
|
|
99
107
|
): Promise<
|
|
@@ -130,6 +138,8 @@ export class TokenOrchestrator implements AuthTokenOrchestrator {
|
|
|
130
138
|
tokens = await this.refreshTokens({
|
|
131
139
|
tokens,
|
|
132
140
|
username,
|
|
141
|
+
clientMetadata:
|
|
142
|
+
options?.clientMetadata ?? (await this.clientMetadataProvider?.()),
|
|
133
143
|
});
|
|
134
144
|
|
|
135
145
|
if (tokens === null) {
|
|
@@ -147,9 +157,11 @@ export class TokenOrchestrator implements AuthTokenOrchestrator {
|
|
|
147
157
|
private async refreshTokens({
|
|
148
158
|
tokens,
|
|
149
159
|
username,
|
|
160
|
+
clientMetadata,
|
|
150
161
|
}: {
|
|
151
162
|
tokens: CognitoAuthTokens;
|
|
152
163
|
username: string;
|
|
164
|
+
clientMetadata?: ClientMetadata;
|
|
153
165
|
}): Promise<CognitoAuthTokens | null> {
|
|
154
166
|
try {
|
|
155
167
|
const { signInDetails } = tokens;
|
|
@@ -157,6 +169,7 @@ export class TokenOrchestrator implements AuthTokenOrchestrator {
|
|
|
157
169
|
tokens,
|
|
158
170
|
authConfig: this.authConfig,
|
|
159
171
|
username,
|
|
172
|
+
clientMetadata,
|
|
160
173
|
});
|
|
161
174
|
newTokens.signInDetails = signInDetails;
|
|
162
175
|
await this.setTokens({ tokens: newTokens });
|
|
@@ -3,21 +3,24 @@
|
|
|
3
3
|
import {
|
|
4
4
|
AuthConfig,
|
|
5
5
|
AuthTokens,
|
|
6
|
+
ClientMetadataProvider,
|
|
6
7
|
FetchAuthSessionOptions,
|
|
7
8
|
KeyValueStorageInterface,
|
|
8
9
|
TokenProvider,
|
|
9
10
|
} from '@aws-amplify/core';
|
|
10
11
|
|
|
11
|
-
import { CognitoAuthSignInDetails } from '../types';
|
|
12
|
+
import { ClientMetadata, CognitoAuthSignInDetails } from '../types';
|
|
12
13
|
|
|
13
14
|
export type TokenRefresher = ({
|
|
14
15
|
tokens,
|
|
15
16
|
authConfig,
|
|
16
17
|
username,
|
|
18
|
+
clientMetadata,
|
|
17
19
|
}: {
|
|
18
20
|
tokens: CognitoAuthTokens;
|
|
19
21
|
authConfig?: AuthConfig;
|
|
20
22
|
username: string;
|
|
23
|
+
clientMetadata?: ClientMetadata;
|
|
21
24
|
}) => Promise<CognitoAuthTokens>;
|
|
22
25
|
|
|
23
26
|
export type AuthKeys<AuthKey extends string> = Record<AuthKey, string>;
|
|
@@ -66,6 +69,9 @@ export interface AuthTokenOrchestrator {
|
|
|
66
69
|
export interface CognitoUserPoolTokenProviderType extends TokenProvider {
|
|
67
70
|
setKeyValueStorage(keyValueStorage: KeyValueStorageInterface): void;
|
|
68
71
|
setAuthConfig(authConfig: AuthConfig): void;
|
|
72
|
+
setClientMetadataProvider(
|
|
73
|
+
clientMetadataProvider: ClientMetadataProvider,
|
|
74
|
+
): void;
|
|
69
75
|
}
|
|
70
76
|
|
|
71
77
|
export type CognitoAuthTokens = AuthTokens & {
|
|
@@ -38,7 +38,7 @@ export const cognitoHostedUIIdentityProviderMap: Record<AuthProvider, string> =
|
|
|
38
38
|
/**
|
|
39
39
|
* Arbitrary key/value pairs that may be passed as part of certain Cognito requests
|
|
40
40
|
*/
|
|
41
|
-
export type ClientMetadata
|
|
41
|
+
export type { ClientMetadata } from '@aws-amplify/core';
|
|
42
42
|
|
|
43
43
|
/**
|
|
44
44
|
* Allowed values for preferredChallenge
|
|
@@ -14,15 +14,18 @@ import { assertAuthTokensWithRefreshToken } from '../utils/types';
|
|
|
14
14
|
import { AuthError } from '../../../errors/AuthError';
|
|
15
15
|
import { createCognitoUserPoolEndpointResolver } from '../factories';
|
|
16
16
|
import { createGetTokensFromRefreshTokenClient } from '../../../foundation/factories/serviceClients/cognitoIdentityProvider';
|
|
17
|
+
import { ClientMetadata } from '../types';
|
|
17
18
|
|
|
18
19
|
const refreshAuthTokensFunction: TokenRefresher = async ({
|
|
19
20
|
tokens,
|
|
20
21
|
authConfig,
|
|
21
22
|
username,
|
|
23
|
+
clientMetadata,
|
|
22
24
|
}: {
|
|
23
25
|
tokens: CognitoAuthTokens;
|
|
24
26
|
authConfig?: AuthConfig;
|
|
25
27
|
username: string;
|
|
28
|
+
clientMetadata?: ClientMetadata;
|
|
26
29
|
}): Promise<CognitoAuthTokens> => {
|
|
27
30
|
assertTokenProviderConfig(authConfig?.Cognito);
|
|
28
31
|
const { userPoolId, userPoolClientId, userPoolEndpoint } = authConfig.Cognito;
|
|
@@ -41,6 +44,7 @@ const refreshAuthTokensFunction: TokenRefresher = async ({
|
|
|
41
44
|
ClientId: userPoolClientId,
|
|
42
45
|
RefreshToken: tokens.refreshToken,
|
|
43
46
|
DeviceKey: tokens.deviceMetadata?.deviceKey,
|
|
47
|
+
ClientMetadata: clientMetadata,
|
|
44
48
|
},
|
|
45
49
|
);
|
|
46
50
|
|
package/src/types/inputs.ts
CHANGED
|
@@ -69,7 +69,10 @@ export type AuthProvider = 'Amazon' | 'Apple' | 'Facebook' | 'Google';
|
|
|
69
69
|
export type AuthPrompt = 'NONE' | 'LOGIN' | 'CONSENT' | 'SELECT_ACCOUNT';
|
|
70
70
|
|
|
71
71
|
export interface AuthSignInWithRedirectInput {
|
|
72
|
-
provider?:
|
|
72
|
+
provider?:
|
|
73
|
+
| AuthProvider
|
|
74
|
+
| { custom: string; idpIdentifier?: never }
|
|
75
|
+
| { idpIdentifier: string; custom?: never };
|
|
73
76
|
customState?: string;
|
|
74
77
|
options?: {
|
|
75
78
|
/**
|