本文整理匯總了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)