@aws-amplify/auth 6.9.2-unstable.eac02d0.0 → 6.10.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 +11 -1
- package/dist/cjs/providers/cognito/apis/signInWithRedirect.js.map +1 -1
- package/dist/esm/providers/cognito/apis/signInWithRedirect.mjs +11 -1
- package/dist/esm/providers/cognito/apis/signInWithRedirect.mjs.map +1 -1
- package/dist/esm/types/inputs.d.ts +15 -0
- package/package.json +106 -104
- package/src/providers/cognito/apis/signInWithRedirect.ts +12 -0
- package/src/types/inputs.ts +27 -0
|
@@ -40,11 +40,17 @@ async function signInWithRedirect(input) {
|
|
|
40
40
|
provider,
|
|
41
41
|
customState: input?.customState,
|
|
42
42
|
preferPrivateSession: input?.options?.preferPrivateSession,
|
|
43
|
+
options: {
|
|
44
|
+
loginHint: input?.options?.loginHint,
|
|
45
|
+
lang: input?.options?.lang,
|
|
46
|
+
nonce: input?.options?.nonce,
|
|
47
|
+
},
|
|
43
48
|
});
|
|
44
49
|
}
|
|
45
50
|
exports.signInWithRedirect = signInWithRedirect;
|
|
46
|
-
const oauthSignIn = async ({ oauthConfig, provider, clientId, customState, preferPrivateSession, }) => {
|
|
51
|
+
const oauthSignIn = async ({ oauthConfig, provider, clientId, customState, preferPrivateSession, options, }) => {
|
|
47
52
|
const { domain, redirectSignIn, responseType, scopes } = oauthConfig;
|
|
53
|
+
const { loginHint, lang, nonce } = options ?? {};
|
|
48
54
|
const randomState = (0, oauth_1.generateState)();
|
|
49
55
|
/* encodeURIComponent is not URL safe, use urlSafeEncode instead. Cognito
|
|
50
56
|
single-encodes/decodes url on first sign in and double-encodes/decodes url
|
|
@@ -67,6 +73,10 @@ const oauthSignIn = async ({ oauthConfig, provider, clientId, customState, prefe
|
|
|
67
73
|
client_id: clientId,
|
|
68
74
|
identity_provider: provider,
|
|
69
75
|
scope: scopes.join(' '),
|
|
76
|
+
// eslint-disable-next-line camelcase
|
|
77
|
+
...(loginHint && { login_hint: loginHint }),
|
|
78
|
+
...(lang && { lang }),
|
|
79
|
+
...(nonce && { nonce }),
|
|
70
80
|
state,
|
|
71
81
|
...(responseType === 'code' && {
|
|
72
82
|
code_challenge: toCodeChallenge(),
|
|
@@ -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 = void 0;\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 await (0, signInHelpers_1.assertUserNotAuthenticated)();\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 });\n}\nexports.signInWithRedirect = signInWithRedirect;\nconst oauthSignIn = async ({ oauthConfig, provider, clientId, customState, preferPrivateSession, }) => {\n const { domain, redirectSignIn, responseType, scopes } = oauthConfig;\n const randomState = (0, oauth_1.generateState)();\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 queryString = Object.entries({\n redirect_uri: redirectUri,\n response_type: responseType,\n client_id: clientId,\n identity_provider: provider,\n scope: scopes.join(' '),\n state,\n ...(responseType === 'code' && {\n code_challenge: toCodeChallenge(),\n code_challenge_method: method,\n }),\n })\n .map(([k, v]) => `${encodeURIComponent(k)}=${encodeURIComponent(v)}`)\n .join('&');\n // TODO(v6): use URL object instead\n const oAuthUrl = `https://${domain}/oauth2/authorize?${queryString}`;\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 (0, utils_2.openAuthSession)(oAuthUrl, redirectSignIn, preferPrivateSession)) ??\n {};\n try {\n if (type === 'error') {\n throw (0, createOAuthError_1.createOAuthError)(String(error));\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,CAAC;AAC9D,OAAO,CAAC,kBAAkB,GAAG,KAAK,CAAC,CAAC;AACpC,MAAM,MAAM,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAAC;AAC5C,MAAM,OAAO,GAAG,OAAO,CAAC,mCAAmC,CAAC,CAAC;AAC7D,OAAO,CAAC,oCAAoC,CAAC,CAAC;AAC9C,MAAM,QAAQ,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC;AAC5C,MAAM,OAAO,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC;AAC1C,MAAM,eAAe,GAAG,OAAO,CAAC,wBAAwB,CAAC,CAAC;AAC1D,MAAM,OAAO,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC;AAC1C,MAAM,kBAAkB,GAAG,OAAO,CAAC,iCAAiC,CAAC,CAAC;AACtE,MAAM,iBAAiB,GAAG,OAAO,CAAC,gCAAgC,CAAC,CAAC;AACpE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,kBAAkB,CAAC,KAAK,EAAE;AACzC,IAAI,MAAM,UAAU,GAAG,MAAM,CAAC,OAAO,CAAC,SAAS,EAAE,CAAC,IAAI,EAAE,OAAO,CAAC;AAChE,IAAI,IAAI,OAAO,CAAC,yBAAyB,EAAE,UAAU,CAAC,CAAC;AACvD,IAAI,IAAI,OAAO,CAAC,iBAAiB,EAAE,UAAU,CAAC,CAAC;AAC/C,IAAI,OAAO,CAAC,UAAU,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC;AACjD,IAAI,MAAM,IAAI,eAAe,CAAC,0BAA0B,GAAG,CAAC;AAC5D,IAAI,IAAI,QAAQ,GAAG,SAAS,CAAC;AAC7B,IAAI,IAAI,OAAO,KAAK,EAAE,QAAQ,KAAK,QAAQ,EAAE;AAC7C,QAAQ,QAAQ,GAAG,QAAQ,CAAC,kCAAkC,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;AAC/E,KAAK;AACL,SAAS,IAAI,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE;AACtC,QAAQ,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC;AACzC,KAAK;AACL,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,WAAW,EAAE,KAAK,EAAE,WAAW;AACvC,QAAQ,oBAAoB,EAAE,KAAK,EAAE,OAAO,EAAE,oBAAoB;AAClE,KAAK,CAAC,CAAC;AACP,CAAC;AACD,OAAO,CAAC,kBAAkB,GAAG,kBAAkB,CAAC;AAChD,MAAM,WAAW,GAAG,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,QAAQ,EAAE,WAAW,EAAE,oBAAoB,GAAG,KAAK;
|
|
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 = void 0;\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 await (0, signInHelpers_1.assertUserNotAuthenticated)();\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 },\n });\n}\nexports.signInWithRedirect = signInWithRedirect;\nconst oauthSignIn = async ({ oauthConfig, provider, clientId, customState, preferPrivateSession, options, }) => {\n const { domain, redirectSignIn, responseType, scopes } = oauthConfig;\n const { loginHint, lang, nonce } = options ?? {};\n const randomState = (0, oauth_1.generateState)();\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 queryString = Object.entries({\n redirect_uri: redirectUri,\n response_type: responseType,\n client_id: clientId,\n identity_provider: provider,\n scope: scopes.join(' '),\n // eslint-disable-next-line camelcase\n ...(loginHint && { login_hint: loginHint }),\n ...(lang && { lang }),\n ...(nonce && { nonce }),\n state,\n ...(responseType === 'code' && {\n code_challenge: toCodeChallenge(),\n code_challenge_method: method,\n }),\n })\n .map(([k, v]) => `${encodeURIComponent(k)}=${encodeURIComponent(v)}`)\n .join('&');\n // TODO(v6): use URL object instead\n const oAuthUrl = `https://${domain}/oauth2/authorize?${queryString}`;\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 (0, utils_2.openAuthSession)(oAuthUrl, redirectSignIn, preferPrivateSession)) ??\n {};\n try {\n if (type === 'error') {\n throw (0, createOAuthError_1.createOAuthError)(String(error));\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 signInWithRed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ClB,KAAK;AACL,CAAC;;"}
|
|
@@ -46,10 +46,16 @@ async function signInWithRedirect(input) {
|
|
|
46
46
|
provider,
|
|
47
47
|
customState: input?.customState,
|
|
48
48
|
preferPrivateSession: input?.options?.preferPrivateSession,
|
|
49
|
+
options: {
|
|
50
|
+
loginHint: input?.options?.loginHint,
|
|
51
|
+
lang: input?.options?.lang,
|
|
52
|
+
nonce: input?.options?.nonce,
|
|
53
|
+
},
|
|
49
54
|
});
|
|
50
55
|
}
|
|
51
|
-
const oauthSignIn = async ({ oauthConfig, provider, clientId, customState, preferPrivateSession, }) => {
|
|
56
|
+
const oauthSignIn = async ({ oauthConfig, provider, clientId, customState, preferPrivateSession, options, }) => {
|
|
52
57
|
const { domain, redirectSignIn, responseType, scopes } = oauthConfig;
|
|
58
|
+
const { loginHint, lang, nonce } = options ?? {};
|
|
53
59
|
const randomState = generateState();
|
|
54
60
|
/* encodeURIComponent is not URL safe, use urlSafeEncode instead. Cognito
|
|
55
61
|
single-encodes/decodes url on first sign in and double-encodes/decodes url
|
|
@@ -72,6 +78,10 @@ const oauthSignIn = async ({ oauthConfig, provider, clientId, customState, prefe
|
|
|
72
78
|
client_id: clientId,
|
|
73
79
|
identity_provider: provider,
|
|
74
80
|
scope: scopes.join(' '),
|
|
81
|
+
// eslint-disable-next-line camelcase
|
|
82
|
+
...(loginHint && { login_hint: loginHint }),
|
|
83
|
+
...(lang && { lang }),
|
|
84
|
+
...(nonce && { nonce }),
|
|
75
85
|
state,
|
|
76
86
|
...(responseType === 'code' && {
|
|
77
87
|
code_challenge: toCodeChallenge(),
|
|
@@ -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 { getAuthUserAgentValue, openAuthSession } 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 await assertUserNotAuthenticated();\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 });\n}\nconst oauthSignIn = async ({ oauthConfig, provider, clientId, customState, preferPrivateSession, }) => {\n const { domain, redirectSignIn, responseType, scopes } = oauthConfig;\n const randomState = generateState();\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 queryString = Object.entries({\n redirect_uri: redirectUri,\n response_type: responseType,\n client_id: clientId,\n identity_provider: provider,\n scope: scopes.join(' '),\n state,\n ...(responseType === 'code' && {\n code_challenge: toCodeChallenge(),\n code_challenge_method: method,\n }),\n })\n .map(([k, v]) => `${encodeURIComponent(k)}=${encodeURIComponent(v)}`)\n .join('&');\n // TODO(v6): use URL object instead\n const oAuthUrl = `https://${domain}/oauth2/authorize?${queryString}`;\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 === '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":[],"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,CAAC;AACzD,IAAI,yBAAyB,CAAC,UAAU,CAAC,CAAC;AAC1C,IAAI,iBAAiB,CAAC,UAAU,CAAC,CAAC;AAClC,IAAI,UAAU,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC;AACzC,IAAI,MAAM,0BAA0B,EAAE,CAAC;AACvC,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,CAAC;AACtE,KAAK;AACL,SAAS,IAAI,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE;AACtC,QAAQ,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC;AACzC,KAAK;AACL,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,WAAW,EAAE,KAAK,EAAE,WAAW;AACvC,QAAQ,oBAAoB,EAAE,KAAK,EAAE,OAAO,EAAE,oBAAoB;AAClE,KAAK,CAAC,CAAC;AACP,CAAC;AACD,MAAM,WAAW,GAAG,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,QAAQ,EAAE,WAAW,EAAE,oBAAoB,GAAG,KAAK;
|
|
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 { getAuthUserAgentValue, openAuthSession } 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 await assertUserNotAuthenticated();\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 },\n });\n}\nconst oauthSignIn = async ({ oauthConfig, provider, clientId, customState, preferPrivateSession, options, }) => {\n const { domain, redirectSignIn, responseType, scopes } = oauthConfig;\n const { loginHint, lang, nonce } = options ?? {};\n const randomState = generateState();\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 queryString = Object.entries({\n redirect_uri: redirectUri,\n response_type: responseType,\n client_id: clientId,\n identity_provider: provider,\n scope: scopes.join(' '),\n // eslint-disable-next-line camelcase\n ...(loginHint && { login_hint: loginHint }),\n ...(lang && { lang }),\n ...(nonce && { nonce }),\n state,\n ...(responseType === 'code' && {\n code_challenge: toCodeChallenge(),\n code_challenge_method: method,\n }),\n })\n .map(([k, v]) => `${encodeURIComponent(k)}=${encodeURIComponent(v)}`)\n .join('&');\n // TODO(v6): use URL object instead\n const oAuthUrl = `https://${domain}/oauth2/authorize?${queryString}`;\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 === '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":[],"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,CAAC;AACzD,IAAI,yBAAyB,CAAC,UAAU,CAAC,CAAC;AAC1C,IAAI,iBAAiB,CAAC,UAAU,CAAC,CAAC;AAClC,IAAI,UAAU,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC;AACzC,IAAI,MAAM,0BAA0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CAAC,CAAC,CAAC;AAC7E,SAAS,IAAI,CAAC,GAAG,CAAC,CAAC;AACnB;AACA,IAAI,MAAM,QAAQ,GAAG,CAAC,QAAQ,EAAE,MAAM,CAAC,kBAAkB,EAAE,WAAW,CAAC,CAAC,CAAC;AACzE;AACA;AACA;AACA,IAAI,8BAA8B,CAAC,UAAU,CAAC,CAAC;AAC/C;AACA,IAAI,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,EAAE,GAAG,CAAC,MAAM,eAAe,CAAC,QAA8C,CAAC;AACvG,QAAQ,EAAE,CAAC;AACX,IAAI,IAAI;AACR,QAAQ,IAAI,IAAI,KAAK,OAAO,EAAE;AAC9B,YAAY,MAAM,gBAAgB,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;AAClD,SAAS;AACT,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,CAAC;AACf,SAAS;AACT,KAAK;AACL,IAAI,OAAO,GAAG,EAAE;AAChB,QAAQ,MAAM,aAAa,CAAC,GAAG,CAAC,CAAC;AACjC;AACA,QAAQ,MAAM,GAAG,CAAC;AAClB,KAAK;AACL,CAAC;;;;"}
|
|
@@ -48,6 +48,21 @@ export interface AuthSignInWithRedirectInput {
|
|
|
48
48
|
* On all other platforms, this flag is ignored.
|
|
49
49
|
*/
|
|
50
50
|
preferPrivateSession?: boolean;
|
|
51
|
+
/**
|
|
52
|
+
* A username prompt that you want to pass to the authorization server. You can collect a username, email address or phone number from your user and allow the destination provider to pre-populate the user's sign-in name. When you submit a `login_hint` parameter and no `idp_identifier` or `identity_provider` parameters to the `/oauth2/authorize` endpoint, managed login fills the username field with your hint value. You can also pass this parameter to the Login endpoint and automatically fill the username value.
|
|
53
|
+
* @see https://docs.aws.amazon.com/cognito/latest/developerguide/authorization-endpoint.html
|
|
54
|
+
*/
|
|
55
|
+
loginHint?: string;
|
|
56
|
+
/**
|
|
57
|
+
* The language that you want to display user-interactive pages in. Managed login pages can be localized, but hosted UI (classic) pages can not
|
|
58
|
+
* @see https://docs.aws.amazon.com/cognito/latest/developerguide/authorization-endpoint.html
|
|
59
|
+
*/
|
|
60
|
+
lang?: 'de' | 'en' | 'es' | 'fr' | 'id' | 'it' | 'ja' | 'ko' | 'pt-BR' | 'zh-CN' | 'zh-TW' | (string & NonNullable<unknown>);
|
|
61
|
+
/**
|
|
62
|
+
* A random value that you can add to the request. The nonce value that you provide is included in the ID token that Amazon Cognito issues. To guard against replay attacks, your app can inspect the `nonce` claim in the ID token and compare it to the one you generated.
|
|
63
|
+
* @see https://docs.aws.amazon.com/cognito/latest/developerguide/authorization-endpoint.html
|
|
64
|
+
*/
|
|
65
|
+
nonce?: string;
|
|
51
66
|
};
|
|
52
67
|
}
|
|
53
68
|
/**
|
package/package.json
CHANGED
|
@@ -1,106 +1,108 @@
|
|
|
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
|
-
|
|
2
|
+
"name": "@aws-amplify/auth",
|
|
3
|
+
"version": "6.10.0",
|
|
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": "./src/index.ts",
|
|
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
|
+
"types": "./dist/esm/index.d.ts",
|
|
48
|
+
"import": "./dist/esm/index.mjs",
|
|
49
|
+
"require": "./dist/cjs/index.js",
|
|
50
|
+
"react-native": "./src/index.ts"
|
|
51
|
+
},
|
|
52
|
+
"./cognito": {
|
|
53
|
+
"types": "./dist/esm/providers/cognito/index.d.ts",
|
|
54
|
+
"import": "./dist/esm/providers/cognito/index.mjs",
|
|
55
|
+
"require": "./dist/cjs/providers/cognito/index.js",
|
|
56
|
+
"react-native": "./src/providers/cognito/index.ts"
|
|
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.1.0"
|
|
100
|
+
},
|
|
101
|
+
"devDependencies": {
|
|
102
|
+
"@aws-amplify/core": "6.9.1",
|
|
103
|
+
"@aws-amplify/react-native": "1.1.6",
|
|
104
|
+
"@jest/test-sequencer": "^29.7.0",
|
|
105
|
+
"typescript": "5.0.2"
|
|
106
|
+
},
|
|
107
|
+
"gitHead": "d19eada08d054c88180fb525c7bea6f24e2afa68"
|
|
106
108
|
}
|
|
@@ -57,6 +57,11 @@ export async function signInWithRedirect(
|
|
|
57
57
|
provider,
|
|
58
58
|
customState: input?.customState,
|
|
59
59
|
preferPrivateSession: input?.options?.preferPrivateSession,
|
|
60
|
+
options: {
|
|
61
|
+
loginHint: input?.options?.loginHint,
|
|
62
|
+
lang: input?.options?.lang,
|
|
63
|
+
nonce: input?.options?.nonce,
|
|
64
|
+
},
|
|
60
65
|
});
|
|
61
66
|
}
|
|
62
67
|
|
|
@@ -66,14 +71,17 @@ const oauthSignIn = async ({
|
|
|
66
71
|
clientId,
|
|
67
72
|
customState,
|
|
68
73
|
preferPrivateSession,
|
|
74
|
+
options,
|
|
69
75
|
}: {
|
|
70
76
|
oauthConfig: OAuthConfig;
|
|
71
77
|
provider: string;
|
|
72
78
|
clientId: string;
|
|
73
79
|
customState?: string;
|
|
74
80
|
preferPrivateSession?: boolean;
|
|
81
|
+
options?: SignInWithRedirectInput['options'];
|
|
75
82
|
}) => {
|
|
76
83
|
const { domain, redirectSignIn, responseType, scopes } = oauthConfig;
|
|
84
|
+
const { loginHint, lang, nonce } = options ?? {};
|
|
77
85
|
const randomState = generateState();
|
|
78
86
|
|
|
79
87
|
/* encodeURIComponent is not URL safe, use urlSafeEncode instead. Cognito
|
|
@@ -99,6 +107,10 @@ const oauthSignIn = async ({
|
|
|
99
107
|
client_id: clientId,
|
|
100
108
|
identity_provider: provider,
|
|
101
109
|
scope: scopes.join(' '),
|
|
110
|
+
// eslint-disable-next-line camelcase
|
|
111
|
+
...(loginHint && { login_hint: loginHint }),
|
|
112
|
+
...(lang && { lang }),
|
|
113
|
+
...(nonce && { nonce }),
|
|
102
114
|
state,
|
|
103
115
|
...(responseType === 'code' && {
|
|
104
116
|
code_challenge: toCodeChallenge(),
|
package/src/types/inputs.ts
CHANGED
|
@@ -68,6 +68,33 @@ export interface AuthSignInWithRedirectInput {
|
|
|
68
68
|
* On all other platforms, this flag is ignored.
|
|
69
69
|
*/
|
|
70
70
|
preferPrivateSession?: boolean;
|
|
71
|
+
/**
|
|
72
|
+
* A username prompt that you want to pass to the authorization server. You can collect a username, email address or phone number from your user and allow the destination provider to pre-populate the user's sign-in name. When you submit a `login_hint` parameter and no `idp_identifier` or `identity_provider` parameters to the `/oauth2/authorize` endpoint, managed login fills the username field with your hint value. You can also pass this parameter to the Login endpoint and automatically fill the username value.
|
|
73
|
+
* @see https://docs.aws.amazon.com/cognito/latest/developerguide/authorization-endpoint.html
|
|
74
|
+
*/
|
|
75
|
+
loginHint?: string;
|
|
76
|
+
/**
|
|
77
|
+
* The language that you want to display user-interactive pages in. Managed login pages can be localized, but hosted UI (classic) pages can not
|
|
78
|
+
* @see https://docs.aws.amazon.com/cognito/latest/developerguide/authorization-endpoint.html
|
|
79
|
+
*/
|
|
80
|
+
lang?:
|
|
81
|
+
| 'de'
|
|
82
|
+
| 'en'
|
|
83
|
+
| 'es'
|
|
84
|
+
| 'fr'
|
|
85
|
+
| 'id'
|
|
86
|
+
| 'it'
|
|
87
|
+
| 'ja'
|
|
88
|
+
| 'ko'
|
|
89
|
+
| 'pt-BR'
|
|
90
|
+
| 'zh-CN'
|
|
91
|
+
| 'zh-TW'
|
|
92
|
+
| (string & NonNullable<unknown>);
|
|
93
|
+
/**
|
|
94
|
+
* A random value that you can add to the request. The nonce value that you provide is included in the ID token that Amazon Cognito issues. To guard against replay attacks, your app can inspect the `nonce` claim in the ID token and compare it to the one you generated.
|
|
95
|
+
* @see https://docs.aws.amazon.com/cognito/latest/developerguide/authorization-endpoint.html
|
|
96
|
+
*/
|
|
97
|
+
nonce?: string;
|
|
71
98
|
};
|
|
72
99
|
}
|
|
73
100
|
|