本文整理汇总了Python中oauth2client.contrib.django_util.storage.DjangoORMStorage方法的典型用法代码示例。如果您正苦于以下问题:Python storage.DjangoORMStorage方法的具体用法?Python storage.DjangoORMStorage怎么用?Python storage.DjangoORMStorage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类oauth2client.contrib.django_util.storage
的用法示例。
在下文中一共展示了storage.DjangoORMStorage方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_storage
# 需要导入模块: from oauth2client.contrib.django_util import storage [as 别名]
# 或者: from oauth2client.contrib.django_util.storage import DjangoORMStorage [as 别名]
def get_storage(request):
""" Gets a Credentials storage object provided by the Django OAuth2 Helper
object.
Args:
request: Reference to the current request object.
Returns:
An :class:`oauth2.client.Storage` object.
"""
storage_model = oauth2_settings.storage_model
user_property = oauth2_settings.storage_model_user_property
credentials_property = oauth2_settings.storage_model_credentials_property
if storage_model:
module_name, class_name = storage_model.rsplit('.', 1)
module = importlib.import_module(module_name)
storage_model_class = getattr(module, class_name)
return storage.DjangoORMStorage(storage_model_class,
user_property,
request.user,
credentials_property)
else:
# use session
return dictionary_storage.DictionaryStorage(
request.session, key=_CREDENTIALS_KEY)
示例2: maybe_authorize
# 需要导入模块: from oauth2client.contrib.django_util import storage [as 别名]
# 或者: from oauth2client.contrib.django_util.storage import DjangoORMStorage [as 别名]
def maybe_authorize(request, redirect_url = False):
storage = DjangoORMStorage(GoogleCredentials, 'id', request.user, 'credential')
credential = storage.get()
if credential is None or credential.invalid == True:
flow = create_and_store_flow(request)
authorize_url = flow.step1_get_authorize_url()
if redirect_url:
authorize_url = add_query_param(authorize_url, 'state', redirect_url)
return (False, authorize_url)
else:
return (True, credential)
示例3: get_creds
# 需要导入模块: from oauth2client.contrib.django_util import storage [as 别名]
# 或者: from oauth2client.contrib.django_util.storage import DjangoORMStorage [as 别名]
def get_creds(request):
flow = jsonpickle.decode(request.session['flow'])
credential = flow.step2_exchange(request.GET.get('code', False))
storage = DjangoORMStorage(GoogleCredentials, 'id', request.user, 'credential')
storage.put(credential)
if request.GET.get('state', False):
return redirect(unquote_plus(request.GET.get('state')))
else:
return HttpResponse(status=200)