How to use the amazon-cognito-identity-js.CognitoUserPool 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 AnomalyInnovations / aws-api-gateway-cli-test / index.js View on Github external
function authenticate(callback) {
  var poolData = {
    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");
github paulcwatts / ember-cognito / addon-test-support / index.js View on Github external
export function mockCognitoUser(userAttributes) {
  const { owner } = getContext();

  const { username } = userAttributes;
  const cognito = owner.lookup('service:cognito');
  const { poolId, clientId } = getProperties(cognito, "poolId", "clientId");
  const pool = new CognitoUserPool({ UserPoolId: poolId, ClientId: clientId });
  const user = new AWSUser({ Username: username, Pool: pool });
  const auth = MockAuth.create({ _authenticatedUser: user });

  set(cognito, 'auth', auth);
  set(cognito, 'user', MockUser.create(userAttributes));
}
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})

            AWS.config.credentials.refresh(function(error) {
github tmobile / jazz / jazz_login / index.js View on Github external
logger.warn("No password provided for user: " + event.body.username);
				return callback(JSON.stringify(errorHandler.throwInputValidationError("102", "No password provided for user: " + event.body.username + ".")));
			}

			var authenticationData = {
				Username: event.body.username.toLowerCase(),
				Password: event.body.password
			};

			var poolData = {
				UserPoolId: config.USER_POOL_ID,
				ClientId: config.CLIENT_ID
			};

			var authenticationDetails = new AWSCognito.AuthenticationDetails(authenticationData);
			var userPool = new AWSCognito.CognitoUserPool(poolData);
			var userData = {
				Username: event.body.username.toLowerCase(),
				Pool: userPool
			};

			logger.info("Authenticate against cognito for " + event.body.username);

			var cognitoUser = new AWSCognito.CognitoUser(userData);
			cognitoUser.authenticateUser(authenticationDetails, {
				onSuccess: function (result) {
					logger.info("successfully authenticated");
					return callback(null, responseObj({ "token": result.getAccessToken().getJwtToken() }, { "username": event.body.username }));
				},
				onFailure: function (err) {
					logger.error("Error while authenticating: " + JSON.stringify(err));
					return callback(JSON.stringify(errorHandler.throwInputValidationError(err.code, err.message)));
github expo / expo-starter-aws / AWSHelper.js View on Github external
getUserPool() {
    let self = this;
    return new CognitoUserPool({
      "UserPoolId": self.config['aws_user_pools_id'],
      "ClientId": self.config['aws_user_pools_web_client_id']
    });
  }
  getCurrentUser() {
github nordcloud / cognitocurl / src / cognito / clibased.ts View on Github external
const GetTokenFromInput = async (poolData: any): Promise => {
  const username = await cli.prompt("Username");
  const password = await cli.prompt("Password", { type: "hide" });
  const authenticationData = {
    Username: username,
    Password: password
  };
  const authenticationDetails = new AuthenticationDetails(authenticationData);
  const userPool = new CognitoUserPool(poolData);
  const userData = {
    Username: username,
    Pool: userPool
  };
  const cognitoUser = new CognitoUser(userData);

  return new Promise((resolve, reject) => {
    cognitoUser.authenticateUser(authenticationDetails, {
      onSuccess: function(result: any) {
        const idToken: string = result.idToken.jwtToken;
        const refreshToken: string = result.refreshToken.token;
        const idTokenTTI: number = +new Date() + 1800000; //now + 1/2 hour

        TokenStorage.add(poolData, {
          idToken,
          idTokenTTI,
github frsechet / cognito-user-pool / src / setMfa.js View on Github external
module.exports = (poolData, body, cb) => {

  const userPool = new AmazonCognitoIdentity.CognitoUserPool(poolData);

  const username = body.username;
  const enableMfa = body.enableMfa;
  const refreshToken = new AmazonCognitoIdentity.CognitoRefreshToken({RefreshToken: body.refreshToken});

  const userData = {
    Username : username,
    Pool : userPool
  };

  let cognitoUser = new AmazonCognitoIdentity.CognitoUser(userData);

  return cognitoUser.refreshSession(refreshToken, function(err, userSession) {
    if (err) {
      return cb(err);
    }
github aws-samples / deploy-manage-microservices-on-ecs-and-fargate / user-profile-service / user-profile-service-code / routes / users.js View on Github external
var signUp = function(req, res) {
        const data = req.body

        var poolData = {
            UserPoolId: config.aws_user_pools_id,
            ClientId: config.aws_user_pools_web_client_id
        };

        var userPool = new CognitoUserPool(poolData);

        var attributeList = [];

        var dataEmail = {
            Name: 'email',
            Value: data.email
        };
        var dataFirstName = {
            Name: 'given_name',
            Value: data.first_name
        };
        var dataLastName = {
            Name: 'family_name',
            Value: data.last_name
        };