web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested Answer

How to generate delegated OAuth2 token (with user info) using X++ in D365FO

(0) ShareShare
ReportReport
Posted on by

Hi everyone,

I’m trying to generate a delegated OAuth2 token (including user context like User.Read) from within X++ in Dynamics 365 Finance & Operations.

In Postman, I’ve successfully achieved this using the OAuth 2.0 flow — I’ve attached a screenshot showing how I configured the request and used the "Get New Access Token" button to retrieve the token.

Now I’m looking to replicate this behavior in X++. Specifically:

  • Is it possible to generate a delegated token from X++?
  • Are there any built-in classes or frameworks that support this flow?
  • ​​​​​​​What’s the recommended approach for securely handling this in D365FO?

For reference, here’s the guide I followed to generate the token using Postman:
🔗 https://learn.microsoft.com/en-gb/answers/questions/4379336/how-to-generate-token-in-x-for-third-party-app-wit


Any guidance, examples, or documentation links would be greatly appreciated.

Thanks in advance!

Categories:
I have the same question (0)
  • Martin Dráb Profile Picture
    238,067 Most Valuable Professional on at
    Sure, you can send HTTP requests from X++, including this one. You just need to use .NET classes such as System.Net.Http.HttpClient, not a native X++ class (unless it's a wrapper of a .NET API). Also, OAuth .NET libraries exist, if you don't want to deal with raw HTTP requests the same way as in Postman.
     
    By the way, there isn't a single OAuth 2.0 flow - several different flows exist, such as client credentials flow. When talking about these things, it'll help if you say which flow you want to use.
  • Suggested answer
    vishalsahijwani Profile Picture
    197 on at
     Hi  , 
     
    Please go through the below mentioned blog post : - 
     
     
    In this blog post the logic is generating a dynamic authentication token through x++ and calling an API generated by Dynamics CRM.
     
    The code segment  - Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationResult authenticationResult =
                authenticationContext.AcquireTokenAsync(activeDirectoryResource, activeDirectoryClientAppId, userCredential).Result;
     
    Hope this helps !!!!
  • hca Profile Picture
    171 on at
    How do you involve the user in this process?

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

News and Announcements

Season of Giving Solutions is Here!

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Abhilash Warrier Profile Picture

Abhilash Warrier 679 Super User 2025 Season 2

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 429 Super User 2025 Season 2

#3
Martin Dráb Profile Picture

Martin Dráb 264 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans