Repository: SharePoint/sp-dev-docs

Issue #4892: getToken() intermittently hangs and fails to resolve/reject
Created: 2019-11-13T16:14:24Z
Category

 Question
 Typo
 Bug
 Additional article idea

Expected or Desired Behavior
The promise returned by AadTokenProvider.getToken() should always resolve or reject. In other words, when a token can't be retrieved for whatever reason, I should get something back that I can catch.
Observed Behavior
getToken() is occasionally hanging - never resolving or rejecting so I can't catch an error or figure out what's happening. The .then() under getToken() just never runs and my web part stalls.
Steps to Reproduce
I'm trying to access a .NET Core Web API secured with AAD from my custom web part. I initially used the instructions found here but AadHttpClient.get() was occasionally stalling so I decided to get the token using AadTokenProvider.getToken() and manually add it to a HttpClient.get() but my issue didn't go away. I was however able to confirm that getToken() is where it hangs rather than an issue with the API. Here's my code:
this.context.aadTokenProviderFactory.getTokenProvider()
    .then((provider) => { 
        return provider.getToken('<Client ID for my API>', false) //THIS IS WHERE IT HANGS
            .then((token) => {
                this.context.httpClient
                    .get('https://www.example.com/api/myAPI/', AadHttpClient.configurations.v1, {
                        headers: [
                            ['accept', 'application/json'],
                            ['Authorization', 'Bearer ' + token]
                        ]
                    })
                    .then((res: HttpClientResponse): Promise<any> => {
                        return res.json();
                    })
                    .then(data => {
                        //process data
                    }, (err: any): void => {
                        this.context.statusRenderer.renderError(this.domElement, err);
                    });
            }, (rejection) => {
                this.context.statusRenderer.renderError(this.domElement, "Token request rejected. " + rejection);
            });
    })
    .catch((err) => {
        this.context.statusRenderer.renderError(this.domElement, "Failed to get token provider.");
    });

I noticed that it seems to hang after a period of inactivity like maybe it's failing to refresh a stale token or something. I'd expect the rejection code to execute but nothing beyond getToken() runs. But if I refesh the page a couple times, it starts working again.
This seems to be related to issue #914 reported on pnp/pnpjs.
Edit: I discovered that this is a lot easier to reproduce in Chrome. (I haven't seen it occur in IE and I've only seen it once or twice in Firefox although I can't seem to reproduce in FF at the moment. Edge gets the token but fails the API request for reasons I can't explain).  In Chrome, it struggles every time it needs to grab a token. So, for example, it hangs the first time you load the page. If you refresh a few times, it starts working. Then if you leave the page open for a period of time (long enough for the token to expire) and refresh the page, it hangs again.
Edit 2: Per the conversation below, we can reproduce the issue when the custom web part is on the same page as a document library and a planner or events web part and it works fine when on a page by itself. There may be some sort of conflict with token retrieval/sharing between web parts.

Duplicate issue #5164: SPFx 1.10.0, msGraphClient, SharePoint Full Page as a Tab in MS Teams doesn’t work.
Created: 2020-01-18T02:48:01Z
Category

 Question
 Typo
 Bug
 Additional article idea

Expected or Desired Behavior
msGraphClient calls should work when we add SharePoint Page as a Tab in Ms Teams.
Observed Behavior
When we access SharePoint page (having SPFx 1.10.0 and msGraphClient calls) outside the Teams, it works as expected. However, when we add the same page as a Tab in Ms Teams it doesn’t work in the browser as well as in Desktop client.
Error:
Refused to display 'https://myorg-app.sharepoint.com/_forms/spfxsinglesignon.aspx... ... ...' in a frame because it set 'X-Frame-Options' to 'sameorigin'.
Token renewal operation failed due to timeout
CALL STACK:
Error: Token renewal operation failed due to timeout
at Array. (https://spoprod-a.akamaihd.net/files/sp-client-prod_2019-10-18.027/teams-web-part-application-assembly_default_c630174accea338c987cda5dc34553ec.js:20:89032)
at Object._callBackMappedToRenewStates.._callBackMappedToRenewStates. (https://spoprod-a.akamaihd.net/files/sp-client-prod_2019-10-18.027/chunk.vendors~sp-http-adal_6a29bd503d1db27efc57.js:1:7704)
at https://spoprod-a.akamaihd.net/files/sp-client-prod_2019-10-18.027/chunk.vendors~sp-http-adal_6a29bd503d1db27efc57.js:1:10166
Ms Teams is blocking some scripts in a process of token renewal operation for SPFx msGraphClient API. I tried by adding valid domains but didn’t succeed.
"validDomains": [
".login.microsoftonline.com",
".sharepoint.com",
".sharepoint-df.com",
"spoppe-a.akamaihd.net",
"spoprod-a.akamaihd.net",
"resourceseng.blob.core.windows.net",
"msft.spoppe.com",
"graph.microsoft.com",
"login.windows.net",
"static.sharepointonline.com",
"login.microsoftonline.com",
".outlook.com",
"*.office365.com"]
WebPart.Manifest.json
"supportedHosts": ["SharePointWebPart", "TeamsTab", "SharePointFullPage"]
Package-solution.json
"isDomainIsolated": false,
"webApiPermissionRequests": [
{
"resource": "Microsoft Graph",
"scope": "User.ReadBasic.All"
},
{
"resource": "Microsoft Graph",
"scope": "User.Read"
}
]
Steps to Reproduce

Build SPFx 1.10.0 WebPart with any msGraphClient call API.
Add supported host "SharePointFullPage"
Create App Page
Add a page as a Tab in Ms Teams using Postman

Post:  https://graph.microsoft.com/v1.0/teams/team-id/channels/channel-id/tabs
Body:
{
"displayName": "Gamify",
"teamsApp@odata.bind" : "https://graph.microsoft.com/v1.0/appCatalogs/teamsApps('2a527703-1f6f-4559-a332-d8a7d288cd88')",
"configuration": {
"entityId": null,
"contentUrl": "https://myorg.sharepoint.com/sites/sampleSite/SitePages/teamPage.aspx",
"websiteUrl": null,
"removeUrl": null
}
}
Thanks for your contribution! Sharing is caring.

Closing comment (2020-01-18T11:04:46Z): Believe this is a dupe of #4892 which is ack'd as a known bug from MSFT & they are working on it. As such, I'll close this issue as a dupe as we try to consolidate related issues to a single instance.