def main_logic(): code = flask.request.args['code'] state = flask.request.args['state'] if state != SESSION.auth_state: raise ValueError("State does not match") auth_context = AuthenticationContext(AUTHORITY_URL, api_version=None) token_response = auth_context.acquire_token_with_authorization_code( code, REDIRECT_URI, config.RESOURCE, config.CLIENT_ID, config.CLIENT_SECRET) SESSION.headers.update({ 'Authorization': "Bearer" + token_response['accessToken'], 'User-Agent': 'adal-python-sample', 'Accept': 'application/json', 'Content-Type': 'application/json', 'return-client-request-id': 'false' }) '''endpoint = config.RESOURCE + '/' + config.API_VERSION + '/me/findMeetingTimes''' endpoint = config.RESOURCE + '/' + config.API_VERSION + '/me/calendars' graph_data = SESSION.post(endpoint, stream=False).json() print('Session' + str(graph_data)) return jsonify(graph_data)
def get_token(): code = request.args['code'] state = request.args['state'] if state != session['state']: raise ValueError("State does not match") auth_context = AuthenticationContext(AUTHORITY_URL) token_response = auth_context.acquire_token_with_authorization_code(code, REDIRECT_URI, app.config['RESOURCE'], app.config['CLIENT_ID'], app.config['CLIENT_SECRET']) session['access_token'] = token_response['accessToken'] return flask.redirect('/graphcall')
def _acquire_token(self): parsed = urlparse(self.path) code = parse_qs(parsed.query)["code"][0] state = parse_qs(parsed.query)["state"][0] cookie = Cookie.SimpleCookie(self.headers["Cookie"]) if state != cookie["auth_state"].value: raise ValueError("state does not match") auth_context = AuthenticationContext(authority_url) return auth_context.acquire_token_with_authorization_code( code, REDIRECT_URI, RESOURCE, sample_parameters["clientId"], sample_parameters["clientSecret"] )
def _acquire_token(self): parsed = urlparse(self.path) code = parse_qs(parsed.query)['code'][0] state = parse_qs(parsed.query)['state'][0] cookie = Cookie.SimpleCookie(self.headers["Cookie"]) if state != cookie['auth_state'].value: raise ValueError('state does not match') auth_context = AuthenticationContext(authority_url) return auth_context.acquire_token_with_authorization_code( code, REDIRECT_URI, RESOURCE, sample_parameters['clientId'], sample_parameters['clientSecret'])
def _aquire_token(): '''Gets the access_token with authorization code. ''' code = flask.request.args['code'] state = flask.request.args['state'] # Main ADAL logic starts. auth_context = AuthenticationContext(AUTHORITY_URL) token_response = auth_context.acquire_token_with_authorization_code( code, REDIRECT_URI, config.RESOURCE, config.CLIENT_ID, config.CLIENT_SECRET) return token_response
def _acquire_token(self): parsed = urlparse(self.path) code = parse_qs(parsed.query)['code'][0] state = parse_qs(parsed.query)['state'][0] cookie = Cookie.SimpleCookie(self.headers["Cookie"]) if state != cookie['auth_state'].value: raise ValueError('state does not match') ### Main logic begins auth_context = AuthenticationContext(authority_url, api_version=None) return auth_context.acquire_token_with_authorization_code( code, REDIRECT_URI, RESOURCE, sample_parameters['clientId'], sample_parameters['clientSecret'])
def handle_login_token(): code = request.args.get('code') state = request.args.get('state') auth_state = session.get('auth_state') if auth_state != state: return myredirect('login', code=307) redirect_uri = get_redirect_uri(request.url_root) authority_url = (AUTH_AUTHORITYURL + '/' + AUTH_TENANT) auth_context = AuthenticationContext(authority_url, api_version=None) token_response = auth_context.acquire_token_with_authorization_code(code, redirect_uri, RESOURCE, AUTH_CLIENTID, AUTH_CLIENTSECRET) session['oid'] = token_response.get('oid') session['userId'] = token_response.get('userId') session['givenName'] = token_response.get('givenName') session['familyName'] = token_response.get('familyName') session['fullName'] = '{} {}'.format(token_response.get('givenName'), token_response.get('familyName')) return myredirect('/', code=307)
def get_refresh_and_access_token(): # configure AuthenticationContext # authority URL and tenant ID are used context = AuthenticationContext(authority_url) # API call to get the token, the response is a # key-value dict token_response = context.acquire_token_with_authorization_code( authorization_code, user_parameters['redirect_uri'], azure_databricks_resource_id, user_parameters['client_id']) # you can print all the fields in the token_response for key in token_response.keys(): print(str(key) + ': ' + str(token_response[key])) # the tokens can be returned as a pair (or you can return the full # token_response) return (token_response['accessToken'], token_response['refreshToken'])
def main_logic(): code = flask.request.args['code'] state = flask.request.args['state'] if state != SESSION.auth_state: raise ValueError("State does not match") auth_context = AuthenticationContext(AUTHORITY_URL, api_version=None) token_response = auth_context.acquire_token_with_authorization_code( code, REDIRECT_URI, config.RESOURCE, config.CLIENT_ID, config.CLIENT_SECRET) SESSION.headers.update({ 'Authorization': "Bearer" + token_response['accessToken'], 'User-Agent': 'adal-python-sample', 'Accept': 'application/json', 'Content-Type': 'application/json', 'return-client-request-id': 'true' }) return flask.redirect('/graphcall')
def get_refresh_and_access_token(): # configure AuthenticationContext # authority URL and tenant ID are used authority_url = authority_host_url + user_parameters['tenant'] context = AuthenticationContext(authority_url) # Obtain the authorization code in by a HTTP request in the browser # then copy it here or, call the function above to get the authorization code authz_code = get_authorization_code() # API call to get the token, the response is a # key-value dict token_response = context.acquire_token_with_authorization_code( authz_code, user_parameters['redirect_uri'], azure_databricks_resource_id, user_parameters['clientId']) # you can print all the fields in the token_response for key in token_response.keys(): print(str(key) + ': ' + str(token_response[key])) # the tokens can be returned as a pair (or you can return the full # token_response) return (token_response['accessToken'], token_response['refreshToken'])
def acquire_token(code: str): context = AuthenticationContext( f'https://login.microsoftonline.com/{TENANT}') return context.acquire_token_with_authorization_code( code, url_for("login_callback", _external=True), RESOURCE, CLIENT, SECRET)