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 :
Small and medium business | Business Central, N...
Suggested Answer

I want to code an authentication interface on Microsoft dynamic center

(0) ShareShare
ReportReport
Posted on by 5

[9:59 AM] Salma Bouzeida

I did all the linking steps between microsoft azure and microsoft dynamic. I found this code, I assumed that this function is the desired function. but when i ran the code it gave me an empty token. I don't know where the fault is! please help me

the code : 

page 50148 "testaccestoken"
{
PageType = Card;
ApplicationArea = All;
UsageCategory = Administration;

layout
{
area(Content)
{
group(GroupName)
{
field(UserEmail; UserEmail)
{
ApplicationArea = All;

}
field(PWD; PWD)
{
ApplicationArea = All;

}
field(AccessToken; AccessToken)
{
ApplicationArea = All;

}
}
}
}

actions
{
area(Processing)
{
action(Token)
{
ApplicationArea = All;
Image = TestFile;
trigger OnAction()

begin
AadTenantId := '*******';
Client_Id := '*******';
UserEmail := 'Salma.bouzeida@vaganet.fr';
pwd := '******';
ResourceURL := 'api.businesscentral.dynamics.com/';
// //Environment := authTable.Environment;
// OAuth2.GetDefaultRedirectURL(RedirectURL);
ClientSecret := '********';

// ** DEFAULT VALUES - redirect and
RedirectURL := 'businesscentral.dynamics.com/OAuthLanding.htm';
// Client_Id := '********';// powershell ID default

MicrosoftOAuth2Url := 'login.microsoftonline.com/.../authorize'; //TOKEN
//OAuthAdminConsentUrl := 'login.microsoftonline.com/.../adminconsent';
Scopes.Add('api://**********/user_impersonation');
OAuth2.AcquireTokensWithUserCredentials(MicrosoftOAuth2Url, Client_Id, Scopes, UserEmail, pwd, AccessToken, idToken);
//Oauth2.AcquireTokenWithClientCredentials(Client_Id, ClientSecret, MicrosoftOAuth2Url, RedirectURL, ResourceURL, AccessToken);
Message(AccessToken);
end;
}
}
}

var
ClientSecret: Text;
RedirectURL: text;
MicrosoftOAuth2Url: text;
OAuthAdminConsentUrl: text;
Scopes: List of [Text];
ResourceURL: Text;
Client_Id: text;
UserEmail: text;
AccessToken: text;
idToken: text;
AadTenantId: Text;
Oauth2: Codeunit OAuth2;
OAuth2Authorization: Codeunit "OAuth 2.0 Mgt.";
PWD: Text;

}

I have the same question (0)
  • Suggested answer
    Marco Mels Profile Picture
    on at

    Hello,

    We currently do not have dedicated Dev support via the Dynamics 365 Business Central forums, but I wanted to provide you some additional resources to assist. If you need assistance with debugging or coding I would recommend discussing this on one of our communities.

    www.yammer.com/dynamicsnavdev

    dynamicsuser.net/.../developers

    I will open this up to the community in case they have something to add.

    Thanks.

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…

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 2,202

#2
Dhiren Nagar Profile Picture

Dhiren Nagar 1,210

#3
YUN ZHU Profile Picture

YUN ZHU 1,115 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans