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


Python _helpers._json_encode方法代码示例

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


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

示例1: make_signed_jwt

# 需要导入模块: from oauth2client import _helpers [as 别名]
# 或者: from oauth2client._helpers import _json_encode [as 别名]
def make_signed_jwt(signer, payload, key_id=None):
    """Make a signed JWT.

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

    Args:
        signer: crypt.Signer, Cryptographic signer.
        payload: dict, Dictionary of data to convert to JSON and then sign.
        key_id: string, (Optional) Key ID header.

    Returns:
        string, The JWT for the payload.
    """
    header = {'typ': 'JWT', 'alg': 'RS256'}
    if key_id is not None:
        header['kid'] = key_id

    segments = [
        _urlsafe_b64encode(_json_encode(header)),
        _urlsafe_b64encode(_json_encode(payload)),
    ]
    signing_input = b'.'.join(segments)

    signature = signer.sign(signing_input)
    segments.append(_urlsafe_b64encode(signature))

    logger.debug(str(segments))

    return b'.'.join(segments) 
开发者ID:0x0ece,项目名称:oscars2016,代码行数:31,代码来源:crypt.py

示例2: test_dictionary_input

# 需要导入模块: from oauth2client import _helpers [as 别名]
# 或者: from oauth2client._helpers import _json_encode [as 别名]
def test_dictionary_input(self):
        # Use only a single key since dictionary hash order
        # is non-deterministic.
        data = {u'foo': 10}
        result = _helpers._json_encode(data)
        self.assertEqual(result, '{"foo":10}') 
开发者ID:openstack,项目名称:deb-python-oauth2client,代码行数:8,代码来源:test__helpers.py

示例3: test_list_input

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

示例4: _generate_assertion

# 需要导入模块: from oauth2client import _helpers [as 别名]
# 或者: from oauth2client._helpers import _json_encode [as 别名]
def _generate_assertion(self):
        """Generate the assertion that will be used in the request."""

        header = {
            'alg': 'RS256',
            'typ': 'JWT',
            'kid': self._private_key_id
        }

        now = int(time.time())
        payload = {
            'aud': self._token_uri,
            'scope': self._scopes,
            'iat': now,
            'exp': now + _ServiceAccountCredentials.MAX_TOKEN_LIFETIME_SECS,
            'iss': self._service_account_email
        }
        payload.update(self._kwargs)

        first_segment = _urlsafe_b64encode(_json_encode(header))
        second_segment = _urlsafe_b64encode(_json_encode(payload))
        assertion_input = first_segment + b'.' + second_segment

        # Sign the assertion.
        rsa_bytes = rsa.pkcs1.sign(assertion_input, self._private_key,
                                   'SHA-256')
        signature = base64.urlsafe_b64encode(rsa_bytes).rstrip(b'=')

        return assertion_input + b'.' + signature 
开发者ID:satwikkansal,项目名称:OneClickDTU,代码行数:31,代码来源:service_account.py

示例5: make_signed_jwt

# 需要导入模块: from oauth2client import _helpers [as 别名]
# 或者: from oauth2client._helpers import _json_encode [as 别名]
def make_signed_jwt(signer, payload):
    """Make a signed JWT.

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

    Args:
        signer: crypt.Signer, Cryptographic signer.
        payload: dict, Dictionary of data to convert to JSON and then sign.

    Returns:
        string, The JWT for the payload.
    """
    header = {'typ': 'JWT', 'alg': 'RS256'}

    segments = [
      _urlsafe_b64encode(_json_encode(header)),
      _urlsafe_b64encode(_json_encode(payload)),
    ]
    signing_input = b'.'.join(segments)

    signature = signer.sign(signing_input)
    segments.append(_urlsafe_b64encode(signature))

    logger.debug(str(segments))

    return b'.'.join(segments) 
开发者ID:satwikkansal,项目名称:OneClickDTU,代码行数:28,代码来源:crypt.py


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