Пример #1
0
def auth(request):
    """First leg of the two stage auth process. We setup and take note"""

    request.session['causal_facebook_oauth_return_url'] = \
        request.GET.get('HTTP_REFERER', None)
    service = get_model_instance(request.user, PACKAGE)

    if not service.auth:
        auth_handler = OAuth()
        auth_handler.save()
        service.auth = auth_handler
        service.save()

    if request.is_secure():
        scheme = "https://"
    else:
        scheme = "http://"
    base_url = "%s%s" % (scheme, request.get_host(),)
    callback = "%s%s" % (base_url, reverse('causal-facebook-callback'),)
    return redirect("https://graph.facebook.com/oauth/authorize&redirect_uri=%s&scope=%s&client_id=%s" % (
            callback,
            'read_stream,offline_access,user_photos,user_photo_video_tags,user_checkins',
            service.app.auth_settings['app_id']
        )
    )
Пример #2
0
def user_login(service, cust_callback_url=None):
    """Create RequestToken to auth on user return and redirect
    user to third party url for auth."""
    try:
        oauth = _oauth(service, cust_callback_url)
        redirect_url = oauth.get_authorization_url()

        # Make sure we have an auth container
        if not service.auth:
            auth_handler = OAuth()
        else:
            auth_handler = service.auth

        # Create a new requesttoken
        new_rt = RequestToken()
        new_rt.oauth_token = oauth.request_token.key
        new_rt.oauth_token_secret = oauth.request_token.secret
        new_rt.save()
        auth_handler.request_token = new_rt
        auth_handler.save()
        if not service.auth:
            service.auth = auth_handler
            service.save()
    except tweepy.TweepError:
        return False

    # Redirect user to Twitter to authorize
    return redirect(redirect_url)
Пример #3
0
def auth(request):
    """Setup oauth details for the return call from foursquare.
    """

    request.session['causal_foursquare_oauth_return_url'] = \
           request.GET.get('HTTP_REFERER', None)
    service = get_model_instance(request.user, PACKAGE)

    if not service.auth:
        auth_handler = OAuth()
        auth_handler.save()
        service.auth = auth_handler
        service.save()

    url = "https://foursquare.com/oauth2/authenticate?client_id=%s&response_type=code&redirect_uri=%s" % (service.app.auth_settings['consumer_key'], service.app.auth_settings['return_url'])

    return redirect(url)
Пример #4
0
def auth(request):
    """We dont need a full oauth setup just a username.
    """

    service = get_model_instance(request.user, PACKAGE)
    
    if not service.auth:
        auth = OAuth()
        auth.save()
        service.auth = auth
        service.save()
        
    current_site = Site.objects.get(id=settings.SITE_ID)
    callback = reverse('causal-github-callback')
    callback = "http://%s%s" % (current_site.domain, callback,)

    return redirect('https://github.com/login/oauth/authorize?client_id=%s&redirect_uri=%s' %(
        service.app.auth_settings['api_key'],
        callback
    ))
Пример #5
0
def auth(request):
    """Prepare a oauth request by saving a record locally ready for the
    redirect from twitter."""
    
    service = get_model_instance(request.user, PACKAGE)
    
    if not service.auth:
        auth_handler = OAuth()
    else:
        auth_handler = service.auth    
    
        
    current_site = Site.objects.get(id=settings.SITE_ID)
    callback = reverse('causal-flickr-callback')
    callback = "http://%s%s" % (current_site.domain, callback,)
    consumer = Consumer(service.app.auth_settings['api_key'], service.app.auth_settings['api_secret'])
    client = Client(consumer)
    
    resp, content = client.request(service.app.auth_settings['request_url'], "POST", body='oauth_callback=%s' % (callback),
                                   headers={'Content-Type' :'application/x-www-form-urlencoded'})
    
    oauth_callback_confirmed, oauth_token, oauth_token_secret = content.split('&')
    
    new_rt = RequestToken()
    new_rt.oauth_token = oauth_token.split('=')[1]
    new_rt.oauth_token_secret = oauth_token_secret.split('=')[1]
    new_rt.save()
    
    auth_handler.request_token = new_rt
    auth_handler.save()
    if not service.auth:
        service.auth = auth_handler
        service.save()
    
    #http://www.flickr.com/services/oauth/authorize
    
    return redirect('http://www.flickr.com/services/oauth/authorize?oauth_token=%s&perms=read' %(oauth_token.split('=')[1]))