How to use amazon-cognito-identity-js - 10 common examples

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 aws-amplify / amplify-js / packages / auth / __tests__ / cred-unit-test-rn.ts View on Github external
const authOptionsWithNoUserPoolId: AuthOptions = {
	userPoolId: null,
	userPoolWebClientId: 'awsUserPoolsWebClientId',
	region: 'region',
	identityPoolId: 'awsCognitoIdentityPoolId',
	mandatorySignIn: false,
};

const userPool = new CognitoUserPool({
	UserPoolId: authOptions.userPoolId,
	ClientId: authOptions.userPoolWebClientId,
});

const idToken = new CognitoIdToken({ IdToken: 'idToken' });
const accessToken = new CognitoAccessToken({ AccessToken: 'accessToken' });

const session = new CognitoUserSession({
	IdToken: idToken,
	AccessToken: accessToken,
});

const cognitoCredentialSpyon = jest
	.spyOn(CognitoIdentityCredentials.prototype, 'get')
	.mockImplementation(callback => {
		callback(null);
	});

describe('for react native', () => {
	describe('currentUserCredentials test', () => {
		test('with federated info', async () => {
			//     const auth = new Auth(authOptions);
github aws-amplify / amplify-js / packages / auth / __tests__ / cred-unit-test-rn.ts View on Github external
userPoolId: null,
	userPoolWebClientId: 'awsUserPoolsWebClientId',
	region: 'region',
	identityPoolId: 'awsCognitoIdentityPoolId',
	mandatorySignIn: false,
};

const userPool = new CognitoUserPool({
	UserPoolId: authOptions.userPoolId,
	ClientId: authOptions.userPoolWebClientId,
});

const idToken = new CognitoIdToken({ IdToken: 'idToken' });
const accessToken = new CognitoAccessToken({ AccessToken: 'accessToken' });

const session = new CognitoUserSession({
	IdToken: idToken,
	AccessToken: accessToken,
});

const cognitoCredentialSpyon = jest
	.spyOn(CognitoIdentityCredentials.prototype, 'get')
	.mockImplementation(callback => {
		callback(null);
	});

describe('for react native', () => {
	describe('currentUserCredentials test', () => {
		test('with federated info', async () => {
			//     const auth = new Auth(authOptions);

			//     const spyon = jest.spyOn(Credentials, 'currentUserCredentials');
github kangzeroo / Kangzeroos-Complete-AWS-Web-Boilerplate / Boilerplate_Frontend / App / src / api / aws / aws_cognito.js View on Github external
const p = new Promise((res, rej)=>{
		// create the `userData` object for instantiating a new `cognitoUser` object
		const userData = {
			Username: email,
			Pool: userPool
		}
		// create the `cognitoUser` object
		const cognitoUser = new CognitoUser(userData)
		// and call the `resendConfirmationCode()` of `cognitoUser`
		cognitoUser.resendConfirmationCode(function(err, result) {
					// reject promise if confirmation code failed
	        if (err) {
	          console.log(err);
		        rej(err)
						return
	        }
					// resolve if successfull
	        res()
	    })
	})
	return p
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 kangzeroo / Kangzeroos-Complete-AWS-Web-Boilerplate / App / src / api / aws / aws_cognito.js View on Github external
const p = new Promise((res, rej)=>{
		// we create an array for our attributes that we want to update, and push all `CognitoUserAttribute` objects into it
		const attributeList = []
		// loop through the `attrs` array to create our `CognitoUserAttribute` objects
		for(let a = 0; a
github kangzeroo / Kangzeroos-Complete-AWS-Web-Boilerplate / Boilerplate_Frontend / App / src / api / aws / aws_cognito.js View on Github external
const p = new Promise((res, rej)=>{
		// we create an array for our attributes that we want to update, and push all `CognitoUserAttribute` objects into it
		const attributeList = []
		// loop through the `attrs` array to create our `CognitoUserAttribute` objects
		for(let a = 0; a
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 jkettmann / universal-react-relay-starter-kit / server / graphql / auth / register.js View on Github external
return new Promise((resolve, reject) => {
    const dataEmail = { Name: 'email', Value: email }
    const dataFirstName = { Name: 'given_name', Value: firstName }
    const dataLastName = { Name: 'family_name', Value: lastName }

    const attributeList = [
      new CognitoUserAttribute(dataEmail),
      new CognitoUserAttribute(dataFirstName),
      new CognitoUserAttribute(dataLastName),
    ]

    userPool.signUp(email, password, attributeList, null, (error, result) => {
      log(error, result)
      if (error) {
        // TODO this code shouldn't know about graphql errors. refactor to use separate layers
        if (error.code === 'UsernameExistsException') {
          reject(new UserError(ERRORS.EmailAlreadyTaken))
        } else {
          reject(error)
        }
        return
      }
      resolve({ id: result.userSub, email })
    })
github jkettmann / universal-react-relay-starter-kit / server / graphql / auth / register.js View on Github external
return new Promise((resolve, reject) => {
    const dataEmail = { Name: 'email', Value: email }
    const dataFirstName = { Name: 'given_name', Value: firstName }
    const dataLastName = { Name: 'family_name', Value: lastName }

    const attributeList = [
      new CognitoUserAttribute(dataEmail),
      new CognitoUserAttribute(dataFirstName),
      new CognitoUserAttribute(dataLastName),
    ]

    userPool.signUp(email, password, attributeList, null, (error, result) => {
      log(error, result)
      if (error) {
        // TODO this code shouldn't know about graphql errors. refactor to use separate layers
        if (error.code === 'UsernameExistsException') {
          reject(new UserError(ERRORS.EmailAlreadyTaken))
        } else {
          reject(error)
        }
        return
      }
      resolve({ id: result.userSub, email })
github timroesner / WeMart / src / SignUp.js View on Github external
poolData = require('./poolData').poolData;
    } else {
        poolData = {
        UserPoolId : process.env.REACT_APP_Auth_UserPoolId,
        ClientId : process.env.REACT_APP_Auth_ClientId
      };
    }
    var userPool = new AmazonCognitoIdentity.CognitoUserPool(poolData);

    var attributeList = [];

    var dataEmail = {
        Name : 'email',
        Value : model.email
    };
    var attributeEmail = new AmazonCognitoIdentity.CognitoUserAttribute(dataEmail);
    attributeList.push(attributeEmail);

    // Necessary becuase the closure has no access to this.props
    let nestedProp = this.props;
    let self = this

    userPool.signUp(model.email, model.password, attributeList, null, function(err, result) {
        if (err) {
          toast.warn(err.message, {
            position: "top-center",
            autoClose: 4000,
            hideProgressBar: false,
            closeOnClick: true,
            pauseOnHover: true,
            draggable: true,
            });