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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Suggested Answer

How to get the token ... Microsoft .. OAuth?

(1) ShareShare
ReportReport
Posted on by 39
Hello forum!

The objective is to obtain a token from the Microsoft site, which will then be used to access Azure Key Vault.

I am using the following code for study purposes. However, every time it runs, I encounter a 400 error. When using the same header configuration in Postman, the token is retrieved successfully. Here’s my code:
 
 
 
I have the same question (0)
  • Gerardo Rentería García Profile Picture
    25,169 Most Valuable Professional on at
  • Suggested answer
    Dynamics_Decoded_Gokul Profile Picture
    451 on at
    Hi, 

    ensure you have a app registered in Azure portal and have the sceret key before using the below code

    Thanks in Advance 
    Gokul
     
        procedure GetAccessToken() AccessToken: Text
        var
            OAuth2: Codeunit OAuth2;
            PromptInteraction: Enum "Prompt Interaction";
            Scopes: List of [Text];
            AuthError: Text;
            Share: Record "Custom Company Setup";
     
        begin
            Share.Reset();
            Share.ChangeCompany("Company Name");
            if Share."Sharepoint URL" <> '' then begin
     
                Scopes.Add('https://graph.microsoft.com/.default');
                Rec.Get(CompanyName);
                OAuth2.AcquireAuthorizationCodeTokenFromCache(GraphMgtGeneralTools.StripBrackets(Format("Application ID")),
                                                              "Client Secret", "Redirect URL", "OAuth Redirect Url", Scopes, AccessToken);
     
                if AccessToken <> '' then
                    exit;
     
                OAuth2.AcquireTokenByAuthorizationCode(GraphMgtGeneralTools.StripBrackets(Format("Application ID")),
                                                      "Client Secret", "OAuth Redirect Url", "Redirect URL", Scopes, PromptInteraction::"Select Account",
                                                      AccessToken, AuthError);
     
                if AccessToken = '' then
                    Error(AuthError);
            end;
        end;

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

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 > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 3,143

#2
Jainam M. Kothari Profile Picture

Jainam M. Kothari 1,694 Super User 2025 Season 2

#3
YUN ZHU Profile Picture

YUN ZHU 1,067 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans