Update: Edited the code with the working version. You can use it to retrieve your authorization code.
I have been trying to figure out how to return the authorization code. I am new to API communication therefore I might be missing something crucial here. I am able to login but I just cant return the code. Please help me out people of exact!
Auth end point is https://start.exactonline.nl/api/oauth2/auth Token end point is https://start.exactonline.nl/api/oauth2/token
import requests
import urllib.parse
from bs4 import BeautifulSoup
user = ''
psw = ''
params = {'client_id': "",
'redirect_uri': "",
'response_type': "code",
'force_login': "1"}
url = 'https://start.exactonline.nl/api/oauth2/auth/'
token_url = 'https://start.exactonline.nl/api/oauth2/token'
with requests.session() as s:
OAuth_AccessRequest = s.get(url,params=params)
OAuthURL = OAuth_AccessRequest.url
soup = BeautifulSoup(OAuth_AccessRequest.content)
form = soup.form
login_data = {e['name']: e.get('value', '') for e in form.find_all('input', {'name': True})}
login_data.update({'UserNameField': user, 'PasswordField': psw})
login_data.update({'hf2StepLoginStep': 1})
login_url = OAuthURL.format(form.attrs['action'])
with requests.session() as s:
Actual_login = s.get(login_url, params=login_data)
Authorization_code=Actual_login.url.split("https://salesanalysisexact.herokuapp.com/?code=")[-1]
Authorization_code=urllib.parse.unquote(Authorization_code)
print (Authorization_code)
I just added the below code and I could see the redirec_uri with the authorization code. I guess I was just not making the right request type.
code_url = s.get(login_url,params=login_data)