本文整理汇总了Python中oauth2client.appengine.AppAssertionCredentials._generate_assertion方法的典型用法代码示例。如果您正苦于以下问题:Python AppAssertionCredentials._generate_assertion方法的具体用法?Python AppAssertionCredentials._generate_assertion怎么用?Python AppAssertionCredentials._generate_assertion使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类oauth2client.appengine.AppAssertionCredentials
的用法示例。
在下文中一共展示了AppAssertionCredentials._generate_assertion方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestAppAssertionCredentials
# 需要导入模块: from oauth2client.appengine import AppAssertionCredentials [as 别名]
# 或者: from oauth2client.appengine.AppAssertionCredentials import _generate_assertion [as 别名]
class TestAppAssertionCredentials(unittest.TestCase):
account_name = "[email protected]"
signature = "signature"
class AppIdentityStubImpl(apiproxy_stub.APIProxyStub):
def __init__(self):
super(TestAppAssertionCredentials.AppIdentityStubImpl, self).__init__(
'app_identity_service')
def _Dynamic_GetServiceAccountName(self, request, response):
return response.set_service_account_name(
TestAppAssertionCredentials.account_name)
def _Dynamic_SignForApp(self, request, response):
return response.set_signature_bytes(
TestAppAssertionCredentials.signature)
def setUp(self):
app_identity_stub = self.AppIdentityStubImpl()
apiproxy_stub_map.apiproxy.RegisterStub("app_identity_service",
app_identity_stub)
self.scope = "http://www.googleapis.com/scope"
self.credentials = AppAssertionCredentials(self.scope)
def test_assertion(self):
assertion = self.credentials._generate_assertion()
parts = assertion.split(".")
self.assertTrue(len(parts) == 3)
header, body, signature = [base64.b64decode(part) for part in parts]
header_dict = simplejson.loads(header)
self.assertEqual(header_dict['typ'], 'JWT')
self.assertEqual(header_dict['alg'], 'RS256')
body_dict = simplejson.loads(body)
self.assertEqual(body_dict['aud'],
'https://accounts.google.com/o/oauth2/token')
self.assertEqual(body_dict['scope'], self.scope)
self.assertEqual(body_dict['iss'], self.account_name)
issuedAt = body_dict['iat']
self.assertTrue(issuedAt > 0)
self.assertEqual(body_dict['exp'], issuedAt + 3600)
self.assertEqual(signature, self.signature)