0

We have been searching and searching to find examples of how to get an OAuth token in al code in our codeunit. We can successfully get the token in Postman, so I know all the credentials are correct. But finding examples on the web of how to do this has proven to be extremely difficult.

I did find this .al page from Microsoft that looks like it has an example using OAuth2.AcquireTokenWithClientCredentials but we can't get it to work. https://github.com/microsoft/BCTech/blob/master/samples/OAuth2Flows/TestOAuth2Flows.Page.al

Does anyone have a working example of this?

dmikester1
  • 1,374
  • 11
  • 55
  • 113

1 Answers1

0

Kauffmann has a good blog post on this. It's talking about calling BC with an OAuth token, but the same principle applies.

Are you able to get the OAuth token in AL, and just have trouble using it to authenticate the request? If so, try this from the blog post:

Client.DefaultRequestHeaders.Add('Authorization', GetAuthenticationHeaderValue(AccessToken));
Client.DefaultRequestHeaders.Add('Accept', 'application/json');

If you can't get the token, I'd recommend looking at the OAuth2 codeunit.