Hi,
We are having one requirement where we want to read data from another crm instance using a web api in a javascript.
while doing this I got an authentication issue and to resolve this I need to set a reqest header for an authentication and pass an access token.
And to get this token I used MSAL library but it is giving me a sign in page, I want to get an access token silently i.e without a log in pop.
How can I achive this without login popup,can anyone please guide me in the right direction.
please find my code below :
getAccessToken: function () { const msalConfig = { auth: { clientId: "XXXXX-XX-XXX-XXXXXX", authority: "https://login.microsoftonline.com/XXXXX-XX-XXX-XXXXXX", redirectUri: "https://XXXX.crm4.dynamics.com", }, cache: { cacheLocation: "sessionStorage", // This configures where your cache will be stored storeAuthStateInCookie: false, // Set this to "true" if you are having issues on IE11 or Edge }, system: { loggerOptions: { loggerCallback: (level, message, containsPii) => { if (containsPii) { return; } switch (level) { case msal.LogLevel.Error: console.error(message); return; case msal.LogLevel.Info: console.info(message); return; case msal.LogLevel.Verbose: console.debug(message); return; case msal.LogLevel.Warning: console.warn(message); return; } } } } }; var request = { scopes: ["User.Read", "Mail.Read"], forceRefresh: false // Set this to "true" to skip a cached token and go to the server to get a new token }; var userAgentApplication = new Msal.UserAgentApplication(msalConfig); userAgentApplication.loginPopup(request.scopes).then(function (idToken) { userAgentApplication.acquireTokenSilent(request.scopes).then(function (accessToken) { //AcquireToken Success alert("token 1 " accessToken); }, function (error) { //AcquireToken Failure, send an interactive request. userAgentApplication.acquireTokenPopup(request.scopes).then(function (accessToken) { alert("token 2 " accessToken); }, function (error) { console.log("error child :: " error); }); }); }, function (error) { console.log("error main :: " error); }); },
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,253 Super User 2024 Season 2
Martin Dráb 230,188 Most Valuable Professional
nmaenpaa 101,156