def callback(request): # The web browser has just completed the integration_google auth stuff and has been # sent back here for the next step. log.debug("CallbackAPI:GET - Reached GET request") # First: rebuild the flow object. flow = build_flow() log.debug("CallbackAPI:GET - Flow client id:: " + flow.client_id) # now we (the AVA app server) sends a web request directly to Google asking # for OAuth2Credentials. log.debug("CallbackAPI:GET - Attempting credential exchange") code = request.query_params['code'] log.debug("CallbackAPI:GET - Request Code:: " + code) credential = flow.step2_exchange(code) # One we have them, we store them in the session, since we don't need to keep # them very long. log.debug("CallbackAPI:GET - Attempting to store credential in session") integration_id = retrieve_temporary_flow_data_from_database(TEMP_MODEL_NAME) store_credential_in_database(MODEL_NAME, integration_id, credential) log.debug("CallbackAPI:GET - Access Token ::" + credential.access_token) log.debug("CallbackAPI:GET - Refresh Token ::" + str(credential.refresh_token)) remove_temporary_flow_data_from_database(TEMP_MODEL_NAME, integration_id) # And send the user to the next step, wherever that might be. This URL # should be updated for the next step in the process. return Response({"message": "Completed callback"}, status=status.HTTP_200_OK)
def callback(request): # The web browser has just completed the integration_google auth stuff and has been # sent back here for the next step. log.debug("CallbackAPI:GET - Reached GET request") auth_code = request.GET['code'] token = get_token_from_code(auth_code) access_token = token['access_token'] user_info = get_user_info_from_token(token['id_token']) log.debug("CallbackAPI:GET - Request Code:: " + auth_code) log.debug("CallbackAPI:GET - Attempting to store credential in session") integration_id = retrieve_temporary_flow_data_from_database( TEMP_MODEL_NAME) credential = {} credential['access_token'] = access_token credential['alias'] = user_info['upn'].split('@')[0] credential['emailAddress'] = user_info['upn'] credential['showSuccess'] = 'false' credential['showError'] = 'false' credential['pageRefresh'] = 'true' # json_credential = json.dumps(credential) store_credential_in_database(MODEL_NAME, integration_id, credential) log.debug("CallbackAPI:GET - Access Token ::" + credential['access_token']) # log.debug("CallbackAPI:GET - Refresh Token ::" + str(credential.refresh_token)) remove_temporary_flow_data_from_database(TEMP_MODEL_NAME, integration_id) # And send the user to the next step, wherever that might be. This URL # should be updated for the next step in the process. return Response({"message": "Completed callback"}, status=status.HTTP_200_OK)
def callback(request): # The web browser has just completed the integration_google auth stuff and has been # sent back here for the next step. log.debug("CallbackAPI:GET - Reached GET request") auth_code = request.GET['code'] token = get_token_from_code(auth_code) access_token = token['access_token'] user_info = get_user_info_from_token(token['id_token']) log.debug("CallbackAPI:GET - Request Code:: " + auth_code) log.debug("CallbackAPI:GET - Attempting to store credential in session") integration_id = retrieve_temporary_flow_data_from_database(TEMP_MODEL_NAME) credential = {} credential['access_token'] = access_token credential['alias'] = user_info['upn'].split('@')[0] credential['emailAddress'] = user_info['upn'] credential['showSuccess'] = 'false' credential['showError'] = 'false' credential['pageRefresh'] = 'true' # json_credential = json.dumps(credential) store_credential_in_database(MODEL_NAME, integration_id, credential) log.debug("CallbackAPI:GET - Access Token ::" + credential['access_token']) # log.debug("CallbackAPI:GET - Refresh Token ::" + str(credential.refresh_token)) remove_temporary_flow_data_from_database(TEMP_MODEL_NAME, integration_id) # And send the user to the next step, wherever that might be. This URL # should be updated for the next step in the process. return Response({"message": "Completed callback"}, status=status.HTTP_200_OK)