Created
August 16, 2023 10:41
-
-
Save Rud5G/aa47408109684b1833ac7d96f8b24c86 to your computer and use it in GitHub Desktop.
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
import { SecretsManager } from "@aws-sdk/client-secrets-manager"; | |
const secretsManager = new SecretsManager({}); | |
const TEST_USER_NAME = "TEST_USER"; | |
const getTestUserPassword = async function () { | |
const testUserPassword = await secretsManager.getSecretValue({ | |
SecretId: process.env.COGNITO_TEST_USER_PASSWORD_SECRETS_MANAGER_ARN, | |
}); | |
return testUserPassword.SecretString || ""; | |
}; | |
const authenticate = async function () { | |
const result = await cognitoIdp.initiateAuth({ | |
AuthFlow: "USER_PASSWORD_AUTH", | |
ClientId: process.env.COGNITO_CLIENT_ID, | |
AuthParameters: { | |
USERNAME: TEST_USER_NAME, | |
PASSWORD: await getTestUserPassword(), | |
}, | |
}); | |
return result.AuthenticationResult?.IdToken || ""; | |
}; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment