Ejemplo n.º 1
0
    def test_online_access(self):
        redirect_uri = 'http://example.com/my-callback'
        state = {'foo': 'bar', 'baz': 3}

        correct_params = {
            "client_id": settings.GOOGLE_CLIENT_ID,
            "redirect_uri": redirect_uri,
            "scope": "openid scope1 scope2",
            "state": json.dumps(state),
            "response_type": "code",
            "openid.realm": 'http://example.com/',
            "access_type": "online",
            "approval_prompt": "force",
        }
        token_url = urlparse.urlparse(
            google.request_token_url(redirect_uri, "online", state,
                                     ['scope1', 'scope2']))
        assert_equal(token_url.scheme, 'https')
        assert_equal(token_url.netloc, 'accounts.google.com')
        assert_equal(token_url.path, '/o/oauth2/auth')
        assert_equal(
            urlparse.parse_qs(token_url.query), {
                "client_id": [settings.GOOGLE_CLIENT_ID],
                "redirect_uri": [redirect_uri],
                "scope": ["openid scope1 scope2"],
                "state": [json.dumps(state)],
                "response_type": ["code"],
                "access_type": ["online"],
                "openid.realm": ['http://example.com/'],
            })
Ejemplo n.º 2
0
def google_login(request):
    state = {
        'type': 'login',
        'next': request.GET.get('next')
    }
    return redirect(google.request_token_url(
        google_callback_url(), 'online', state, ['profile', 'email']))
Ejemplo n.º 3
0
def youtube_add_account(request):
    if 'team_slug' in request.GET:
        state = {'team_slug': request.GET['team_slug']}
    elif 'username' in request.GET:
        state = {'username': request.GET['username']}
    else:
        logging.error("youtube_add_account: Unknown owner")
        raise Http404()
    state['type'] = 'add-account'
    return redirect(google.request_token_url(
        google_callback_url(), 'offline', state,
        google.youtube_scopes()))
Ejemplo n.º 4
0
def google_login(request, next=None, confirmed=True, email=None):
    state_type = 'login'
    if confirmed:
        state_type += '-confirmed'
    state = {
        'type': state_type,
        'next': next or request.GET.get('next'),
    }
    if email is not None:
        state['email'] = email
    return redirect(google.request_token_url(
        google_callback_url(), 'online', state, ['profile', 'email']))