-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlegalesign.js
More file actions
38 lines (30 loc) · 1.17 KB
/
legalesign.js
File metadata and controls
38 lines (30 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import {AuthenticationDetails, CognitoUser, CognitoUserPool} from "amazon-cognito-identity-js";
const getToken = (username, password) => {
const pool = process.env.COGNITO_USER_POOL_ID;
const appClientId = process.env.COGNITO_CLIENT_ID;
if (!pool || !appClientId) {
throw new Error("COGNITO_USER_POOL_ID and COGNITO_CLIENT_ID environment variables are required");
}
if (!username || !password) {
throw new Error("LEGALESIGN_EMAIL and LEGALESIGN_PASSWORD environment variables are required");
}
const authenticationDetails = new AuthenticationDetails({
Username: username,
Password: password
});
let cognitoUser = new CognitoUser({
Username: username,
Pool: new CognitoUserPool({
UserPoolId: pool,
ClientId: appClientId
})
});
cognitoUser.setAuthenticationFlowType('USER_PASSWORD_AUTH');
return new Promise((resolve, reject) =>
cognitoUser.authenticateUser(authenticationDetails, {
onSuccess: result => resolve(result.getAccessToken().getJwtToken()),
onFailure: err => reject(err)
})
);
}
export default getToken;