In OAuth, access_token value can't pass in server.js file

Hi team,

We are facing an issue related to the Freshdesk OAuth access_token. I want to do authorize my app with OAuth 2.0 (third-party applications) after that I had an access_token, use the Request Method to pass access_token value by including the isOAuth parameter in the options. ‘Authorization’: "Bearer " + '<%= access_token %>'
but when i pass this access_token value in server.js file but it is not working it gaves error Unauthorized

how can i pass access_token value in server.js file? how to fix that issue. Is there any way to fix this issue?

freshdesk OAuth 2.0
https://developers.freshdesk.com/v2/docs/oauth/

App code:
server.js link
iparams.html link

Looking forward to your reply.

Hi @mirza_has,

To enable the platform to substitute access_token, quoting the documentation

You must use $request to make OAuth requests from the serverless component of the app to the third-party domain by including the isOAuth parameter in the options. Use the access_token variable to access the token

In the attached server.js link, $request is not used along with isOAuth parameter, can you address this and let us know if you are still facing the issue.

1 Like

Hi @Raghu_Murugesan

Thanks for your reply… it is working use $request in Request Method.

but I am facing an Freshdesk OAuth refresh_token.I want to do authorize my app Oauth after that I had an refresh_token, use the Request Method to refresh_token value in body parameter by including the isOAuth parameter ‘refresh_token’:’<%= refresh_token %>’, but it is not working it gaves error invalid_grant.

how can i pass refresh_token value in iparams.html file?how to fix that issue. Is there any way to fix this issue?

freshdesk OAuth 2.0
https://developers.freshdesk.com/v2/docs/oauth/

App code:
iparams.html link

Looking forward to your reply.

Hi @mirza_has,

I hope you are trying the get the new access token once/if it is expired, you can reauthorize the app from the gallery using the settings icon :gear: of the app, and also platform automatically updates the access_token during the case of expiry using refresh_token. Let us know if this for some other use case.

Hi @Raghu_Murugesan

Thanks for your reply.

I reauthorize my freshdesk app from the settings reauthorize icon :old_key: : of the app but still my app is not working due to access token expired.

Hi @mirza_has,

can you share the app id - How to obtain App ID from the Developer Portal?

Hi @Raghu_Murugesan

yes sure i deploy a custom app in freshdesk env.

App ID:33730

https://www.freshdev.io/custom_apps/33730-xero_app_testing/edit

Thanks for sharing the app ID @mirza_has,

Can you let us know which request is failing due to the token expiry?

Hi @Raghu_Murugesan

Yes i am using Xero API (third-party application) in my app, pass an access_token value by including the isOAuth parameter in the options. but after 30min access_token expired Api is not working

Xero api documentation link

Hi @mirza_has,

From the logs we could notice calls to https://identity.xero.com/connect/token are failing with 400 status code, can you update the app resolving the same and try.

Hi @mirza_has,

Could you share the updated oauth_config.json and it’s use with $request script? (Please remove the sensitive information while pasting the code)

  1. Could you confirm if the request works fine until 30 mins and fails after the access_token expiration?
  2. Is it in local environment?
  3. Is the behavior same when published as custom app?

Hi @Raghu_Murugesan

i update the app code. can you check it again

App ID: 33850

https://www.freshdev.io/custom_apps/33850-xero_app_testing/edit

Hi @Raviraj

yes i use $request in server.js file

I must sure that xero api expires the token after 30 minutes and it works great in local. I was facing the issue specially after deploy the custom app, the api expires after 30 minutes.

Is it possible for you to test at your end and acknowledge me what is the issue at your end? and you told me that evertime i reauthorize to get the new token but i dont think its a good approach for client to go and reauthorize after every 30 minutes. Can you please suggest me good approach ??

App ID: 33850

App code:
oauth_config.json link
server.js link