当前位置: 首页>>代码示例>>Python>>正文


Python Storage.put方法代码示例

本文整理汇总了Python中oauth2client.contrib.django_orm.Storage.put方法的典型用法代码示例。如果您正苦于以下问题:Python Storage.put方法的具体用法?Python Storage.put怎么用?Python Storage.put使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在oauth2client.contrib.django_orm.Storage的用法示例。


在下文中一共展示了Storage.put方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: auth_granted

# 需要导入模块: from oauth2client.contrib.django_orm import Storage [as 别名]
# 或者: from oauth2client.contrib.django_orm.Storage import put [as 别名]
def auth_granted(request):
    get_params = request.GET

    try:
        if 'error' in get_params:
            raise ValueError('Error authorizing application: %s' % get_params[error])

        session_key = request.session.session_key
        session = Session.objects.get(pk = session_key)
        flow_obj = FlowModel.objects.get(session_id = session)
        flow = flow_obj.flow

        credentials = flow.step2_exchange(get_params["code"])

        http = httplib2.Http()
        http = credentials.authorize(http)

        (resp, content) = http.request("https://drchrono.com/api/users/current",
        "GET")

        data = json.loads(content.decode("utf-8"))
        print(data)

        doctor_id = data['doctor']
        doctor = Doctor(pk = doctor_id)
        doctor.save()

        storage = Storage(CredentialsModel, 'doctor_id', doctor_id, "credential")
        storage.put(credentials)

    except ValueError as err:
        print('Handling run-time error: ', err)

    return render(request, "success.html")
开发者ID:jherrr,项目名称:DrChrono_Bday_Notifications,代码行数:36,代码来源:views.py

示例2: finalize

# 需要导入模块: from oauth2client.contrib.django_orm import Storage [as 别名]
# 或者: from oauth2client.contrib.django_orm.Storage import put [as 别名]
def finalize(request):
  ac = AppCreds(user=request.user, label=request.POST['label']) 
  ac.save()
  credential = FLOW.step2_exchange(request.POST)
  internal_label = "%s-%s" % (request.user.id, request.POST['label'])
  storage = Storage(CredentialsModel, 'id', ac, 'credential')
  storage.put(credential)
  return HttpResponseRedirect("/googleaccount/")
开发者ID:Bhasmithal,项目名称:mirandum,代码行数:10,代码来源:views.py

示例3: auth_return

# 需要导入模块: from oauth2client.contrib.django_orm import Storage [as 别名]
# 或者: from oauth2client.contrib.django_orm.Storage import put [as 别名]
def auth_return(request):
  if not xsrfutil.validate_token(settings.SECRET_KEY, request.REQUEST['state'],
                                 request.user):
    return  HttpResponseBadRequest()
  credential = FLOW.step2_exchange(request.REQUEST)
  storage = Storage(CredentialsModel, 'id', request.user, 'credential')
  storage.put(credential)
  return HttpResponseRedirect("/")
开发者ID:anabelensc,项目名称:google-api-python-client,代码行数:10,代码来源:views.py

示例4: oauth2callback

# 需要导入模块: from oauth2client.contrib.django_orm import Storage [as 别名]
# 或者: from oauth2client.contrib.django_orm.Storage import put [as 别名]
def oauth2callback(request):
    if not xsrfutil.validate_token(settings.SECRET_KEY, str(request.GET['state']), request.user):
        return  HttpResponseBadRequest()

    credential = FLOW.step2_exchange(request.GET)
    storage = Storage(GoogleCredentialsModel, 'id', request.user, 'credential')
    storage.put(credential)
    redirect_url = request.session['redirect_uri_after_step2']
    return HttpResponseRedirect(redirect_url)
开发者ID:mercycorps,项目名称:TolaTables,代码行数:11,代码来源:gviews_v4.py

示例5: auth_return_view

# 需要导入模块: from oauth2client.contrib.django_orm import Storage [as 别名]
# 或者: from oauth2client.contrib.django_orm.Storage import put [as 别名]
def auth_return_view(request):
	user = request.user
	if not xsrfutil.validate_token(settings.SECRET_KEY, str(request.GET['state']), user):
		return HttpResponseBadRequest()
	FLOW = FlowModel.objects.get(id=user).flow
	credential = FLOW.step2_exchange(request.GET)
	storage = Storage(CredentialsModel, 'id', user, 'credential')
	storage.put(credential)
	return HttpResponseRedirect('/oauth2')
开发者ID:aejones89,项目名称:calendar_app,代码行数:11,代码来源:views.py

示例6: auth_return

# 需要导入模块: from oauth2client.contrib.django_orm import Storage [as 别名]
# 或者: from oauth2client.contrib.django_orm.Storage import put [as 别名]
def auth_return(request):
    user = request.user
    FLOW = FlowModel.objects.get(id=user).flow
    if not xsrfutil.validate_token(
            settings.SECRET_KEY, FLOW.params['state'], user):
        return HttpResponseBadRequest()
    credential = FLOW.step2_exchange(request.GET['code'])
    storage = Storage(CredentialsModel, 'id', user, 'credential')
    storage.put(credential)
    return HttpResponseRedirect(reverse("oauth2:index"))
开发者ID:david--wright,项目名称:bookserver,代码行数:12,代码来源:views.py

示例7: put_credentials

# 需要导入模块: from oauth2client.contrib.django_orm import Storage [as 别名]
# 或者: from oauth2client.contrib.django_orm.Storage import put [as 别名]
def put_credentials(integration_type, credentials):
    """
    Store new information for the given credentials.

    Args:
        integration_type (str): Name of the integration for which the storage should be retrieved.
        credentials (IntegrationCredentials): Updated credentials object.
    """
    integration_type = IntegrationType.objects.get(name__iexact=integration_type)
    details = IntegrationDetails.objects.get(type=integration_type.id)

    storage = Storage(IntegrationCredentials, 'details', details, 'credentials')
    storage.put(credentials)
开发者ID:HelloLily,项目名称:hellolily,代码行数:15,代码来源:credentials.py

示例8: finalize

# 需要导入模块: from oauth2client.contrib.django_orm import Storage [as 别名]
# 或者: from oauth2client.contrib.django_orm.Storage import put [as 别名]
def finalize(request):
  ac = AppCreds(user=request.user, label=request.POST['label'])
  ac.save()
  credential = FLOW.step2_exchange(request.POST)
  internal_label = "%s-%s" % (request.user.id, request.POST['label'])
  storage = Storage(CredentialsModel, 'id', ac, 'credential')
  storage.put(credential)
  if 'redir' in request.POST:
    if request.POST['redir'] == 'ffsetup':
        return HttpResponseRedirect("/fanfunding/setup?force=1")
    if request.POST['redir'] == 'subs':
        return HttpResponseRedirect("/youtubesubs/setup?force=1")
    if request.POST['redir'] == 'sponsors':
        return HttpResponseRedirect("/sponsors/setup?force=1")
  return HttpResponseRedirect("/accounts/")
开发者ID:google,项目名称:mirandum,代码行数:17,代码来源:views.py

示例9: auth_return

# 需要导入模块: from oauth2client.contrib.django_orm import Storage [as 别名]
# 或者: from oauth2client.contrib.django_orm.Storage import put [as 别名]
def auth_return(request):
  if not xsrfutil.validate_token(settings.SECRET_KEY, str(request.GET['state']),
                                 request.user.username):
    return  HttpResponseBadRequest()
  credential = FLOW.step2_exchange(request.GET)
  http = httplib2.Http()
  http = credential.authorize(http)
  resp, data = http.request("https://api.patreon.com/oauth2/api/current_user")
  data = json.loads(data)
  name = data['data']['attributes'].get("full_name") or "(unnamed)"
  internal_label = "%s-%s" % (request.user.id, name)
  ac = PatreonAppCreds(user=request.user, label=internal_label)
  ac.save()
  storage = Storage(PatreonCredentialsModel, 'id', ac, 'credential')
  storage.put(credential)
  pu = PatreonUpdate(credentials=ac, user=request.user, type="patreon")
  pu.save()
  return HttpResponseRedirect("/patreon/")
开发者ID:google,项目名称:mirandum,代码行数:20,代码来源:views.py

示例10: get_api_data

# 需要导入模块: from oauth2client.contrib.django_orm import Storage [as 别名]
# 或者: from oauth2client.contrib.django_orm.Storage import put [as 别名]
def get_api_data():
    all_data = {}

    for doctor in Doctor.objects.all():
        storage = Storage(CredentialsModel, 'doctor_id', doctor.id, 'credential')
        credentials = storage.get()

        http = httplib2.Http()
        http = credentials.authorize(http)

        storage.put(credentials)
        (resp, content) = http.request("https://drchrono.com/api/patients",
        "GET")
        data = json.loads(content.decode("utf-8"))

        all_data[doctor.id] = data

    return all_data
开发者ID:jherrr,项目名称:DrChrono_Bday_Notifications,代码行数:20,代码来源:tasks.py

示例11: auth_return

# 需要导入模块: from oauth2client.contrib.django_orm import Storage [as 别名]
# 或者: from oauth2client.contrib.django_orm.Storage import put [as 别名]
def auth_return(request):
  '''The Token generated in index() should be validated here with the same user that was used to generate the token'''
  U = User(
      username = 'example2',
      firstname= 'Bla Bla',
      lastname= 'Bla Bla',
      email = '[email protected]'
  )
  '''
  Reference:
  1. https://github.com/tschellenbach/Django-facebook/pull/564
  2. encode() is used here because in Django 1.6 or less we used to get the string automatically
  but in Django 1.7+ we have to use encode() to get the string
  '''
  if not xsrfutil.validate_token(settings.SECRET_KEY, (request.GET['state']).encode('utf-8'),
                                 U):
    print("Test: 1")
    return  HttpResponseBadRequest()
  print("Test: 2")
  credential = FLOW.step2_exchange(request.GET)
  storage = Storage(CredentialsModel, 'id', U, 'credential')
  storage.put(credential)
  return HttpResponseRedirect("/")
开发者ID:IEEEDTU,项目名称:gmail-api,代码行数:25,代码来源:views.py

示例12: get

# 需要导入模块: from oauth2client.contrib.django_orm import Storage [as 别名]
# 或者: from oauth2client.contrib.django_orm.Storage import put [as 别名]
    def get(self, request):
        error = request.GET.get('error')
        if error:
            messages.error(
                self.request,
                _('Sorry, Lily needs authorization from Google to synchronize your email account.')
            )
            return HttpResponseRedirect('/#/preferences/emailaccounts')

        # Get the state param from the request.
        state = str(request.GET.get('state'))
        # Replace %xx characters with single quotes and UTF8 decode the string.
        state = urllib.unquote(state).decode('utf8')
        # Deserialize the JSON string.
        state = anyjson.deserialize(b64decode(state))

        if not validate_token(settings.SECRET_KEY, state.get('token'), request.user.pk):
            return HttpResponseBadRequest()

        credentials = FLOW.step2_exchange(code=request.GET.get('code'))

        # Setup service to retrieve email address from Google.
        gmail_service = GmailService(credentials)
        try:
            profile = gmail_service.execute_service(gmail_service.service.users().getProfile(userId='me'))
        except HttpError as error:
            error = anyjson.loads(error.content)
            error = error.get('error', error)
            if error.get('code') == 400 and error.get('message') == 'Mail service not enabled':
                messages.error(self.request, _('Mail is not enabled for this email account.'))
            else:
                messages.error(self.request, error.get('message'))

            if not request.user.info.registration_finished:
                # User is still busy with registration, so redirect to email account setup step again.
                return HttpResponseRedirect(reverse('register_email_account_setup'))
            else:
                return HttpResponseRedirect('/#/preferences/emailaccounts')

        # Create account based on email address.
        try:
            account, created = EmailAccount.objects.get_or_create(
                owner=request.user,
                tenant_id=request.user.tenant_id,
                email_address=profile.get('emailAddress')
            )
        except EmailAccount.MultipleObjectsReturned:
            account, created = EmailAccount.objects.get_or_create(
                owner=request.user,
                tenant_id=request.user.tenant_id,
                email_address=profile.get('emailAddress'),
                is_deleted=False
            )

        # Store credentials based on new email account.
        storage = Storage(GmailCredentialsModel, 'id', account, 'credentials')
        storage.put(credentials)

        account.is_deleted = False

        if request.user.tenant.billing.is_free_plan:
            account.privacy = EmailAccount.PRIVATE

        if created:
            account.only_new = None

        account.save()

        post_intercom_event(event_name='email-account-added', user_id=request.user.id)

        if not request.user.info.registration_finished:
            # User is still busy with registration, so redirect to the next step in the flow.
            return HttpResponseRedirect(reverse('register_email_account_details'))
        else:
            return HttpResponseRedirect('/#/preferences/emailaccounts/edit/%s' % account.pk)
开发者ID:HelloLily,项目名称:hellolily,代码行数:77,代码来源:views.py

示例13: post

# 需要导入模块: from oauth2client.contrib.django_orm import Storage [as 别名]
# 或者: from oauth2client.contrib.django_orm.Storage import put [as 别名]
    def post(self, request, integration_type):
        """
        Get the authentication URL for the given integration type.
        """
        is_slack = integration_type == 'slack'

        if is_slack:
            client_id = settings.SLACK_LILY_CLIENT_ID
            client_secret = settings.SLACK_LILY_CLIENT_SECRET
        else:
            client_id = request.POST.get('client_id')
            client_secret = request.POST.get('client_secret')

        integration_context = request.POST.get('integration_context', {})

        if integration_context:
            integration_context = anyjson.loads(integration_context)

        errors = {}

        if not client_id:
            errors.update({
                'client_id': ['Please enter a valid client ID'],
            })

        if not client_secret:
            errors.update({
                'client_secret': ['Please enter a valid client secret'],
            })

        if errors:
            return HttpResponseBadRequest(anyjson.serialize(errors), content_type='application/json')

        integration_type = IntegrationType.objects.get(name__iexact=integration_type)
        redirect_uri = request.build_absolute_uri()

        params = {
            'client_id': client_id,
            'client_secret': client_secret,
            'redirect_uri': redirect_uri,
            'scope': integration_type.scope,
            'response_type': 'code',
        }

        if is_slack:
            # Save a unique identifier so we can verify the follow up request from Slack is legit.
            state = sha256('%s-%s' % (
                self.request.user.id,
                settings.SECRET_KEY
            )).hexdigest()

            params.update({'state': state})

            details, created = SlackDetails.objects.get_or_create(type=integration_type)
        else:
            details, created = IntegrationDetails.objects.get_or_create(type=integration_type)

        storage = Storage(IntegrationCredentials, 'details', details, 'credentials')

        credentials = LilyOAuthCredentials(
            client_id=client_id,
            client_secret=client_secret,
            redirect_uri=redirect_uri,
            integration_context=integration_context,
        )

        storage.put(credentials)

        auth_url = integration_type.auth_url + urllib.urlencode(params)

        response = anyjson.serialize({'url': auth_url})

        return HttpResponse(response, content_type='application/json')
开发者ID:HelloLily,项目名称:hellolily,代码行数:75,代码来源:views.py

示例14: get_access_token

# 需要导入模块: from oauth2client.contrib.django_orm import Storage [as 别名]
# 或者: from oauth2client.contrib.django_orm.Storage import put [as 别名]
def get_access_token(credentials, integration_type, code=None):
    """
    Generic function to retrieve an OAuth 2.0 access token.

    Args:
        credentials (object): Contains the OAuth 2.0 credentials needed to retrieve a token.
        integration_type (str): Name of the integration for which the credentials should be retrieved.
        code (str, optional): Authorization code which will be exchanged for an access token.

    Returns:
        credentials (object): Updated credentials with a new access token.
    """
    payload = {
        'client_id': credentials.client_id,
        'client_secret': credentials.client_secret,
    }

    if code:
        # Trade the auth code for an access token.
        payload.update({
            'grant_type': 'authorization_code',
            'redirect_uri': credentials.redirect_uri,
            'code': code
        })
    else:
        # Already authenticated once, but access token expired.
        payload.update({
            'grant_type': 'refresh_token',
            'refresh_token': credentials.refresh_token
        })

    if isinstance(integration_type, basestring):
        # Sometimes we pass just a string, so fetch the actual integration type.
        integration_type = IntegrationType.objects.get(name__iexact=integration_type)

    response = requests.post(
        url=integration_type.token_url,
        data=payload,
    )

    if response.status_code == 200:
        is_slack = integration_type.name.lower() == 'slack'
        data = response.json()

        expires = data.get('expires_in')

        credentials.access_token = data.get('access_token')
        credentials.refresh_token = data.get('refresh_token')

        if expires:
            credentials.expires = timezone.now() + timedelta(seconds=expires)

        if is_slack:
            # Store the team ID so we can use it later for authorization.
            details = SlackDetails.objects.get(type=integration_type.id)
            details.team_id = data.get('team_id')
            details.save()
        else:
            details = IntegrationDetails.objects.get(type=integration_type.id)

        storage = Storage(IntegrationCredentials, 'details', details, 'credentials')
        storage.put(credentials)

        return credentials
    else:
        return None
开发者ID:HelloLily,项目名称:hellolily,代码行数:68,代码来源:credentials.py


注:本文中的oauth2client.contrib.django_orm.Storage.put方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。