本文整理汇总了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)
示例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}')
示例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]')
示例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
示例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)