Skip to content

Commit

Permalink
Merge branch 'main' into chore/upgrade-jest
Browse files Browse the repository at this point in the history
  • Loading branch information
cshfang authored Nov 28, 2023
2 parents 8519c4b + a353e0d commit fa1b5ce
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 59 deletions.
2 changes: 1 addition & 1 deletion packages/analytics/src/providers/pinpoint/types/inputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

import { PinpointAnalyticsEvent } from '@aws-amplify/core/internals/providers/pinpoint';
import { IdentifyUserOptions } from '.';
import { IdentifyUserOptions } from './options';
import {
AnalyticsConfigureAutoTrackInput,
AnalyticsIdentifyUserInput,
Expand Down
2 changes: 1 addition & 1 deletion packages/analytics/src/types/inputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

import { UserProfile } from '@aws-amplify/core';
import { AnalyticsServiceOptions } from '.';
import { AnalyticsServiceOptions } from './options';
import {
SessionTrackingOptions,
PageViewTrackingOptions,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import {
AuthConfig,
AuthTokens,
FetchAuthSessionOptions,
KeyValueStorageInterface,
defaultStorage,
} from '@aws-amplify/core';
import { refreshAuthTokens } from '../utils/refreshAuthTokens';
import { DefaultTokenStore } from './TokenStore';
import { TokenOrchestrator } from './TokenOrchestrator';
import { CognitoUserPoolTokenProviderType } from './types';

export class CognitoUserPoolsTokenProvider
implements CognitoUserPoolTokenProviderType
{
authTokenStore: DefaultTokenStore;
tokenOrchestrator: TokenOrchestrator;
constructor() {
this.authTokenStore = new DefaultTokenStore();
this.authTokenStore.setKeyValueStorage(defaultStorage);
this.tokenOrchestrator = new TokenOrchestrator();
this.tokenOrchestrator.setAuthTokenStore(this.authTokenStore);
this.tokenOrchestrator.setTokenRefresher(refreshAuthTokens);
}
getTokens(
{ forceRefresh }: FetchAuthSessionOptions = { forceRefresh: false }
): Promise<AuthTokens | null> {
return this.tokenOrchestrator.getTokens({ forceRefresh });
}

setKeyValueStorage(keyValueStorage: KeyValueStorageInterface): void {
this.authTokenStore.setKeyValueStorage(keyValueStorage);
}
setWaitForInflightOAuth(waitForInflightOAuth: () => Promise<void>): void {
this.tokenOrchestrator.setWaitForInflightOAuth(waitForInflightOAuth);
}
setAuthConfig(authConfig: AuthConfig) {
this.authTokenStore.setAuthConfig(authConfig);
this.tokenOrchestrator.setAuthConfig(authConfig);
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
import { AmplifyError, decodeJWT } from '@aws-amplify/core/internals/utils';
import { tokenOrchestrator } from '.';
import { CognitoAuthSignInDetails } from '../types';
import { AuthenticationResultType } from '../utils/clients/CognitoIdentityProvider/types';
import { tokenOrchestrator } from './tokenProvider';
import { CognitoAuthTokens, DeviceMetadata } from './types';
import { CognitoAuthSignInDetails } from '../types';

export async function cacheCognitoTokens(
AuthenticationResult: AuthenticationResultType & {
Expand Down
59 changes: 7 additions & 52 deletions packages/auth/src/providers/cognito/tokenProvider/index.ts
Original file line number Diff line number Diff line change
@@ -1,56 +1,11 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
import {
AuthConfig,
AuthTokens,
FetchAuthSessionOptions,
KeyValueStorageInterface,
defaultStorage,
} from '@aws-amplify/core';
import { refreshAuthTokens } from '../utils/refreshAuthTokens';
import { DefaultTokenStore } from './TokenStore';
import { TokenOrchestrator } from './TokenOrchestrator';
import { CognitoUserPoolTokenProviderType } from './types';

class CognitoUserPoolsTokenProviderClass
implements CognitoUserPoolTokenProviderType
{
authTokenStore: DefaultTokenStore;
tokenOrchestrator: TokenOrchestrator;
constructor() {
this.authTokenStore = new DefaultTokenStore();
this.authTokenStore.setKeyValueStorage(defaultStorage);
this.tokenOrchestrator = new TokenOrchestrator();
this.tokenOrchestrator.setAuthTokenStore(this.authTokenStore);
this.tokenOrchestrator.setTokenRefresher(refreshAuthTokens);
}
getTokens(
{ forceRefresh }: FetchAuthSessionOptions = { forceRefresh: false }
): Promise<AuthTokens | null> {
return this.tokenOrchestrator.getTokens({ forceRefresh });
}

setKeyValueStorage(keyValueStorage: KeyValueStorageInterface): void {
this.authTokenStore.setKeyValueStorage(keyValueStorage);
}
setWaitForInflightOAuth(waitForInflightOAuth: () => Promise<void>): void {
this.tokenOrchestrator.setWaitForInflightOAuth(waitForInflightOAuth);
}
setAuthConfig(authConfig: AuthConfig) {
this.authTokenStore.setAuthConfig(authConfig);
this.tokenOrchestrator.setAuthConfig(authConfig);
}
}

export const cognitoUserPoolsTokenProvider =
new CognitoUserPoolsTokenProviderClass();

export const tokenOrchestrator =
cognitoUserPoolsTokenProvider.tokenOrchestrator;

export { refreshAuthTokens } from '../utils/refreshAuthTokens';
export { DefaultTokenStore } from './TokenStore';
export { TokenOrchestrator } from './TokenOrchestrator';
export { CognitoUserPoolTokenProviderType } from './types';
export {
CognitoUserPoolTokenProviderType,
DefaultTokenStore,
TokenOrchestrator,
refreshAuthTokens,
};
cognitoUserPoolsTokenProvider,
tokenOrchestrator,
} from './tokenProvider';
10 changes: 10 additions & 0 deletions packages/auth/src/providers/cognito/tokenProvider/tokenProvider.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import { CognitoUserPoolsTokenProvider } from './CognitoUserPoolsTokenProvider';

export const cognitoUserPoolsTokenProvider =
new CognitoUserPoolsTokenProvider();

export const tokenOrchestrator =
cognitoUserPoolsTokenProvider.tokenOrchestrator;
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import { IdentifyUserOptions } from './options';
import {
IdentifyUserOptions,
InAppMessageConflictHandler,
OnMessageInteractionEventHandler,
} from '.';
} from './types';
import {
InAppMessage,
InAppMessageInteractionEvent,
Expand Down
2 changes: 1 addition & 1 deletion packages/notifications/src/inAppMessaging/types/inputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

import { UserProfile } from '@aws-amplify/core';
import { InAppMessagingServiceOptions } from '.';
import { InAppMessagingServiceOptions } from './options';

/**
* Input type for `identifyUser`.
Expand Down

0 comments on commit fa1b5ce

Please sign in to comment.