forked from aws-amplify/amplify-js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'next' into temp-signOut
- Loading branch information
Showing
36 changed files
with
454 additions
and
242 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
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
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
34 changes: 34 additions & 0 deletions
34
packages/auth/src/providers/cognito/apis/internal/fetchUserAttributes.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,34 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { AmplifyClassV6 } from '@aws-amplify/core'; | ||
import { | ||
assertTokenProviderConfig, | ||
fetchAuthSession, | ||
} from '@aws-amplify/core/internals/utils'; | ||
import { getUser } from '../../utils/clients/CognitoIdentityProvider'; | ||
import { AuthUserAttribute } from '../../../..'; | ||
import { getRegion } from '../../utils/clients/CognitoIdentityProvider/utils'; | ||
import { assertAuthTokens } from '../../utils/types'; | ||
import { CognitoUserAttributeKey } from '../../types'; | ||
import { toAuthUserAttribute } from '../../utils/apiHelpers'; | ||
|
||
export const fetchUserAttributes = async ( | ||
amplify: AmplifyClassV6 | ||
): Promise<AuthUserAttribute<CognitoUserAttributeKey>> => { | ||
const authConfig = amplify.getConfig().Auth; | ||
assertTokenProviderConfig(authConfig); | ||
const { tokens } = await fetchAuthSession(amplify, { | ||
forceRefresh: false, | ||
}); | ||
assertAuthTokens(tokens); | ||
|
||
const { UserAttributes } = await getUser( | ||
{ region: getRegion(authConfig.userPoolId) }, | ||
{ | ||
AccessToken: tokens.accessToken.toString(), | ||
} | ||
); | ||
|
||
return toAuthUserAttribute(UserAttributes); | ||
}; |
28 changes: 28 additions & 0 deletions
28
packages/auth/src/providers/cognito/apis/internal/getCurrentUser.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,28 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { AmplifyClassV6 } from '@aws-amplify/core'; | ||
import { | ||
assertTokenProviderConfig, | ||
fetchAuthSession, | ||
} from '@aws-amplify/core/internals/utils'; | ||
import { GetCurrentUserRequest, AuthUser } from '../../../../types'; | ||
import { assertAuthTokens } from '../../utils/types'; | ||
|
||
export const getCurrentUser = async ( | ||
amplify: AmplifyClassV6, | ||
getCurrentUserRequest?: GetCurrentUserRequest | ||
): Promise<AuthUser> => { | ||
const authConfig = amplify.getConfig().Auth; | ||
assertTokenProviderConfig(authConfig); | ||
const { tokens } = await fetchAuthSession(amplify, { | ||
forceRefresh: getCurrentUserRequest?.recache ?? false, | ||
}); | ||
assertAuthTokens(tokens); | ||
const { payload } = tokens.idToken; | ||
|
||
return { | ||
username: payload['cognito:username'] as string, | ||
userId: payload['sub'] as string, | ||
}; | ||
}; |
18 changes: 18 additions & 0 deletions
18
packages/auth/src/providers/cognito/apis/server/fetchUserAttributes.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,18 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { | ||
AmplifyServer, | ||
getAmplifyServerContext, | ||
} from '@aws-amplify/core/internals/adapter-core'; | ||
import { AuthUserAttribute } from '../../../../types'; | ||
import { CognitoUserAttributeKey } from '../../types'; | ||
import { fetchUserAttributes as fetchUserAttributesInternal } from '../internal/fetchUserAttributes'; | ||
|
||
export const fetchUserAttributes = ( | ||
contextSpec: AmplifyServer.ContextSpec | ||
): Promise<AuthUserAttribute<CognitoUserAttributeKey>> => { | ||
return fetchUserAttributesInternal( | ||
getAmplifyServerContext(contextSpec).amplify | ||
); | ||
}; |
Oops, something went wrong.