def test_oauth_token(self): """oauth_token() makes a POST to /oauth/token with the appropriate headers and query params""" uaac = UAAClient('http://example.com', 'foo', False) m = Mock() uaac._request = m uaac.oauth_token('foo', 'bar', 'baz') args, kwargs = m.call_args assert args == ('/oauth/token', 'POST') assert kwargs['params'] == { 'code': 'foo', 'grant_type': 'authorization_code', 'response_type': 'token' } assert isinstance(kwargs['auth'], HTTPBasicAuth) assert kwargs['auth'].username == 'bar' assert kwargs['auth'].password == 'baz'
def oauth_login(): """Called at the end of the oauth flow. We'll receive an auth code from UAA and use it to retrieve a bearer token that we can use to actually do stuff """ uaac = UAAClient(app.config['UAA_BASE_URL'], None, verify_tls=app.config['VERIFY_TLS']) token = uaac.oauth_token(request.args['code'], app.config['UAA_CLIENT_ID'], app.config['UAA_CLIENT_SECRET']) session['UAA_TOKEN'] = token['access_token'] session['UAA_TOKEN_EXPIRES'] = datetime.utcnow() + timedelta(seconds=token['expires_in']) session['UAA_TOKEN_SCOPES'] = token['scope'].split(' ') return redirect(url_for('ui.index'))
def oauth_login(): """Called at the end of the oauth flow. We'll receive an auth code from UAA and use it to retrieve a bearer token that we can use to actually do stuff """ uaac = UAAClient(app.config['UAA_BASE_URL'], None, verify_tls=app.config['VERIFY_TLS']) token = uaac.oauth_token(request.args['code'], app.config['UAA_CLIENT_ID'], app.config['UAA_CLIENT_SECRET']) session['UAA_TOKEN'] = token['access_token'] session['UAA_TOKEN_EXPIRES'] = datetime.utcnow() + timedelta( seconds=token['expires_in']) session['UAA_TOKEN_SCOPES'] = token['scope'].split(' ') return redirect(url_for('ui.index'))