docs: function putAuthUser(req, res) {
      var query;
      var update;
  
      // Check if the user is actually logged in. We should try to update info
      // for an anonymous user.
      if (!(req.user && req.user.data)) {
        res.status(401).send('Not authenticated');
  
        return;
      }
  
      // For right now, we do not allow the user to change their username if it
      // has been set before.
      if (req.user.username) {
        res.status(422).send(
          'You cannot change the user name of a registered user.');
        return;
      }
  
      // Setup and execute an update query.
      query = {
        provider: req.user.data.provider,
        idWithProvider: req.user.data.idWithProvider
      };
      update = {
        username: req.body.username
      };
  
      providerAccounts.update(query, update).exec()
        .then(function () {
  
          // Now we need to update user's data in the session. The simplest way
          // to do that is to first get the current user's data.
          return oauth.getUserFromProfile(providerAccounts, req.user.data)
            .then(function (userRecord) {
              if (!userRecord) {
                throw new Error('Could not get user record.');
              }
              // Once we have the userRecord, we try to update the session.
              if (authConfig.maintenance === 'cookie') {
                req.login(userRecord, function (error) {
                  if (error) {
                    throw error;
                  } else {
                    res.status(200).send(userRecord);
                  }
                });
              } else {
                // generate a new token
                var secrets = config.getConfig('secrets');
                var currentToken = req.headers.authorization.replace(
                  'Bearer ', '');
                var decodedToken = jwt.decode(currentToken);
  
                var expiresInMinutes = 60;
                decodedToken.data.username = userRecord.data.username;
                var newToken = generateToken(decodedToken.data,
                  expiresInMinutes,
                  secrets.authTokenSecret);
  
                userRecord.meta = userRecord.meta || {};
                userRecord.meta.token = newToken;
                userRecord.meta.expires = getExpirationTime(
                  expiresInMinutes);
  
                log.debug('getNewToken requested with: ', currentToken);
                log.debug('token decoded as :', decodedToken);
  
  
                res.status(200).send(userRecord);
              }
            });
        })
        .then(null, util.makeErrorResponder(res));
    }