Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require('dotenv').config();
- // import {LoggedInCallback} from "../../MaximalAnalytics/src/models/cognito.service";
- var AmazonCognitoIdentity = require('amazon-cognito-identity-js');
- var CognitoUserPool = AmazonCognitoIdentity.CognitoUserPool;
- var CognitoUser = AmazonCognitoIdentity.CognitoUser;
- var CognitoUserAttribute = AmazonCognitoIdentity.CognitoUserAttribute;
- var CognitoUserSession = AmazonCognitoIdentity.CognitoUserSession;
- var AuthenticationDetails = AmazonCognitoIdentity.AuthenticationDetails;
- var _POOL_DATA = {
- UserPoolId: process.env.IDENTITY_POOL_ID,
- ClientId: process.env.CLIENT_ID
- };
- console.log("Before auth");
- function authenticate(username, password) {
- var authenticationData = {
- Username : username,
- Password : password,
- };
- var authenticationDetails = new AuthenticationDetails(authenticationData);
- var userData = {
- Username : username,
- Pool: _POOL_DATA
- };
- var cognitoUser = new CognitoUser(userData);
- cognitoUser.authenticateUser(authenticationDetails, {
- onSuccess: function (result) {
- console.log('access token + ' + result.getAccessToken().getJwtToken());
- //POTENTIAL: Region needs to be set if not already set previously elsewhere.
- // AWS.config.region = '<region>';
- //
- // AWS.config.credentials = new AWS.CognitoIdentityCredentials({
- // IdentityPoolId : '...', // your identity pool id here
- // Logins : {
- // // Change the key below according to the specific region your user pool is in.
- // 'cognito-idp.<region>.amazonaws.com/<YOUR_USER_POOL_ID>' : result.getIdToken().getJwtToken()
- // }
- // });
- // Instantiate aws sdk service objects now that the credentials have been updated.
- // example: var s3 = new AWS.S3();
- },
- onFailure: function(err) {
- alert(err);
- },
- });
- // console.log('UserLoginService: starting the authentication');
- // let authenticationData = {
- // Username: username,
- // Password: password,
- // };
- // let authenticationDetails = new AuthenticationDetails(authenticationData);
- // console.log("authenticationDetails");
- // let userData = {
- // Username: username,
- // Pool: _POOL_DATA
- // };
- // console.log('UserLoginService: Params set...Authenticating the user');
- // let cognitoUser = new CognitoUser(userData);
- // console.log(authenticationDetails);
- // cognitoUser.authenticateUser(authenticationDetails, {
- // onSuccess: function (result) {
- // console.log("Auutheeeeenti");
- //
- // let logins = {};
- // logins['cognito-idp.' + process.env.REGION + '.amazonaws.com/' + process.env.COGNITO_POOL_NAME] = result.getIdToken().getJwtToken();
- // // callback.cognitoCallback(null, null);
- // console.log("DONE");
- // },
- // onFailure: function (err) {
- // console.log("ERRRRROR");
- // console.log(err);
- // // callback.cognitoCallback(err.message, null);
- // },
- // // newPasswordRequired: function (userAttributes, requiredAttributes) {
- // // callback.cognitoCallback(null, {
- // // changePassword: true,
- // // cognitoUser: cognitoUser,
- // // userAttributes: userAttributes
- // // });
- // // },
- // // mfaRequired: function (res, res2) {
- // //
- // // },
- // // customChallenge: function (res) {
- // //
- // // }
- // });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement