How to use the amazon-cognito-identity-js.CognitoRefreshToken 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 frsechet / cognito-user-pool / src / profileEditPhoneNumber.js View on Github external
module.exports = (poolData, body, cb) => {

  const userPool = new AmazonCognitoIdentity.CognitoUserPool(poolData);

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

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

  let cognitoUser = new AmazonCognitoIdentity.CognitoUser(userData);

  // refresh the user session before anything else
  return cognitoUser.refreshSession(refreshToken, function(err, userSession) {
    if (err) {
      return cb(err);
    }
    cognitoUser.signInUserSession = userSession;
github paulcwatts / ember-cognito / addon-test-support / utils / -mock-auth.js View on Github external
export function newSession({ idToken, refreshToken, accessToken } = {}) {
  const token = makeToken();
  return new CognitoUserSession({
    IdToken: new CognitoIdToken({ IdToken: idToken || token }),
    RefreshToken: new CognitoRefreshToken({ RefreshToken: refreshToken || token }),
    AccessToken: new CognitoAccessToken({ AccessToken: accessToken || token })
  });
}
github ElucidataInc / ElMaven / bin / index.js View on Github external
cognito_user_pool_region = body.cognito_user_pool_region;
        
        var poolData = {
            UserPoolId : cognito_user_pool,
            ClientId : cognito_client_id
        };
        var userPool = new AmazonCognitoIdentity.CognitoUserPool(poolData);
        var userData = {
            Username : email,
            Pool : userPool
        };
        
        var cognitoUser = new AmazonCognitoIdentity.CognitoUser(userData);
        var refresh_token = String(read_id_token(token_filename+"_refreshToken"))
        console.log("trying to refresh the token now..");
        var refresh_token_object = new AmazonCognitoIdentity.CognitoRefreshToken({ RefreshToken: refresh_token });
    
        cognitoUser.refreshSession(refresh_token_object, (err, session) => {
            if(err) {
                console.log("error while refreshing the token.."+err);
            } 
            else{
                write_id_token(token_filename, String(session.getIdToken().getJwtToken()));
                return;
            }
        });
        
    });
}
github frsechet / cognito-user-pool / src / passwordChange.js View on Github external
module.exports = (poolData, body, cb) => {

  const userPool = new AmazonCognitoIdentity.CognitoUserPool(poolData);

  const username = body.username;
  const oldPassword = body.oldPassword;
  const newPassword = body.newPassword;
  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);
    }

    cognitoUser.signInUserSession = userSession;
    return cognitoUser.changePassword(oldPassword, newPassword, function(err, res) {
      if (err) {
github frsechet / cognito-user-pool / src / methods / refreshSession.js View on Github external
async function refreshSession(poolData, body, cb) {

  const userPool = new AmazonCognitoIdentity.CognitoUserPool(poolData);

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

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

  const cognitoUser = new AmazonCognitoIdentity.CognitoUser(userData);

  cognitoUser.refreshSession(refreshToken, (err, res) => {
    if (err) return cb(err);

    const data = {
      refreshToken: res.getRefreshToken().getToken(),
      accessToken: res.getAccessToken().getJwtToken(),
      accessTokenExpiresAt: res.getAccessToken().getExpiration(),
      idToken: res.getIdToken().getJwtToken(),
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);
    }

    cognitoUser.signInUserSession = userSession;
    if (enableMfa === true) {
      return cognitoUser.enableMFA(function(err, res) {
github frsechet / cognito-user-pool / src / getMfa.js View on Github external
module.exports = (poolData, body, cb) => {

  const userPool = new AmazonCognitoIdentity.CognitoUserPool(poolData);

  const username = body.username;
  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);
    }
    cognitoUser.signInUserSession = userSession;

    return cognitoUser.getMFAOptions((err, res) => {
      if (err) {
github jpdillingham / SWoT / web / src / components / security / SecurityActions.js View on Github external
export const refreshSession = () => (dispatch, getState) => {
    let cognitoUser = getCognitoUser(getState().security.user);
    let sessionData = getState().security.session;
    let refreshToken = new CognitoRefreshToken({ RefreshToken: sessionData.refreshToken.token });

    return new Promise((resolve, reject) => {
        cognitoUser.refreshSession(refreshToken, function(err, result) {
            if (err) {
                dispatch(logoutAction());
                reject(err);
            }
            else {
                dispatch(refreshAction(result));
                resolve(result);
            }
        });
    });
};
github frsechet / cognito-user-pool / src / logout.js View on Github external
module.exports = (poolData, body, cb) => {

  const userPool = new AmazonCognitoIdentity.CognitoUserPool(poolData);

  const username = body.username;
  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);
    }

    cognitoUser.signInUserSession = userSession;
    return cognitoUser.globalSignOut({
      onFailure(err) {