예제 #1
0
파일: oauth.py 프로젝트: sindhus/lastuser
def oauth_auth_success(client, redirect_uri, state, code, token=None):
    """
    Commit session and redirect to OAuth redirect URI
    """
    if client.trusted:
        save_flashed_messages()
    else:
        clear_flashed_messages()
    db.session.commit()
    if client.confidential:
        use_fragment = False
    else:
        use_fragment = True
    if token:
        redirect_to = make_redirect_url(redirect_uri, use_fragment=use_fragment, access_token=token.token,
            token_type=token.token_type, expires_in=token.validity, scope=token._scope, state=state)
    else:
        redirect_to = make_redirect_url(redirect_uri, use_fragment=use_fragment, code=code, state=state)
    if use_fragment:
        return render_template('oauth_public_redirect.html', client=client, redirect_to=redirect_to)
    else:
        response = redirect(redirect_to, code=302)
        response.headers['Cache-Control'] = 'no-cache, no-store, max-age=0, must-revalidate'
        response.headers['Pragma'] = 'no-cache'
        return response
예제 #2
0
def oauth_auth_success(client, redirect_uri, state, code, token=None):
    """
    Commit session and redirect to OAuth redirect URI
    """
    if client.trusted:
        save_flashed_messages()
    else:
        clear_flashed_messages()
    db.session.commit()
    if client.confidential:
        use_fragment = False
    else:
        use_fragment = True
    if token:
        redirect_to = make_redirect_url(redirect_uri, use_fragment=use_fragment, access_token=token.token,
            token_type=token.token_type, expires_in=token.validity, scope=token._scope, state=state)
    else:
        redirect_to = make_redirect_url(redirect_uri, use_fragment=use_fragment, code=code, state=state)
    if use_fragment:
        return render_template('oauth_public_redirect.html.jinja2', client=client, redirect_to=redirect_to)
    else:
        response = redirect(redirect_to, code=303)
        response.headers['Cache-Control'] = 'no-cache, no-store, max-age=0, must-revalidate'
        response.headers['Pragma'] = 'no-cache'
        return response
예제 #3
0
    def test_make_redirect_url(self):
        # scenario 1: straight forward splitting
        result = make_redirect_url('http://example.com/?foo=bar', foo='baz')
        expected_result = 'http://example.com/?foo=bar&foo=baz'
        self.assertEqual(result, expected_result)

        # scenario 2: with use_fragment set as True
        result = make_redirect_url('http://example.com/?foo=bar',
                                   use_fragment=True,
                                   foo='baz')
        expected_result = 'http://example.com/?foo=bar#foo=baz'
        self.assertEqual(result, expected_result)
예제 #4
0
def oauth_auth_success(client, redirect_uri, state, code):
    """
    Commit session and redirect to OAuth redirect URI
    """
    if client.trusted:
        save_flashed_messages()
    else:
        clear_flashed_messages()
    db.session.commit()
    if state is None:
        response = redirect(make_redirect_url(redirect_uri, code=code), code=302)
    else:
        response = redirect(make_redirect_url(redirect_uri, code=code, state=state), code=302)
    response.headers['Cache-Control'] = 'no-cache, no-store, max-age=0, must-revalidate'
    response.headers['Pragma'] = 'no-cache'
    return response
예제 #5
0
def oauth_auth_success(client, redirect_uri, state, code):
    """
    Commit session and redirect to OAuth redirect URI
    """
    if client.trusted:
        save_flashed_messages()
    else:
        clear_flashed_messages()
    db.session.commit()
    if state is None:
        response = redirect(make_redirect_url(redirect_uri, code=code), code=302)
    else:
        response = redirect(make_redirect_url(redirect_uri, code=code, state=state), code=302)
    response.headers['Cache-Control'] = 'no-cache, no-store, max-age=0, must-revalidate'
    response.headers['Pragma'] = 'no-cache'
    return response
예제 #6
0
def oauth_auth_error(redirect_uri, state, error, error_description=None, error_uri=None):
    """
    Auth request resulted in an error. Return to client.
    """
    params = {'error': error}
    if state is not None:
        params['state'] = state
    if error_description is not None:
        params['error_description'] = error_description
    if error_uri is not None:
        params['error_uri'] = error_uri
    clear_flashed_messages()
    response = redirect(make_redirect_url(redirect_uri, **params), code=302)
    response.headers['Cache-Control'] = 'no-cache, no-store, max-age=0, must-revalidate'
    response.headers['Pragma'] = 'no-cache'
    return response
예제 #7
0
def oauth_auth_error(redirect_uri, state, error, error_description=None, error_uri=None):
    """
    Auth request resulted in an error. Return to client.
    """
    params = {'error': error}
    if state is not None:
        params['state'] = state
    if error_description is not None:
        params['error_description'] = error_description
    if error_uri is not None:
        params['error_uri'] = error_uri
    clear_flashed_messages()
    response = redirect(make_redirect_url(redirect_uri, **params), code=302)
    response.headers['Cache-Control'] = 'no-cache, no-store, max-age=0, must-revalidate'
    response.headers['Pragma'] = 'no-cache'
    return response