当前位置: 首页>>代码示例>>Python>>正文


Python _helpers._urlsafe_b64decode方法代码示例

本文整理汇总了Python中oauth2client._helpers._urlsafe_b64decode方法的典型用法代码示例。如果您正苦于以下问题:Python _helpers._urlsafe_b64decode方法的具体用法?Python _helpers._urlsafe_b64decode怎么用?Python _helpers._urlsafe_b64decode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在oauth2client._helpers的用法示例。


在下文中一共展示了_helpers._urlsafe_b64decode方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: from_string

# 需要导入模块: from oauth2client import _helpers [as 别名]
# 或者: from oauth2client._helpers import _urlsafe_b64decode [as 别名]
def from_string(key_pem, is_x509_cert):
        """Construct a Verified instance from a string.

        Args:
            key_pem: string, public key in PEM format.
            is_x509_cert: bool, True if key_pem is an X509 cert, otherwise it
                          is expected to be an RSA key in PEM format.

        Returns:
            Verifier instance.
        """
        if is_x509_cert:
            key_pem = _to_bytes(key_pem)
            pemLines = key_pem.replace(b' ', b'').split()
            certDer = _urlsafe_b64decode(b''.join(pemLines[1:-1]))
            certSeq = DerSequence()
            certSeq.decode(certDer)
            tbsSeq = DerSequence()
            tbsSeq.decode(certSeq[0])
            pubkey = RSA.importKey(tbsSeq[6])
        else:
            pubkey = RSA.importKey(key_pem)
        return PyCryptoVerifier(pubkey) 
开发者ID:0x0ece,项目名称:oscars2016,代码行数:25,代码来源:_pycrypto_crypt.py

示例2: _extract_id_token

# 需要导入模块: from oauth2client import _helpers [as 别名]
# 或者: from oauth2client._helpers import _urlsafe_b64decode [as 别名]
def _extract_id_token(id_token):
    """Extract the JSON payload from a JWT.

    Does the extraction w/o checking the signature.

    Args:
        id_token: string or bytestring, OAuth 2.0 id_token.

    Returns:
        object, The deserialized JSON payload.
    """
    if type(id_token) == bytes:
        segments = id_token.split(b'.')
    else:
        segments = id_token.split(u'.')

    if len(segments) != 3:
        raise VerifyJwtTokenError(
            'Wrong number of segments in token: %s' % id_token)

    return json.loads(_from_bytes(_urlsafe_b64decode(segments[1]))) 
开发者ID:0x0ece,项目名称:oscars2016,代码行数:23,代码来源:client.py

示例3: from_string

# 需要导入模块: from oauth2client import _helpers [as 别名]
# 或者: from oauth2client._helpers import _urlsafe_b64decode [as 别名]
def from_string(key_pem, is_x509_cert):
        """Construct a Verified instance from a string.

        Args:
            key_pem: string, public key in PEM format.
            is_x509_cert: bool, True if key_pem is an X509 cert, otherwise it
                          is expected to be an RSA key in PEM format.

        Returns:
            Verifier instance.
        """
        if is_x509_cert:
            key_pem = _helpers._to_bytes(key_pem)
            pemLines = key_pem.replace(b' ', b'').split()
            certDer = _helpers._urlsafe_b64decode(b''.join(pemLines[1:-1]))
            certSeq = DerSequence()
            certSeq.decode(certDer)
            tbsSeq = DerSequence()
            tbsSeq.decode(certSeq[0])
            pubkey = RSA.importKey(tbsSeq[6])
        else:
            pubkey = RSA.importKey(key_pem)
        return PyCryptoVerifier(pubkey) 
开发者ID:taers232c,项目名称:GAMADV-XTD,代码行数:25,代码来源:_pycrypto_crypt.py

示例4: test_valid_input_str

# 需要导入模块: from oauth2client import _helpers [as 别名]
# 或者: from oauth2client._helpers import _urlsafe_b64decode [as 别名]
def test_valid_input_str(self):
        test_string = 'ZGVhZGJlZWY'
        result = _helpers._urlsafe_b64decode(test_string)
        self.assertEqual(result, self.DEADBEEF_DECODED) 
开发者ID:openstack,项目名称:deb-python-oauth2client,代码行数:6,代码来源:test__helpers.py

示例5: test_valid_input_bytes

# 需要导入模块: from oauth2client import _helpers [as 别名]
# 或者: from oauth2client._helpers import _urlsafe_b64decode [as 别名]
def test_valid_input_bytes(self):
        test_string = b'ZGVhZGJlZWY'
        result = _helpers._urlsafe_b64decode(test_string)
        self.assertEqual(result, self.DEADBEEF_DECODED) 
开发者ID:openstack,项目名称:deb-python-oauth2client,代码行数:6,代码来源:test__helpers.py

示例6: test_valid_input_unicode

# 需要导入模块: from oauth2client import _helpers [as 别名]
# 或者: from oauth2client._helpers import _urlsafe_b64decode [as 别名]
def test_valid_input_unicode(self):
        test_string = u'ZGVhZGJlZWY'
        result = _helpers._urlsafe_b64decode(test_string)
        self.assertEqual(result, self.DEADBEEF_DECODED) 
开发者ID:openstack,项目名称:deb-python-oauth2client,代码行数:6,代码来源:test__helpers.py

示例7: test_bad_input

# 需要导入模块: from oauth2client import _helpers [as 别名]
# 或者: from oauth2client._helpers import _urlsafe_b64decode [as 别名]
def test_bad_input(self):
        import binascii
        bad_string = b'+'
        with self.assertRaises((TypeError, binascii.Error)):
            _helpers._urlsafe_b64decode(bad_string) 
开发者ID:openstack,项目名称:deb-python-oauth2client,代码行数:7,代码来源:test__helpers.py

示例8: verify_signed_jwt_with_certs

# 需要导入模块: from oauth2client import _helpers [as 别名]
# 或者: from oauth2client._helpers import _urlsafe_b64decode [as 别名]
def verify_signed_jwt_with_certs(jwt, certs, audience=None):
    """Verify a JWT against public certs.

    See http://self-issued.info/docs/draft-jones-json-web-token.html.

    Args:
        jwt: string, A JWT.
        certs: dict, Dictionary where values of public keys in PEM format.
        audience: string, The audience, 'aud', that this JWT should contain. If
                  None then the JWT's 'aud' parameter is not verified.

    Returns:
        dict, The deserialized JSON payload in the JWT.

    Raises:
        AppIdentityError: if any checks are failed.
    """
    jwt = _to_bytes(jwt)

    if jwt.count(b'.') != 2:
        raise AppIdentityError(
            'Wrong number of segments in token: %s' % (jwt,))

    header, payload, signature = jwt.split(b'.')
    message_to_sign = header + b'.' + payload
    signature = _urlsafe_b64decode(signature)

    # Parse token.
    payload_bytes = _urlsafe_b64decode(payload)
    try:
        payload_dict = json.loads(_from_bytes(payload_bytes))
    except:
        raise AppIdentityError('Can\'t parse token: %s' % (payload_bytes,))

    # Verify that the signature matches the message.
    _verify_signature(message_to_sign, signature, certs.values())

    # Verify the issued at and created times in the payload.
    _verify_time_range(payload_dict)

    # Check audience.
    _check_audience(payload_dict, audience)

    return payload_dict 
开发者ID:0x0ece,项目名称:oscars2016,代码行数:46,代码来源:crypt.py

示例9: verify_signed_jwt_with_certs

# 需要导入模块: from oauth2client import _helpers [as 别名]
# 或者: from oauth2client._helpers import _urlsafe_b64decode [as 别名]
def verify_signed_jwt_with_certs(jwt, certs, audience=None):
    """Verify a JWT against public certs.

    See http://self-issued.info/docs/draft-jones-json-web-token.html.

    Args:
        jwt: string, A JWT.
        certs: dict, Dictionary where values of public keys in PEM format.
        audience: string, The audience, 'aud', that this JWT should contain. If
                  None then the JWT's 'aud' parameter is not verified.

    Returns:
        dict, The deserialized JSON payload in the JWT.

    Raises:
        AppIdentityError: if any checks are failed.
    """
    jwt = _helpers._to_bytes(jwt)

    if jwt.count(b'.') != 2:
        raise AppIdentityError(
            'Wrong number of segments in token: {0}'.format(jwt))

    header, payload, signature = jwt.split(b'.')
    message_to_sign = header + b'.' + payload
    signature = _helpers._urlsafe_b64decode(signature)

    # Parse token.
    payload_bytes = _helpers._urlsafe_b64decode(payload)
    try:
        payload_dict = json.loads(_helpers._from_bytes(payload_bytes))
    except:
        raise AppIdentityError('Can\'t parse token: {0}'.format(payload_bytes))

    # Verify that the signature matches the message.
    _verify_signature(message_to_sign, signature, certs.values())

    # Verify the issued at and created times in the payload.
    _verify_time_range(payload_dict)

    # Check audience.
    _check_audience(payload_dict, audience)

    return payload_dict 
开发者ID:taers232c,项目名称:GAMADV-XTD,代码行数:46,代码来源:crypt.py


注:本文中的oauth2client._helpers._urlsafe_b64decode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。