[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;
}