本文整理汇总了Python中oauth2client._helpers._urlsafe_b64encode方法的典型用法代码示例。如果您正苦于以下问题:Python _helpers._urlsafe_b64encode方法的具体用法?Python _helpers._urlsafe_b64encode怎么用?Python _helpers._urlsafe_b64encode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类oauth2client._helpers
的用法示例。
在下文中一共展示了_helpers._urlsafe_b64encode方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: make_signed_jwt
# 需要导入模块: from oauth2client import _helpers [as 别名]
# 或者: from oauth2client._helpers import _urlsafe_b64encode [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: make_signed_jwt
# 需要导入模块: from oauth2client import _helpers [as 别名]
# 或者: from oauth2client._helpers import _urlsafe_b64encode [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 = [
_helpers._urlsafe_b64encode(_helpers._json_encode(header)),
_helpers._urlsafe_b64encode(_helpers._json_encode(payload)),
]
signing_input = b'.'.join(segments)
signature = signer.sign(signing_input)
segments.append(_helpers._urlsafe_b64encode(signature))
logger.debug(str(segments))
return b'.'.join(segments)
示例3: test_valid_input_str
# 需要导入模块: from oauth2client import _helpers [as 别名]
# 或者: from oauth2client._helpers import _urlsafe_b64encode [as 别名]
def test_valid_input_str(self):
test_string = 'deadbeef'
result = _helpers._urlsafe_b64encode(test_string)
self.assertEqual(result, self.DEADBEEF_ENCODED)
示例4: test_valid_input_bytes
# 需要导入模块: from oauth2client import _helpers [as 别名]
# 或者: from oauth2client._helpers import _urlsafe_b64encode [as 别名]
def test_valid_input_bytes(self):
test_string = b'deadbeef'
result = _helpers._urlsafe_b64encode(test_string)
self.assertEqual(result, self.DEADBEEF_ENCODED)
示例5: test_valid_input_unicode
# 需要导入模块: from oauth2client import _helpers [as 别名]
# 或者: from oauth2client._helpers import _urlsafe_b64encode [as 别名]
def test_valid_input_unicode(self):
test_string = u'deadbeef'
result = _helpers._urlsafe_b64encode(test_string)
self.assertEqual(result, self.DEADBEEF_ENCODED)
示例6: _generate_assertion
# 需要导入模块: from oauth2client import _helpers [as 别名]
# 或者: from oauth2client._helpers import _urlsafe_b64encode [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
示例7: make_signed_jwt
# 需要导入模块: from oauth2client import _helpers [as 别名]
# 或者: from oauth2client._helpers import _urlsafe_b64encode [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)
示例8: test_verify_id_token_bad_tokens
# 需要导入模块: from oauth2client import _helpers [as 别名]
# 或者: from oauth2client._helpers import _urlsafe_b64encode [as 别名]
def test_verify_id_token_bad_tokens(self):
private_key = datafile('privatekey.' + self.format_)
# Wrong number of segments
self._check_jwt_failure('foo', 'Wrong number of segments')
# Not json
self._check_jwt_failure('foo.bar.baz', 'Can\'t parse token')
# Bad signature
jwt = b'.'.join([b'foo',
_helpers._urlsafe_b64encode('{"a":"b"}'),
b'baz'])
self._check_jwt_failure(jwt, 'Invalid token signature')
# No expiration
signer = self.signer.from_string(private_key)
audience = ('https:#www.googleapis.com/auth/id?client_id='
'[email protected]')
jwt = crypt.make_signed_jwt(signer, {
'aud': audience,
'iat': time.time(),
})
self._check_jwt_failure(jwt, 'No exp field in token')
# No issued at
jwt = crypt.make_signed_jwt(signer, {
'aud': 'audience',
'exp': time.time() + 400,
})
self._check_jwt_failure(jwt, 'No iat field in token')
# Too early
jwt = crypt.make_signed_jwt(signer, {
'aud': 'audience',
'iat': time.time() + 301,
'exp': time.time() + 400,
})
self._check_jwt_failure(jwt, 'Token used too early')
# Too late
jwt = crypt.make_signed_jwt(signer, {
'aud': 'audience',
'iat': time.time() - 500,
'exp': time.time() - 301,
})
self._check_jwt_failure(jwt, 'Token used too late')
# Wrong target
jwt = crypt.make_signed_jwt(signer, {
'aud': 'somebody else',
'iat': time.time(),
'exp': time.time() + 300,
})
self._check_jwt_failure(jwt, 'Wrong recipient')