How to use the amazon-cognito-identity-js.AuthenticationDetails function in amazon-cognito-identity-js

To help you get started, we’ve selected a few amazon-cognito-identity-js examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github serverless / serverless-graphql / app-backend / appsync / dynamo-elasticsearch / generate-token.js View on Github external
Password: '...', // password created in cognito pool
};

const poolData = {
  UserPoolId: '...', // Your user pool id here
  ClientId: '...', // Your client id here
};

const userPool = new CognitoUserPool(poolData);

const userData = {
  Username: '...', // username created in cognito pool
  Pool: userPool,
};

const authenticationDetails = new AuthenticationDetails(authenticationData);
const cognitoUser = new CognitoUser(userData);

cognitoUser.authenticateUser(authenticationDetails, {
  onSuccess: function(result) {
    // console.log("access token = " + result.getAccessToken().getJwtToken());
    console.log(`id token = ${result.getIdToken().getJwtToken()}`);
  },

  onFailure: function(err) {
    console.log(err);
  },

  newPasswordRequired: function(userAttributes) {
    // User was signed up by an admin and must provide new
    // password and required attributes, if any, to complete
    // authentication.
github innFactory / aws-session-token-gui / app / actions / user.js View on Github external
function _cognitoLogin(user, dispatch, getState) {
    let {config} = getState();
  dispatch({type: SET_USER, data: {...user}});

  const authenticationData = {
        Username: user.userName,
        Password: user.password,
    };
    const authenticationDetails = new AuthenticationDetails(authenticationData);
    const poolData = {
        UserPoolId: config.userPoolId,
        ClientId: config.clientId
    };
    const userPool = new CognitoUserPool(poolData);
    const userData = {
        Username: user.userName,
        Pool: userPool
    };
    const cognitoUser = new CognitoUser(userData);
    cognitoUser.authenticateUser(authenticationDetails, {
        onSuccess: (result) => {
            // login was successful: store aws idToken to state
            dispatch({type: "SET_ID_TOKEN", token: result.getIdToken().getJwtToken()});
            dispatch({type: "SET_ACCESS_TOKEN", token: result.getAccessToken().getJwtToken()});
        },
github AnomalyInnovations / aws-api-gateway-cli-test / index.js View on Github external
UserPoolId: argv.userPoolId,
    ClientId: argv.appClientId
  };

  AWS.config.update({ region: argv.cognitoRegion });
  var userPool = new AWSCognito.CognitoUserPool(poolData);

  var userData = {
    Username: argv.username,
    Pool: userPool
  };
  var authenticationData = {
    Username: argv.username,
    Password: argv.password
  };
  var authenticationDetails = new AWSCognito.AuthenticationDetails(
    authenticationData
  );

  var cognitoUser = new AWSCognito.CognitoUser(userData);

  console.log("Authenticating with User Pool");

  cognitoUser.authenticateUser(authenticationDetails, {
    onSuccess: function(result) {
      callback({
        idToken: result.getIdToken().getJwtToken(),
        accessToken: result.getAccessToken().getJwtToken()
      });
    },
    onFailure: function(err) {
      console.log(err.message ? err.message : err);
github syl20lego / insomnia-plugin-aws-cognito-token / src / plugin.js View on Github external
const session = ({ Username, Password, UserPoolId, ClientId, TokenType }) => new Promise((resolve, reject) => {
  new AWSCognito.CognitoUser({
    Username,
    Pool: new AWSCognito.CognitoUserPool({
      UserPoolId,
      ClientId,
    })
  }).authenticateUser(new AWSCognito.AuthenticationDetails({
    Username,
    Password
  }),
  {
    onSuccess: result => {
      TokenType === 'id' ? resolve(result.idToken.jwtToken): resolve(result.accessToken.jwtToken);
    },
    onFailure: error => {
      console.log(error);
      reject(error);
    }
  });
});
github awslabs / aws-cognito-angular-quickstart / src / app / service / user-login.service.ts View on Github external
authenticate(username: string, password: string, callback: CognitoCallback) {
        console.log("UserLoginService: starting the authentication");

        let authenticationData = {
            Username: username,
            Password: password,
        };
        let authenticationDetails = new AuthenticationDetails(authenticationData);

        let userData = {
            Username: username,
            Pool: this.cognitoUtil.getUserPool()
        };

        console.log("UserLoginService: Params set...Authenticating the user");
        let cognitoUser = new CognitoUser(userData);
        console.log("UserLoginService: config is " + AWS.config);
        cognitoUser.authenticateUser(authenticationDetails, {
            newPasswordRequired: (userAttributes, requiredAttributes) => callback.cognitoCallback(`User needs to set password.`, null),
            onSuccess: result => this.onLoginSuccess(callback, result),
            onFailure: err => this.onLoginError(callback, err),
            mfaRequired: (challengeName, challengeParameters) => {
                callback.handleMFAStep(challengeName, challengeParameters, (confirmationCode: string) => {
                    cognitoUser.sendMFACode(confirmationCode, {
github awslabs / aws-api-gateway-developer-portal / dev-portal / src / js / devportal.js View on Github external
export function login(email, password) {
    const authenticationData = {
        Username: email,
        Password: password
    }
    const authenticationDetails = new AuthenticationDetails(authenticationData)
    const userPool = new CognitoUserPool(poolData)
    const userData = {
        Username: email,
        Pool: userPool
    }

    const cognitoUser = new CognitoUser(userData)
    cognitoUser.authenticateUser(authenticationDetails, {
        onSuccess: function(result) {
            console.log('access token + ' + result.getAccessToken().getJwtToken())

            const cognitoLoginKey = 'cognito-idp.' + cognitoRegion + '.amazonaws.com/' + cognitoUserPoolId
            const Logins = {}
            Logins[cognitoLoginKey] = result.getIdToken().getJwtToken()
            AWS.config.credentials = new AWS.CognitoIdentityCredentials({IdentityPoolId: identityPoolId, Logins: Logins})
github AnomalyInnovations / serverless-stack-demo-client / src / containers / Login.js View on Github external
login(email, password) {
    const userPool = new CognitoUserPool({
      UserPoolId: config.cognito.USER_POOL_ID,
      ClientId: config.cognito.APP_CLIENT_ID
    });
    const user = new CognitoUser({ Username: email, Pool: userPool });
    const authenticationData = { Username: email, Password: password };
    const authenticationDetails = new AuthenticationDetails(authenticationData);

    return new Promise((resolve, reject) =>
      user.authenticateUser(authenticationDetails, {
        onSuccess: result => resolve(),
        onFailure: err => reject(err)
      })
    );
  }
github frsechet / cognito-user-pool / src / login.js View on Github external
module.exports = (poolData, body, cb) => {

  const userPool = new AmazonCognitoIdentity.CognitoUserPool(poolData);

  const username = body.username;
  const password = body.password;

  let authenticationData = {
    Username : username,
    Password : password
  };
  let authenticationDetails = new AmazonCognitoIdentity.AuthenticationDetails(authenticationData);
  let userData = {
    Username : username,
    Pool : userPool
  };

  let cognitoUser = new AmazonCognitoIdentity.CognitoUser(userData);

  return cognitoUser.authenticateUser(authenticationDetails, {
    onSuccess: function (res) {
      let data = {
        refreshToken: res.getRefreshToken().getToken(),
        accessToken: res.getAccessToken().getJwtToken(),
        accessTokenExpiresAt: res.getAccessToken().getExpiration(),
        idToken: res.getIdToken().getJwtToken(),
        idTokenExpiresAt: res.getAccessToken().getExpiration()
      };
github ctx-core / ctx-core / packages / cognito / lib.ts View on Github external
export async function authenticateUser(Username:string, Password:string):Promise {
	const AuthenticationDetails__ = new AuthenticationDetails({
		Username,
		Password,
	})
	const user = _user__cognito(Username)
	return new Promise((resolve, reject)=>{
		user.authenticateUser(AuthenticationDetails__, {
			onSuccess(session:CognitoUserSession) {
				resolve({ session, user })
			},
			onFailure(err) {
				reject(err.message || JSON.stringify(err))
			},
		})
	})
}
export async function getUserAttributes(user:CognitoUser):Promise {
github ConduitVC / aws-utils / packages / aws-utils / bin / createCognitoUser.js View on Github external
const createUser = async (cognito, { userPoolId, username, password }) => {
  const tempPassword = uuid();
  await cognito
    .adminCreateUser({
      UserPoolId: userPoolId,
      Username: username,
      MessageAction: 'SUPPRESS',
      TemporaryPassword: tempPassword,
      UserAttributes: [
        { Name: 'email_verified', Value: 'True' },
        { Name: 'email', Value: 'user@example.com' },
      ],
    })
    .promise();

  const authDetails = new AmazonCognitoIdentity.AuthenticationDetails({
    Username: username,
    Password: tempPassword,
  });
  const user = new AmazonCognitoIdentity.CognitoUser({
    Username: username,
    Pool: userPool,
  });
  user.setAuthenticationFlowType('USER_SRP_AUTH');

  await new Promise((accept, reject) => {
    user.authenticateUser(authDetails, {
      onSuccess: () => {
        accept(user);
      },
      onFailure: err => {
        reject(err);