-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into chore/upgrade-jest
- Loading branch information
Showing
8 changed files
with
68 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
packages/auth/src/providers/cognito/tokenProvider/CognitoUserPoolsTokenProvider.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
4 changes: 2 additions & 2 deletions
4
packages/auth/src/providers/cognito/tokenProvider/cacheTokens.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 7 additions & 52 deletions
59
packages/auth/src/providers/cognito/tokenProvider/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
10
packages/auth/src/providers/cognito/tokenProvider/tokenProvider.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
4 changes: 2 additions & 2 deletions
4
packages/notifications/src/inAppMessaging/providers/pinpoint/types/inputs.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters