Get a user for a particular token
@param decodedToken
@returns {*}
775483
function getUserForToken(decodedToken) {
        var userId = decodedToken._id;
        var authToken = decodedToken.authToken;
        var cacheKey = userId + authToken;
        var conditions = {
            caller: userService.admin,
            where: { _id: userId, authToken: authToken, status: 'created' },
            findOne: true
        };
        var cachedUser;

        // if no user id or authToken, then no user
        if (!userId || !authToken) { return null; }

        // try to get user from cache, then DB
        return userCacheService.get({ key: cacheKey })
            .then(function (user) {
                cachedUser = user;
                return user ? user : userService.find(conditions);
            })
            .then(function (user) {

                // if user found in database, but not in cache, save in cache
                if (user && !cachedUser) {
                    userCacheService.set({ key: cacheKey, value: user });
                }

                // return the user
                return user;
            });
    }
54607
function readNotifyUserMessage(message, tokens) {
	message.userName = protocol.decodeString(tokens[1]);
	message.sessionId = protocol.decodeString(tokens[3]);
	message.userMessage = protocol.decodeString(tokens[5]);
}
456562
public function GetUserFromCache($UserToken, $TokenType) {
      if ($TokenType == 'name') {
         $UserNameKey = FormatString(self::USERNAME_KEY, array('Name' => md5($UserToken)));
         $UserID = Gdn::Cache()->Get($UserNameKey);
         
         if ($UserID === Gdn_Cache::CACHEOP_FAILURE) return FALSE;
         $UserToken = $UserID; $TokenType = 'userid';
      } else {
         $UserID = $UserToken;
      }
      
      if ($TokenType != 'userid') return FALSE;
      
      // Get from memcached
      $UserKey = FormatString(self::USERID_KEY, array('UserID' => $UserToken));
      $User = Gdn::Cache()->Get($UserKey);
      
      return $User;
   }
309642
public static boolean decodeGSSUPToken(Codec codec, @Sensitive byte[] token_arr,
                                           InitialContextToken gssup_tok) {
        boolean result = false;
        if (gssup_tok != null) {
            try {
                byte[] data = readGSSTokenData(GSSUPMechOID.value.substring(4), token_arr);
                if (data != null) {
                    Any a = codec.decode_value(data, InitialContextTokenHelper.type());
                    InitialContextToken token = InitialContextTokenHelper.extract(a);
                    if (token != null) {
                        gssup_tok.username = token.username;
                        gssup_tok.password = token.password;
                        gssup_tok.target_name = decodeGSSExportedName(token.target_name).getName().getBytes("UTF-8");

                        result = true;
                    }
                }
            } catch (Exception ex) {
                // do nothing, return false
            }
        }
        return result;
    }
229906
function findUserFromAccessToken(accessToken, UserModel) {

    if (!accessToken) return null;

    return UserModel.findById(accessToken.userId).then((user) => {
        if (!user) return Promise.reject('No user with this access token was found.');
        return Promise.resolve(user);
    });
}
458532
private AuthToken parseAuthorizationToken(String authHeader) {
        try {
            String tokenEncoded = authHeader.substring(11);
            return AuthTokenUtil.consumeToken(tokenEncoded);
        } catch (IllegalArgumentException e) {
            // TODO log this error
            return null;
        }
    }
616040
protected OneTimeTokenAccount decode(final OneTimeTokenAccount account) {
        val decodedSecret = tokenCredentialCipher.decode(account.getSecretKey());
        val newAccount = account.clone();
        newAccount.setSecretKey(decodedSecret);
        return newAccount;
    }
693198
function readNotifyUserAuth(message, tokens) {
	message.userName = protocol.decodeString(tokens[1]);
	message.userPassword = protocol.decodeString(tokens[3]);
	message.clientPrincipal = protocol.decodeString(tokens[5]);
	readNotifyUserHeaders(message, tokens.slice(6));
}
278931
def decode_token(token):
    
    if isinstance(token, (unicode,str)):
        return _decode_token_compact(token)

    else:
        return _decode_token_json(token)
6272
private String getUserFromToken(HiveAuthFactory authFactory, String tokenStr) throws HiveSQLException {
    return authFactory.getUserFromToken(tokenStr);
  }
645630
public static String getUserNameFromToken(String authToken) {
        if (null == authToken) {
            return null;
        }

        return authToken.split(TOKEN_SEPARATOR)[0];
    }
682783
def get_token_payload(token)

        # Attempt to decode without verifying. May raise DecodeError.
        decoded = JWT.decode token, nil, false
        payload = decoded[0]

        # At this point, we know that the token is not expired and
        # well formatted. Find out if the payload is well defined.
        if payload.nil?
          # :nocov:
          logger.error("Token payload is nil: #{token}")
          raise UNAUTHORIZED_ERROR, "Invalid token"
          # :nocov:
        end

        return payload

      rescue JWT::DecodeError => e
        logger.error("Token decode error: #{e.message}")
        raise UNAUTHORIZED_ERROR, "Invalid token"
      end
264429
function getUser(username, done) {
  return getModels(function(m) {
    return m.collections.user.findOne({ username })
      .populate("tokens")
      .populate("groups")
      .populate("leading")
      .exec(done);
  });
}
232305
function readNotifyUserHeaders(message, tokens) {
	var i;
	message.headers = {};
	for (i = 0; i < tokens.length; i = i + 4) {
		message.headers[protocol.decodeString(tokens[i + 1])] = protocol.decodeString(tokens[i + 3]);
	}
}
874748
function getToken (token, callback) {

    if (token != null &&
        token != '') {

        // Fetch token from database or cache

        if (token == 'h328hdkasjd3') {

            var record = { algorithm: 'hmac-sha-256',   // Required
                secret: '23hdkdho2893hdkjd',            // Required
                userId: 'johndoe'                       // Application-specific field
            };

            callback(record);
        }
        else {

            // Token not found

            callback({});
        }
    }
    else {

        // Invalid token request

        callback({});
    }
}
250638
async function retrieveUserFromRedis(res, auth, tokenOrEmail, config) {
  if (config.redisClient) {
    const getFromRedis = util
      .promisify(config.redisClient.get)
      .bind(config.redisClient);
    const cachedUserData = await getFromRedis(`${ns}:${tokenOrEmail}`);
    if (cachedUserData) {
      const data = JSON.parse(cachedUserData);
      const user = auth.createAuthFromData(data);
      auth.currentUser = user;
      res.locals = res.locals || {};
      res.locals.auth = auth;
      return user;
    }
  }
}
361827
function getSessionBlockchainID() {

   let userData = getUserData();
   assert(userData);
   assert(userData.coreSessionToken);

   const session = jsontokens.decodeToken(userData.coreSessionToken).payload;

   return getBlockchainIDFromSessionOrDefault(session);
}