diff --git a/packages/aws-amplify/__tests__/exports.test.ts b/packages/aws-amplify/__tests__/exports.test.ts index c6425ad7c93..7d151df375c 100644 --- a/packages/aws-amplify/__tests__/exports.test.ts +++ b/packages/aws-amplify/__tests__/exports.test.ts @@ -186,6 +186,8 @@ describe('aws-amplify Exports', () => { it('should only export expected symbols from the Cognito provider', () => { expect(Object.keys(authCognitoExports).sort()).toEqual( [ + 'AUTH_KEY_PREFIX', + 'createKeysForAuthStorage', 'signUp', 'resetPassword', 'confirmResetPassword', @@ -200,7 +202,10 @@ describe('aws-amplify Exports', () => { 'setUpTOTP', 'updateUserAttributes', 'updateUserAttribute', + 'generateCodeVerifier', + 'generateState', 'getCurrentUser', + 'getRedirectUrl', 'confirmUserAttribute', 'signInWithRedirect', 'fetchUserAttributes', @@ -220,6 +225,7 @@ describe('aws-amplify Exports', () => { 'DefaultTokenStore', 'refreshAuthTokens', 'refreshAuthTokensWithoutDedupe', + 'validateState', ].sort(), ); }); diff --git a/packages/aws-amplify/jest.config.js b/packages/aws-amplify/jest.config.js index 5254f524623..fa397b3b531 100644 --- a/packages/aws-amplify/jest.config.js +++ b/packages/aws-amplify/jest.config.js @@ -8,6 +8,10 @@ module.exports = { statements: 91, }, }, + coveragePathIgnorePatterns: [ + 'src/adapter-core/index.ts', + 'src/utils/index.ts', + ], moduleNameMapper: { uuid: require.resolve('uuid'), }, diff --git a/packages/aws-amplify/src/adapter-core/constants.ts b/packages/aws-amplify/src/adapter-core/constants.ts new file mode 100644 index 00000000000..d96711d3454 --- /dev/null +++ b/packages/aws-amplify/src/adapter-core/constants.ts @@ -0,0 +1,4 @@ +// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +// SPDX-License-Identifier: Apache-2.0 + +export const DEFAULT_COOKIE_EXPIRY = 365 * 24 * 60 * 60 * 1000; // 1 year in milliseconds diff --git a/packages/aws-amplify/src/adapter-core/index.ts b/packages/aws-amplify/src/adapter-core/index.ts index 755f8c12b42..0bb85581dc0 100644 --- a/packages/aws-amplify/src/adapter-core/index.ts +++ b/packages/aws-amplify/src/adapter-core/index.ts @@ -15,3 +15,12 @@ export { AmplifyServer, CookieStorage, } from '@aws-amplify/core/internals/adapter-core'; +export { + generateState, + getRedirectUrl, + generateCodeVerifier, + validateState, + createKeysForAuthStorage, + AUTH_KEY_PREFIX, +} from '@aws-amplify/auth/cognito'; +export { DEFAULT_COOKIE_EXPIRY } from './constants'; diff --git a/packages/aws-amplify/src/adapter-core/storageFactories/createKeyValueStorageFromCookieStorageAdapter.ts b/packages/aws-amplify/src/adapter-core/storageFactories/createKeyValueStorageFromCookieStorageAdapter.ts index da15ae22192..0bce4c8395f 100644 --- a/packages/aws-amplify/src/adapter-core/storageFactories/createKeyValueStorageFromCookieStorageAdapter.ts +++ b/packages/aws-amplify/src/adapter-core/storageFactories/createKeyValueStorageFromCookieStorageAdapter.ts @@ -7,13 +7,14 @@ import { KeyValueStorageMethodValidator, } from '@aws-amplify/core/internals/adapter-core'; +import { DEFAULT_COOKIE_EXPIRY } from '../constants'; + export const defaultSetCookieOptions: CookieStorage.SetCookieOptions = { // TODO: allow configure with a public interface sameSite: 'lax', secure: true, path: '/', }; -const ONE_YEAR_IN_MS = 365 * 24 * 60 * 60 * 1000; /** * Creates a Key Value storage interface using the `cookieStorageAdapter` as the @@ -40,7 +41,7 @@ export const createKeyValueStorageFromCookieStorageAdapter = ( // TODO(HuiSF): follow up the default CookieSerializeOptions values cookieStorageAdapter.set(key, value, { ...defaultSetCookieOptions, - expires: new Date(Date.now() + ONE_YEAR_IN_MS), + expires: new Date(Date.now() + DEFAULT_COOKIE_EXPIRY), ...overrideCookieAttributes, });