Exemplo n.º 1
0
def login(request, service=None, template_name="linked_accounts/login.html"):
    next_url = request.REQUEST.get('next', settings.LOGIN_REDIRECT_URL)
    request.session[LINKED_ACCOUNTS_NEXT_KEY] = next_url
    # hint for Google which account to use
    # see http://stackoverflow.com/questions/12506380/google-oauth-login-avoid-asking-the-user-to-choose-which-account-to-use
    user_id = request.REQUEST.get('user_id', '')
    hd = request.REQUEST.get('hd', '')
    kwargs = {}
    if service:
        if service == 'google':
            extra_args = {}
            if user_id:
                extra_args['user_id'] = user_id
            if hd:
                extra_args['hd'] = hd
            if extra_args:
                kwargs['extra_settings'] = {'EXTRA_ARGUMENTS': extra_args}
        oauth_handler = get_oauth_handler(
            service,
            request=request,
            redirect=reverse('linked_accounts_complete', args=[service]),
            **kwargs
        )
        return redirect(oauth_handler.auth_url())
    return render(request, template_name, {
        'next': next_url,
        'service': service,
    })
Exemplo n.º 2
0
def auth_complete(request, service=None):
    oauth_handler = get_oauth_handler(
        service,
        request=request,
        redirect=reverse('linked_accounts_complete', args=[service])
    )
    api = False
    access_denied = (
        ('error' in request.REQUEST) and (request.REQUEST['error'] == 'access_denied')
    ) or (
        ('denied' in request.REQUEST) and (service == 'twitter')
    )

    if access_denied:
        messages.warning(request, "Access to %s account was denied by user" % service.capitalize())
        return redirect(settings.LOGIN_REDIRECT_URL)

    if request.method == 'POST':
        data = json.loads(request.raw_post_data)
        access_token = data['token']
        api = True
    else:
        access_token = oauth_handler.auth_complete()
    callback = AuthCallback()
    return callback(request, oauth_handler, access_token, api=api)
Exemplo n.º 3
0
 def get_access(self, **kwargs):
     oauth_handler = get_oauth_handler(self.service, **kwargs)
     return oauth_handler