本文整理汇总了Python中model.Credentials.put方法的典型用法代码示例。如果您正苦于以下问题:Python Credentials.put方法的具体用法?Python Credentials.put怎么用?Python Credentials.put使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类model.Credentials
的用法示例。
在下文中一共展示了Credentials.put方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get
# 需要导入模块: from model import Credentials [as 别名]
# 或者: from model.Credentials import put [as 别名]
def get(self):
"""Handle code exchange."""
code = self.request.get('code')
if not code:
# TODO: Display error.
return None
oauth_flow = self.create_oauth_flow()
# Perform the exchange of the code. If there is a failure with exchanging
# the code, return None.
try:
creds = oauth_flow.step2_exchange(code)
except FlowExchangeError:
# TODO: Display error.
return None
users_service = util.create_service('oauth2', 'v2', creds)
# TODO: Check for errors.
user = users_service.userinfo().get().execute()
userid = user.get('id')
username = user.get('name')
# Store the credentials in the data store using the userid as the key.
# TODO: Hash the userid the same way the userToken is.
"""StorageByKeyName(Credentials, userid, 'credentials').put(creds)"""
entity = Credentials(name = username,
credentials = creds,
key_name = userid)
entity.put()
logging.info('Successfully stored credentials for user: %s', entity)
util.store_userid(self, userid)
self._perform_post_auth_tasks(userid, creds)
self.redirect('/')