Skip to main content

Notifications

Microsoft Dynamics 365 | Integration, Dataverse...
Suggested answer

Unable to get access token using msal

Posted on by 5

We have one webresource, we want to use microsoft graph api for that, we are getting access token using msal below in the code 

try {
            var config = {
                auth: {
                    clientId: "our client id",
                    authority: "authority"
                },
                cache: {
                    cacheLocation: "sessionStorage"
                }
            };
            var requestPermissionScope = {
                scopes: ["user.read"]
            };
            var myMSALObj = new Msal.UserAgentApplication(config);
            debugger;
            myMSALObj.acquireTokenSilent(requestPermissionScope).then(result => {
                debugger;
                if (result != undefined) { // sucessfully authenticate and got token.
                    debugger
                  
                }
            }).catch(function (error) {
                debugger;
                console.error(error);
            });
            debugger
        } catch (error) {
            
        }


This code is working fine, if we are accessing webresource directly through the URL, but we have added this webresource in the dynamics too, and there it is not working, token is not getting no error in the console

Please help us in this
Thanks
  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Unable to get access token using msal

    Hi rizwan58955895,

    I'm not familiar with masl. I create a web resource in dynamics with the following code:

    
    
    
    test
    
    
    
        

    When I paste the web resource URL, I can get the token:

    pastedimage1631172428412v1.png

    Hope it can help you.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,240 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans