Oauth2 for Local App: Access token cannot be refreshed

Hello,

I am working on a freshdesk-app to integrate Business Central with Freshdesk. I have been able to receive the access token for my local app but whenever i try to make a request, the console shows the following error: “Access token cannot be refreshed”

My oauth_config.js looks as follows (with the client_id, client_secret and tenant replaced with ***):

{
	"client_id": "***",
	"client_secret": "***",
	"authorize_url": "https://login.microsoftonline.com/***/oauth2/v2.0/authorize",
	"token_url": "https://login.microsoftonline.com/***/oauth2/v2.0/token",
	"options": {
		"scope": "https://api.businesscentral.dynamics.com/.default"
	},
	"token_type": "account"
}

The request function looks as follows (with our company domain and name replaced with ***):

function BCRequest() {
  var self = this,
        path = "/salesShipmentLines?$filter=billToCustomerNo eq '20000'&company=CRONUS CH",
        headers = { Authorization: "bearer <%= access_token %>"},
        reqData = { headers: headers, isOAuth: true },
        url = "https://api.businesscentral.dynamics.com/v2.0/***/Sandbox-DEV/api/***/freshdesk/v1.0" + path;
      client.request.get(url, reqData).then(
        function(data) {
          console.log(data);

        },
        function(error) {
          console.log(error)
        }
      );
}

The request generates the following entries in the fdk.log file:

How can i make a successfull request without this error getting shown?

Thank you very much!

I managed to get this to work. Apparently the scope offline_access is required for oauth2 access in local development. The file oauth_config.json should therefore look like the following (sensitive data replaced with ***):

{
	"client_id": "***",
	"client_secret": "***",
	"authorize_url": "https://login.microsoftonline.com/***/oauth2/v2.0/authorize",
	"token_url": "https://login.microsoftonline.com/***/oauth2/v2.0/token",
	"options": {
		"scope": "https://api.businesscentral.dynamics.com/.default offline_access"
	},
	"token_type": "account"
}
1 Like

This topic was automatically closed 6 days after the last reply. New replies are no longer allowed.