How to use the aws-sdk.CognitoIdentityServiceProvider function in aws-sdk

To help you get started, we’ve selected a few aws-sdk 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 cesanta / mongoose-os / fw / examples / helpers / cloudformation-helpers / aws / cognito.js View on Github external
'use strict';

const https = require("https");
const url = require("url");
const AWS = require('aws-sdk');
const cognitoidentity = new AWS.CognitoIdentity();
const cognitoidentityserviceprovider = new AWS.CognitoIdentityServiceProvider();
const SUCCESS = 'SUCCESS';
const FAILED = 'FAILED';
const UNKNOWN = {
  Error: 'Unknown operation'
};
const requestTypes = [
  'Create',
  'Update',
  'Delete'
];

// Some field are encoded as strings in CloudFormation, e.g. "true" and
// "false", so we need to convert them back to the proper type
function tr(val) {
  switch (typeof val) {
    case "string":
github voteflux / THE-APP / packages / api / flux / aws / cognito.js View on Github external
"use strict";
const aws = require('aws-sdk');
const config = require('../config');
const utils = require('../utils');
const common = {
    UserPoolId: process.env.USER_POOL_ID
};
const _identity = new aws.CognitoIdentityServiceProvider(Object.assign({}, common));
const identity = new Proxy({}, {
    get: (obj, prop) => utils.mkPromise(_identity[prop].bind(_identity))
});
module.exports = {
    // userPool,
    identity,
    _identity,
    common,
};
github awslabs / aws-data-lake-solution / source / api / services / admin / lib / user.js View on Github external
getUserPoolConfigInfo(function(err, poolinfo) {
            if (err) {
                console.log(err);
                return cb({code: 502, message: "Failed to process forgot request."}, null);
            }

            let cognitoidentityserviceprovider = new AWS.CognitoIdentityServiceProvider();
            let _password = generatedSecurePassword();
            let params = {
                ClientId: process.env.USER_POOL_CLIENT_ID,
                Username: userId
            };
            cognitoidentityserviceprovider.forgotPassword(params, function(err, data) {
                if (err) {
                    if (err.code === 'NotAuthorizedException') {
                        let params = {
                            UserPoolId: poolinfo,
                            Username: userId,
                            DesiredDeliveryMediums: ['EMAIL'],
                            MessageAction: 'RESEND',
                            TemporaryPassword: _password,
                            UserAttributes: []
                        };
github awslabs / aws-data-lake-solution / source / resources / access-validator / access-validator.js View on Github external
"Description": "Imported from AD",
                            "LastModifiedDate": "",
                            "CreationDate": ""
                        });
                    }

                    return cb(null, _result);
                }
            });

        } else {
            let params = {
              UserPoolId: process.env.USER_POOL_ID,
              Username: userId
            };
            let cognitoidentityserviceprovider = new AWS.CognitoIdentityServiceProvider(cognitoConfig);
            cognitoidentityserviceprovider.adminListGroupsForUser(params, function(err, data) {
                if (err) {
                    console.log(err);
                    return cb({code: 502, message: `Failed to list the groups that the user belongs to.`}, null);
                }

                return cb(null, data);
            });
        }

    };
github awslabs / iot-device-simulator / source / services / admin / lib / user.admin.js View on Github external
this._getUserPoolConfigInfo().then((poolinfo) => {

                let cognitoidentityserviceprovider = new AWS.CognitoIdentityServiceProvider();

                let params = {
                    UserPoolId: poolinfo,
                    Username: userId
                };
                cognitoidentityserviceprovider.adminDisableUser(params, function (err, data) {
                    if (err) {
                        Logger.error(Logger.levels.INFO, err.message);
                        Logger.error(Logger.levels.INFO, 'Error occurred while attempting to disable a user.');
                        throw err;
                    }

                    resolve(data);
                });

            }).catch((err) => {
github squidfunk / terraform-aws-cognito-auth / modules / api / lambda / src / clients / session / index.ts View on Github external
public constructor(
    protected session: Session,
    cognito = new CognitoIdentityServiceProvider({
      apiVersion: "2016-04-18"
    })
  ) {
    super(cognito)
  }
github dabit3 / full-stack-serverless-code / serverless-functions-in-depth-part-2 / amplify / backend / function / serverlessfunctionsic0a69b1cPostConfirmation / src / add-to-group.js View on Github external
exports.handler = async (event, context, callback) => {
  const cognitoidentityserviceprovider = new aws.CognitoIdentityServiceProvider({ apiVersion: '2016-04-18' });
  
  const adminEmails = ["dabit3@gmail.com", "jennifer@gmail.com"]
  
  if (adminEmails.indexOf(event.request.userAttributes.email) === -1) {
    callback(null, event)
  }
  
  const groupParams = {
    GroupName: process.env.GROUP,
    UserPoolId: event.userPoolId,
  };

  const addUserParams = {
    GroupName: process.env.GROUP,
    UserPoolId: event.userPoolId,
    Username: event.userName,
github awslabs / aws-centralized-logging / source / services / auth / index.js View on Github external
exports.handler = function(event, context) {

    LOGGER.log('DEBUG',`REQUEST RECEIVED: ${JSON.stringify(event,null,2)}`);
    const cognitoidentityserviceprovider = new AWS.CognitoIdentityServiceProvider();
    const es = new AWS.ES();
    let responseData = {};

    if (event.RequestType == "Delete" || event.RequestType == "Update" ) {
        sendResponse(event, context, "SUCCESS", responseData);
    }
    else if (event.RequestType == "Create") {

        if (event.ResourceProperties.Resource === "UUID") {
          responseData = {UUID: uuid.v4()};
          sendResponse(event, context, "SUCCESS", responseData);
        }
        else {

          let params = {
              DomainName: event.ResourceProperties.Domain,
github claudiajs / claudia / spec / util / cognito-oauth2-user-pool.js View on Github external
module.exports.destroy = function () {
	if (userPoolId) {
		const cognitoIdentityServiceProvider = new aws.CognitoIdentityServiceProvider({ region: awsRegion });
		return cognitoIdentityServiceProvider.deleteUserPool({ UserPoolId: userPoolId }).promise();
	}
};
github tmobile / jazz / core / jazz_cognito-admin-authorizer / index.js View on Github external
}
          //fake that auth succeeded to lambda's w/o principal id
          let policy = new AuthPolicy("", awsAccountId, apiOptions);
          policy.allowAllMethods();
          context.succeed(policy.build());
          return;
        } else {
          return cb("Unauthorized");
        }
      } else {
        logger.info(JSON.stringify(payload));
        //Valid token. Generate the API Gateway policy for the user
        //Always generate the policy on value of 'sub' claim and not for 'username' because username is reassignable
        //sub is UUID for a user which is never reassigned to another user.

        const cognito = new AWS.CognitoIdentityServiceProvider({
          apiVersion: '2016-04-19',
          region: config.REGION
        });

        var params = {
          AccessToken: token
        };

        cognito.getUser(params, (err, data) => {
          if (err) {
            logger.error(`cognito.getUser error: ${JSON.stringify(err)}`);
            return cb("Unauthorized");
          } else {
            logger.info(`success with cognito.getUser: ${JSON.stringify(data)}`);
            let emailAddress = _.find(data.UserAttributes, {
              "Name": "email"