本文整理汇总了Python中oauth2client.contrib.appengine.AppAssertionCredentials类的典型用法代码示例。如果您正苦于以下问题:Python AppAssertionCredentials类的具体用法?Python AppAssertionCredentials怎么用?Python AppAssertionCredentials使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了AppAssertionCredentials类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get
def get(self):
scope = 'https://www.googleapis.com/auth/userinfo.email'
credentials = AppAssertionCredentials(scope)
http = credentials.authorize(Http())
DISCOVERY_URL = (
'https://monorail-prod.appspot.com/_ah/api/discovery/v1/apis/'
'{api}/{apiVersion}/rest'
)
monorail = build(
'monorail', 'v1',
discoveryServiceUrl=DISCOVERY_URL,
http=http
)
if self.request.get('site') == 'issues':
urlfetch.set_default_fetch_deadline(10)
self.response.headers.add_header("Access-Control-Allow-Origin", "*")
result = monorail.issues().list(projectId='chromium', q=self.request.get('q'), can='open').execute()
self.response.write(json.dumps(result))
elif self.request.get('site') == 'issue':
urlfetch.set_default_fetch_deadline(10)
self.response.headers.add_header("Access-Control-Allow-Origin", "*")
result = monorail.issues().get(projectId='chromium', issueId=self.request.get('issueId')).execute()
self.response.write(json.dumps(result))
elif self.request.get('site') == 'comments':
urlfetch.set_default_fetch_deadline(10)
self.response.headers.add_header("Access-Control-Allow-Origin", "*")
result = monorail.issues().comments().list(projectId='chromium', issueId=self.request.get('issueId')).execute()
self.response.write(json.dumps(result))
示例2: get
def get(self):
if self.request.get('site') == 'issues':
url = "https://bugs.chromium.org/p/chromium/issues/csv?"
for item in self.request.GET.items():
if item[0] != 'site':
url += item[0] +'=' + item[1] + '&'
scope = 'https://www.googleapis.com/auth/userinfo.email'
credentials = AppAssertionCredentials(scope)
http = credentials.authorize(Http())
DISCOVERY_URL = (
'https://monorail-prod.appspot.com/_ah/api/discovery/v1/apis/'
'{api}/{apiVersion}/rest'
)
monorail = build(
'monorail', 'v1',
discoveryServiceUrl=DISCOVERY_URL,
http=http
)
urlfetch.set_default_fetch_deadline(10)
self.response.headers.add_header("Access-Control-Allow-Origin", "*")
result = monorail.issues().list(projectId='chromium', owner=self.request.get('q')[6:], can='open').execute()
self.response.write(json.dumps(result))
示例3: test_get_access_token
def test_get_access_token(self):
app_identity_stub = self.AppIdentityStubImpl()
apiproxy_stub_map.apiproxy = apiproxy_stub_map.APIProxyStubMap()
apiproxy_stub_map.apiproxy.RegisterStub("app_identity_service",
app_identity_stub)
apiproxy_stub_map.apiproxy.RegisterStub(
'memcache', memcache_stub.MemcacheServiceStub())
credentials = AppAssertionCredentials(['dummy_scope'])
token = credentials.get_access_token()
self.assertEqual('a_token_123', token.access_token)
self.assertEqual(None, token.expires_in)
示例4: test_raise_correct_type_of_exception
def test_raise_correct_type_of_exception(self):
app_identity_stub = self.ErroringAppIdentityStubImpl()
apiproxy_stub_map.apiproxy = apiproxy_stub_map.APIProxyStubMap()
apiproxy_stub_map.apiproxy.RegisterStub('app_identity_service',
app_identity_stub)
apiproxy_stub_map.apiproxy.RegisterStub(
'memcache', memcache_stub.MemcacheServiceStub())
scope = 'http://www.googleapis.com/scope'
credentials = AppAssertionCredentials(scope)
http = httplib2.Http()
with self.assertRaises(AccessTokenRefreshError):
credentials.refresh(http)
示例5: test_service_account_email_already_set
def test_service_account_email_already_set(self):
acct_name = '[email protected]'
credentials = AppAssertionCredentials([])
credentials._service_account_email = acct_name
app_identity_stub = self.AppIdentityStubImpl(svc_acct=acct_name)
apiproxy_stub_map.apiproxy = apiproxy_stub_map.APIProxyStubMap()
apiproxy_stub_map.apiproxy.RegisterStub('app_identity_service',
app_identity_stub)
self.assertEqual(app_identity_stub._get_acct_name_calls, 0)
self.assertEqual(credentials.service_account_email, acct_name)
self.assertEqual(app_identity_stub._get_acct_name_calls, 0)
示例6: test_sign_blob
def test_sign_blob(self):
key_name = b'1234567890'
sig_bytes = b'himom'
app_identity_stub = self.AppIdentityStubImpl(
key_name=key_name, sig_bytes=sig_bytes)
apiproxy_stub_map.apiproxy = apiproxy_stub_map.APIProxyStubMap()
apiproxy_stub_map.apiproxy.RegisterStub('app_identity_service',
app_identity_stub)
credentials = AppAssertionCredentials([])
to_sign = b'blob'
self.assertEqual(app_identity_stub._sign_calls, [])
result = credentials.sign_blob(to_sign)
self.assertEqual(result, (key_name, sig_bytes))
self.assertEqual(app_identity_stub._sign_calls, [to_sign])
示例7: test_custom_service_account
def test_custom_service_account(self):
scope = "http://www.googleapis.com/scope"
account_id = "[email protected]"
with mock.patch.object(app_identity, 'get_access_token',
return_value=('a_token_456', None),
autospec=True) as get_access_token:
credentials = AppAssertionCredentials(
scope, service_account_id=account_id)
http = httplib2.Http()
credentials.refresh(http)
self.assertEqual('a_token_456', credentials.access_token)
self.assertEqual(scope, credentials.scope)
get_access_token.assert_called_once_with(
[scope], service_account_id=account_id)
示例8: test_get_access_token_on_refresh
def test_get_access_token_on_refresh(self):
app_identity_stub = self.AppIdentityStubImpl()
apiproxy_stub_map.apiproxy = apiproxy_stub_map.APIProxyStubMap()
apiproxy_stub_map.apiproxy.RegisterStub("app_identity_service",
app_identity_stub)
apiproxy_stub_map.apiproxy.RegisterStub(
'memcache', memcache_stub.MemcacheServiceStub())
scope = [
"http://www.googleapis.com/scope",
"http://www.googleapis.com/scope2"]
credentials = AppAssertionCredentials(scope)
http = httplib2.Http()
credentials.refresh(http)
self.assertEqual('a_token_123', credentials.access_token)
json = credentials.to_json()
credentials = Credentials.new_from_json(json)
self.assertEqual(
'http://www.googleapis.com/scope http://www.googleapis.com/scope2',
credentials.scope)
scope = ('http://www.googleapis.com/scope '
'http://www.googleapis.com/scope2')
credentials = AppAssertionCredentials(scope)
http = httplib2.Http()
credentials.refresh(http)
self.assertEqual('a_token_123', credentials.access_token)
self.assertEqual(
'http://www.googleapis.com/scope http://www.googleapis.com/scope2',
credentials.scope)
示例9: generate_jwt
def generate_jwt():
"""Generates a signed JSON Web Token using a service account."""
credentials = AppAssertionCredentials(
'https://www.googleapis.com/auth/iam')
http_auth = credentials.authorize(httplib2.Http())
service = googleapiclient.discovery.build(
serviceName='iam', version='v1', http=http_auth)
now = int(time.time())
header_json = json.dumps({
"typ": "JWT",
"alg": "RS256"})
payload_json = json.dumps({
'iat': now,
# expires after one hour.
"exp": now + 3600,
# iss is the service account email.
'iss': SERVICE_ACCOUNT_EMAIL,
'sub': SERVICE_ACCOUNT_EMAIL,
# aud must match 'audience' in the security configuration in your
# swagger spec.It can be any string.
'aud': 'echo.endpoints.sample.google.com',
"email": SERVICE_ACCOUNT_EMAIL
})
headerAndPayload = '{}.{}'.format(
base64.urlsafe_b64encode(header_json),
base64.urlsafe_b64encode(payload_json))
slist = service.projects().serviceAccounts().signBlob(
name=SERVICE_ACCOUNT,
body={'bytesToSign': base64.b64encode(headerAndPayload)})
res = slist.execute()
signature = base64.urlsafe_b64encode(
base64.decodestring(res['signature']))
signed_jwt = '{}.{}'.format(headerAndPayload, signature)
return signed_jwt
示例10: generate_jwt
def generate_jwt():
"""Generates a signed JSON Web Token using a service account."""
credentials = AppAssertionCredentials("https://www.googleapis.com/auth/iam")
http_auth = credentials.authorize(httplib2.Http())
service = build(serviceName="iam", version="v1", http=http_auth)
now = int(time.time())
header_json = json.dumps({"typ": "JWT", "alg": "RS256"})
payload_json = json.dumps(
{
"iat": now,
# expires after one hour.
"exp": now + 3600,
# iss is the service account email.
"iss": SERVICE_ACCOUNT_EMAIL,
"sub": SERVICE_ACCOUNT_EMAIL,
# aud must match 'audience' in the security configuration in your
# swagger spec.It can be any string.
"aud": "echo.endpoints.sample.google.com",
"email": SERVICE_ACCOUNT_EMAIL,
}
)
headerAndPayload = "{}.{}".format(base64.urlsafe_b64encode(header_json), base64.urlsafe_b64encode(payload_json))
slist = (
service.projects()
.serviceAccounts()
.signBlob(name=SERVICE_ACCOUNT, body={"bytesToSign": base64.b64encode(headerAndPayload)})
)
res = slist.execute()
signature = base64.urlsafe_b64encode(base64.decodestring(res["signature"]))
signed_jwt = "{}.{}".format(headerAndPayload, signature)
return signed_jwt
示例11: auth_bq
def auth_bq(self):
credentials = AppAssertionCredentials(scope=SCOPE)
http = credentials.authorize(httplib2.Http())
bigquery = build('bigquery', 'v2', http=http)
return bigquery
示例12: test_create_scoped
def test_create_scoped(self):
credentials = AppAssertionCredentials([])
new_credentials = credentials.create_scoped(['dummy_scope'])
self.assertNotEqual(credentials, new_credentials)
self.assertTrue(isinstance(new_credentials, AppAssertionCredentials))
self.assertEqual('dummy_scope', new_credentials.scope)
示例13: test_create_scoped_required_with_scopes
def test_create_scoped_required_with_scopes(self):
credentials = AppAssertionCredentials(['dummy_scope'])
self.assertFalse(credentials.create_scoped_required())
示例14: test_create_scoped_required_without_scopes
def test_create_scoped_required_without_scopes(self):
credentials = AppAssertionCredentials([])
self.assertTrue(credentials.create_scoped_required())
示例15: get
def get(self):
credentials = AppAssertionCredentials("https://www.googleapis.com/auth/calendar.readonly")
http_auth = credentials.authorize(Http())
cal_service = discovery.build('calendar', 'v3', http=http_auth)
service_settings = ServiceSettings.query().get()
if not service_settings:
service_settings = ServiceSettings()
next_sync_token = service_settings.cal_sync_token
cal_events = []
if next_sync_token:
now = None
else:
now = strict_rfc3339.now_to_rfc3339_utcoffset()
try:
events_result = cal_service.events().list(calendarId="[email protected]", timeMin=now,
syncToken=next_sync_token).execute()
except:
service_settings.cal_sync_token = None
service_settings.put()
raise
cal_events += events_result.get('items', [])
next_page_token = events_result.get('nextPageToken', None)
while next_page_token:
events_result = cal_service.events().list(calendarId="[email protected]", timeMin=now,
syncToken=next_sync_token, pageToken=next_page_token).execute()
cal_events += events_result.get('items', [])
next_page_token = events_result.get('nextPageToken', None)
next_sync_token = events_result.get("nextSyncToken", None)
service_settings.cal_sync_token = next_sync_token
service_settings.put()
for cal_event in cal_events:
cal_id = cal_event.get("id")
event = Event.query().filter(Event.cal_id == cal_id).get()
if event:
q = taskqueue.Queue('default')
for task in event.tasks:
q.delete_tasks(taskqueue.Task(name=task))
event.tasks = []
if cal_event.get("status") == "cancelled":
event.key.delete()
logging.info("Event deleted: %s", event)
continue
else:
event = Event(cal_id=cal_id)
event.put()
summary = cal_event.get("summary")
description = cal_event.get("description")
start = cal_event.get("start")
end = cal_event.get("end")
start = parse_date_time(start.get("date"), start.get("dateTime"))
end = parse_date_time(end.get("date"), end.get("dateTime"))
event.summary = summary
event.description = description
event.start = start
event.end = end
set_event_reminders(event)
event.put()
logging.info("New event created: %s", event)