Jump to content

Authentication Issue


 Share

Recommended Posts

Hi, 
I am new In the community. I actually trying to integrate the with the accounting apis with sage. But I am getting an error at time time of getting access token.  I am getting the following 400 bad request n response.

{
"$severity": "error",
"$dataCode": "DataParsingError",
"$message": "The auth code you transmitted has an unexpected format.",
"$source": "Proxy"
}
 
What I have to do to get access token properly, I followed the step of authentication mentions in this page https://developer.sage.com/accounting/guides/authenticating/authentication/
Thanks,
Emon, Developer, Favrit AS
Link to comment
Share on other sites

Hi Favrit, thank you for your question.

From the error message it appears that you are obtaining the auth code on authenticating a sageID and the error is returned when trying to exchange the auth code for an access token. Could you provide the POST request you are making to https://oauth.accounting.sage.com/token. Please ensure that any client_id and secret are not visible.
 

Thanks

Mark

Link to comment
Share on other sites

Hi Mark, 

I have the same issue as Emon described above. Please find my POST request below. Could you please advise?

Many thanks in advance, 

Yun

url_accesstoken = "https://oauth.accounting.sage.com/token"
authorization_code= '83xxxxxxxxxca'
auth_payload = {'client_id': client_id,
'client_secret': client_secret,
'code' : authorization_code,
'grant_type' : 'authorization_code',
'redirect_uri': "https://www.more-fire.com/callback"
}

headers = {'Content-Type' : 'application/x-www-form-urlencoded'}

access_token = requests.request("POST", url_accesstoken, headers=headers, data=auth_payload)

 

The entire http request looks like this:

print(access_token.request.url)
https://oauth.accounting.sage.com/token

print(access_token.request.headers)
{'User-Agent': 'python-requests/2.25.1', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive', 'Content-Type': 'application/x-www-form-urlencoded', 'Content-Length': '254'}

print(access_token.request.body)
client_id=dfxxxxxxxc&client_secret=xxxxxxx&code=83xxxxxxx&grant_type=authorization_code&redirect_uri=https%3A%2F%2Fwww.more-fire.com%2Fcallback

Link to comment
Share on other sites

Hi @Steel, Mark@EMiliaEmilia Cheladze
I got the solution. I was doing wrong in the authorization code  while calling https://oauth.accounting.sage.com/token . I am getting the code like GB%2Fabsxxxx99, and I was not decoded the value so the I got the error,  after decoded it will be like GB/absxxxx99 and it is working now. 

Thanks, 
Emon
Link to comment
Share on other sites

Hi @Steel, Mark,

In authorization process, after expiration of access token, I can get access token using refresh token?

If after 31 days refresh token will expire. Do my customer need to re authorize after 31 days or I will get a new refresh token at the time of getting access token by refresh token with new expire date? or is there any way to keep refresh token for ever?

Thanks,
Emon, Favrit AS

 

Link to comment
Share on other sites

Hi Favrit, thanks for the update.

The refresh token is refreshed every time you exchange a refresh_token for an access_token. This means that the auth can be kept alive by exchanging refresh_tokens before they expire and preventing the need for the user to re-auth.

Thanks

Mark

  • Like 1
Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...