Skip to content

Commit

Permalink
update README to mention compatability with v2 and v3 SDK
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon McAllister committed Oct 28, 2023
1 parent 09c6319 commit e6626c7
Showing 1 changed file with 57 additions and 1 deletion.
58 changes: 57 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Or CommonJS require:
const CognitoSrpHelper = require("cognito-srp-helper");
```

Here is an example of how you would use the helper to implement SRP authentication with Cognito using the AWS JavaScript SDK (v3):
Here is an example of how you would use the helper to implement SRP authentication with Cognito using the AWS JavaScript SDK v3:

```ts
import {
Expand Down Expand Up @@ -78,6 +78,62 @@ const respondToAuthChallengeRes = await cognitoIdentityProviderClient
// . . . return login tokens from respondToAuthChallengeResponse
```

Here is an example of how you would use the helper to implement SRP authentication with Cognito using the AWS JavaScript SDK v2 (deprecated):

```ts
import {
createSecretHash,
createPasswordHash,
createSrpSession,
signSrpSession,
wrapAuthChallenge,
wrapInitiateAuth,
} from "cognito-srp-helper";

// . . . obtain user credentials, IDs, and setup Cognito client

const secretHash = createSecretHash(username, clientId, secretId);
const passwordHash = createPasswordHash(username, password, poolId);
const srpSession = createSrpSession(username, passwordHash, poolId);

const initiateAuthRes = await cognitoIdentityServiceProvider
.initiateAuth(
wrapInitiateAuth(srpSession, {
ClientId: CLIENT_ID,
AuthFlow: "USER_SRP_AUTH",
AuthParameters: {
CHALLENGE_NAME: "SRP_A",
SECRET_HASH: secretHash,
USERNAME,
},
}),
)
.promise()
.catch((err) => {
throw err;
});

const signedSrpSession = signSrpSession(srpSession, initiateAuthRes);

const respondToAuthChallengeRes = await cognitoIdentityServiceProvider
.respondToAuthChallenge(
wrapAuthChallenge(signedSrpSession, {
ClientId: CLIENT_ID,
ChallengeName: "PASSWORD_VERIFIER",
ChallengeResponses: {
SECRET_HASH: secretHash,
USERNAME,
},
}),
)
.promise()
.catch((err) => {
throw err;
});

// . . . return login tokens from respondToAuthChallengeResponse
```

## Zero values in SRP

Should you worry about 0 being used during the SRP calculations?
Expand Down

0 comments on commit e6626c7

Please sign in to comment.