Esempio n. 1
0
def _get_user_id_from_id_token(jwt):
    """
    Attempt to get Google+ User ID from ID Token.

    First calls endpoints.get_current_user() to assure there is a valid user.
    If it has already been called, there will be environment variables set
    so this will be a low-cost call (no network overhead).

    After this, we know the JWT is valid and can simply parse a value from it.

    :param str jwt: The JSON web token which acts as the ID Token.

    :rtype: unicode
    :return: The Google+ user ID or None if it can't be determined
             from the JWT.
    """
    if endpoints.get_current_user() is None:
        return

    segments = jwt.split('.')
    if len(segments) != 3:
        return

    # noinspection PyProtectedMember
    json_body = users_id_token._urlsafe_b64decode(segments[1])
    # noinspection PyBroadException
    try:
        parsed = json.loads(json_body)
        return parsed.get('sub')
    except:
        pass
Esempio n. 2
0
def _get_user_id_from_id_token(jwt):
    """Attempts to get Google+ User ID from ID Token.

    First calls endpoints.get_current_user() to assure there is a valid user.
    If it has already been called, there will be environment variables set
    so this will be a low-cost call (no network overhead).

    After this, we know the JWT is valid and can simply parse a value from it.

    Args:
      jwt: String, containing the JSON web token which acts as the ID Token.

    Returns:
      String containing the Google+ user ID or None if it can't be determined
        from the JWT.
    """
    if endpoints.get_current_user() is None:
        return

    segments = jwt.split('.')
    if len(segments) != 3:
        return

    try:
        json_body = users_id_token._urlsafe_b64decode(segments[1])
        parsed = json.loads(json_body)
        return parsed.get('sub')
    except:
        pass
Esempio n. 3
0
 def GetSampleBody(self):
   split_token = self._SAMPLE_TOKEN.split('.')
   body = json.loads(users_id_token._urlsafe_b64decode(split_token[1]))
   return body