-
Notifications
You must be signed in to change notification settings - Fork 590
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
Cognito Sign Up not returning Session #6724
Comments
Hi @leonardoalifraco - thanks for reaching out. According to service model, |
Hi @aBurmeseDev, thank you very much. Adding code snippet below, exec instructions and response below. import { CognitoIdentityProviderClient, SignUpCommand, SignUpCommandInput } from "@aws-sdk/client-cognito-identity-provider";
import { createHmac } from 'crypto';
const generateSecretHash = (username: string) => {
const message = username + process.env.COGNITO_CLIENT_ID;
return createHmac('sha256', process.env.COGNITO_CLIENT_SECRET || '')
.update(message)
.digest('base64');
};
const signUp = async (
username: string,
password: string,
userAttributes: {
email: string;
name: string;
},
) => {
const cognitoClient = new CognitoIdentityProviderClient();
const params: SignUpCommandInput = {
ClientId: process.env.COGNITO_CLIENT_ID,
Username: username,
Password: password,
SecretHash: generateSecretHash(username),
UserAttributes: [
{ Name: 'email', Value: userAttributes.email },
{ Name: 'name', Value: userAttributes.name },
],
};
const command = new SignUpCommand(params);
return await cognitoClient.send(command);
};
const main = async () => {
try {
const response = await signUp("username", "Password01!", {
email: "[email protected]",
name: "Leo",
});
console.log("Sign-up successful:", JSON.stringify(response, null, 2));
} catch (error) {
console.error("Failed to sign up:", error);
}
};
main().catch((error) => {
console.error("Unhandled error in main:", error);
}); Run with: Response was:
|
Ran into the same missing Session attribute yesterday but on the ConfirmSignUpCommand
Response is missing the Session
|
same issue |
any updates on this one? @aBurmeseDev |
Hi @aBurmeseDev, did you have any updates from the Service team? |
Hi @leonardoalifraco - sorry for the wait. I just heard back from service team member and here's the response
If you've turned on |
Thank you very much @aBurmeseDev. I have enabled USER_AUTH for the Cognito App Client and it worked perfectly. For reference, I am attaching test code on how I am confirming a user and initiating auth using the sign up session, and later the confirm sign up session. This code runs after #6724 (comment) and is returning auth tokens without the need of other user credentials but the session. import { CognitoIdentityProviderClient, ConfirmSignUpCommand, ConfirmSignUpCommandInput, AuthFlowType, InitiateAuthCommand, InitiateAuthCommandInput} from "@aws-sdk/client-cognito-identity-provider";
import { createHmac } from 'crypto';
const generateSecretHash = (username: string) => {
const message = username + process.env.COGNITO_CLIENT_ID;
return createHmac('sha256', process.env.COGNITO_CLIENT_SECRET || '')
.update(message)
.digest('base64');
};
const confirmSignUp = async (
username: string,
confirmationCode: string,
session: string,
) => {
const cognitoClient = new CognitoIdentityProviderClient();
const params: ConfirmSignUpCommandInput = {
ClientId: process.env.COGNITO_CLIENT_ID,
Username: username,
SecretHash: generateSecretHash(username),
ConfirmationCode: confirmationCode,
Session: session,
};
const command = new ConfirmSignUpCommand(params);
return await cognitoClient.send(command);
};
const initiateAuth = async (
username: string,
session: string,
) => {
const cognitoClient = new CognitoIdentityProviderClient();
const params: InitiateAuthCommandInput = {
ClientId: process.env.COGNITO_CLIENT_ID,
AuthFlow: AuthFlowType.USER_AUTH,
AuthParameters: {
USERNAME: username,
SECRET_HASH: generateSecretHash(username),
},
Session: session,
};
const command = new InitiateAuthCommand(params);
return await cognitoClient.send(command);
};
const main = async () => {
try {
const username = ""; // username here
const confirmationCode = ""; // confirmation code here
const session = ""; // sign-up session here
const response = await confirmSignUp(username, confirmationCode, session);
console.log("Confirm Sign-Up successful:", JSON.stringify(response, null, 2));
const initiateAuthResponse = await initiateAuth(username, response.Session || "");
console.log("InitiateAuth successful:", JSON.stringify(initiateAuthResponse, null, 2));
} catch (error) {
console.error("Failed:", error);
}
};
main().catch((error) => {
console.error("Unhandled error in main:", error);
}); |
Checkboxes for prior research
Describe the bug
The documentation for the SignUp operation, indicates that the response will include a Session attribute that you can pass to ConfirmSignUp when you want to immediately sign in your user with the USER_AUTH flow after they complete sign-up.
However the Session attribute is returned always as null.
Tried different configurations in Cognito, allowing all Authentication Flows, but the session still returns as null (or doesn't return at all when called from AWS CLI).
https://docs.aws.amazon.com/cognito-user-identity-pools/latest/APIReference/API_SignUp.html#API_SignUp_ResponseSyntax
Regression Issue
SDK version number
@aws-sdk/[email protected]
Which JavaScript Runtime is this issue in?
Node.js
Details of the browser/Node.js/ReactNative version
Node v20.11.1
Reproduction Steps
Observed Behavior
Session attribute from the SignUpCommandOutput is always null.
Expected Behavior
Session attribute from the SignUpCommand should have a value that can be persisted locally and eventually included in the ConfirmSignUpCommand.
Possible Solution
No response
Additional Information/Context
No response
The text was updated successfully, but these errors were encountered: