Closed varuna-peiris closed 3 weeks ago
Hey Varuna, thanks for checking out the project 🙂
Importing src/*
files won't work if you're importing inside a .js
file, because the project is written in TypeScript. It needs to be compiled before you can import it in JavaScript
If you build the project with npm run build
then you should be able to import it by refering to the package name:
import * as CognitoSrpHelper from "cognito-srp-helper";
// . . .
Let me know if that works for you
Thank you for your response. I tried what you suggested steps but the error is still the same. Here I attached a screenshot for your reference.
That's odd 🤔
Did you update the import statement? from:
import CognitoSrpHelper from "./src/cognito-srp-helper";
.. to ..
import * as CognitoSrpHelper from "cognito-srp-helper";
Yes, I updated it. Now I did the following to a new clone and the error was changed. Here I attached a screenshot for your reference.
Oh, that's to do with CognitoIdentityProviderClient. You need to instantiate the client first:
const cognitoIdentityProviderClient = new CognitoIdentityProviderClient({
region: "eu-west-2", // <-- this should be the AWS region
});
Then you can call send on the instance you created:
const respondToAuthChallengeRes = await cognitoIdentityProviderClient.send(
// . . .
);
I ran the code applying the above changes and it runs without errors. But it does not appear to pop up or anything for the challenge. I've attached a screenshot for you to look over. Please guide me.
Ah, you may just need to log something to the console
Since a lot of these questions are unrelated to the package itself I'll close this issue. But if any issues specific to the package does come up feel free to open up this issue again
I am trying to authenticate a user using the User_SRP_Auth authflow from the repository. While following the steps provided, I encountered an error. Steps to Reproduce:
import CognitoSrpHelper from "./src/cognito-srp-helper"; import { CognitoIdentityProviderClient, InitiateAuthCommand, RespondToAuthChallengeCommand } from "@aws-sdk/client-cognito-identity-provider";
const username = "xxxxxx"; const password = "xxxxxx"; const clientId = "xxxxxxxxxxxxxxxxxxxxxx"; const secretId = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; const poolId = "xxxxxxx_xxxxxxxxx";
const secretHash = CognitoSrpHelper.createSecretHash(username, clientId, secretId); const srpSession = CognitoSrpHelper.createSrpSession(username, password, poolId, false);
async function run() { try { const initiateAuthRes = await CognitoIdentityProviderClient.send( new InitiateAuthCommand( CognitoSrpHelper.wrapInitiateAuth(srpSession, { ClientId: clientId, AuthFlow: "USER_SRP_AUTH", AuthParameters: { CHALLENGE_NAME: "SRP_A", SECRET_HASH: secretHash, USERNAME: username, }, }), ), );
} catch (err) { console.error(err); } }
run(); ``
Please guide me, in completing the SRP authentication process successfully, resulting in a valid authentication response using your repo.
I appreciate any help you can provide.
Thanks in advance.