Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(auth): Added missing UserContextData to Cognito User Pool operation SignUp #13477

Merged
merged 13 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions packages/auth/__tests__/providers/cognito/signUp.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,38 @@ describe('signUp', () => {
userId,
});
});

it('should send UserContextData', async () => {
window.AmazonCognitoAdvancedSecurityData = {
getData() {
return 'abcd';
},
};
await signUp({
username: user1.username,
password: user1.password,
options: {
userAttributes: { email: user1.email },
},
});
expect(mockSignUp).toHaveBeenCalledWith(
{
region: 'us-west-2',
userAgentValue: expect.any(String),
},
{
ClientMetadata: undefined,
Password: user1.password,
UserAttributes: [{ Name: 'email', Value: user1.email }],
Username: user1.username,
ValidationData: undefined,
ClientId: '111111-aaaaa-42d8-891d-ee81a1549398',
UserContextData: { EncodedData: 'abcd' },
},
);
expect(mockSignUp).toHaveBeenCalledTimes(1);
window.AmazonCognitoAdvancedSecurityData = undefined;
});
});

describe('Error Path Cases:', () => {
Expand Down
14 changes: 11 additions & 3 deletions packages/auth/src/providers/cognito/apis/signUp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
setAutoSignInStarted,
setUsernameUsedForAutoSignIn,
} from '../utils/signUpHelpers';
import { getUserContextData } from '../utils/userContextData';
import { getAuthUserAgentValue } from '../../../utils';

import { setAutoSignIn } from './autoSignIn';
Expand Down Expand Up @@ -62,7 +63,6 @@ export async function signUp(input: SignUpInput): Promise<SignUpOutput> {
username,
options: signInServiceOptions,
};

// if the authFlowType is 'CUSTOM_WITHOUT_SRP' then we don't include the password
if (signInServiceOptions?.authFlowType !== 'CUSTOM_WITHOUT_SRP') {
signInInput.password = password;
Expand All @@ -71,9 +71,12 @@ export async function signUp(input: SignUpInput): Promise<SignUpOutput> {
setUsernameUsedForAutoSignIn(username);
setAutoSignInStarted(true);
}

const { userPoolId, userPoolClientId } = authConfig;

const clientOutput = await signUpClient(
{
region: getRegion(authConfig.userPoolId),
region: getRegion(userPoolId),
userAgentValue: getAuthUserAgentValue(AuthAction.SignUp),
},
{
Expand All @@ -83,7 +86,12 @@ export async function signUp(input: SignUpInput): Promise<SignUpOutput> {
options?.userAttributes && toAttributeType(options?.userAttributes),
ClientMetadata: clientMetadata,
ValidationData: validationData && toAttributeType(validationData),
ClientId: authConfig.userPoolClientId,
ClientId: userPoolClientId,
UserContextData: getUserContextData({
username,
userPoolId,
userPoolClientId,
}),
},
);
const { UserSub, CodeDeliveryDetails } = clientOutput;
Expand Down
Loading