sp-dev-docs icon indicating copy to clipboard operation
sp-dev-docs copied to clipboard

SPFX using AadHttpClient to access AAD secured endpoint not working on Teams Tab

Open Ashish1662 opened this issue 7 years ago • 31 comments

Category

  • [x] Question
  • [ ] Typo
  • [x] Bug
  • [ ] Additional article idea

We are using a SPFX client webpart using v1.8.1 and have successfully consumed an AAD protected endpoint. We have used AadHttpClient to take care of token acquisition which works pretty well in a SP web page.

However, when adding the WP as teams tab, it loads infinitely and does not show anything. Is this a known issue or am we are missing something. If it know what could be the possible workarounds.

Also the teams dev tools console is not showing any detailed information/error to debug or to start the RCA.

auth_spfx_teams_client

Thanks in advance.

Ashish1662 avatar May 22 '19 12:05 Ashish1662

Thank you for reporting this issue. We will be triaging your incoming issue as soon as possible.

msft-github-bot avatar May 22 '19 12:05 msft-github-bot

Are you seeing this in the Teams web client / native client?

If web, which browser?

Have you tried it using SPFx v1.8.2 as it contained a fix for the teamsContext... not sure if it's related or if something else was addressed in 1.8.2 that's related to this...

andrewconnell avatar May 28 '19 14:05 andrewconnell

It works fine for the web browsers. The issue is when using teams native client (both desktop & mobile).

I have tried it with latest version i.e. 1.8.2 but the issue is with this version too.

Ashish1662 avatar May 30 '19 14:05 Ashish1662

It is reproducable. If you fetch an AAD protected endpoint (e.g. Az web app or Az function) in an SPfx web part (1.8.1 and 1.8.2) the authentication process with AadHttpClient ....

  • ... works fine with Teams Online (SPfx component as tab, SharePoint tab).
  • ... works fine with SPO (SPfx webpart in SPO page).
  • ... FAILS in Teams CLIENT. Even if you embed the SharePoint tab to MS teams client, the authentication for these web parts fails as well. Looks like there are two different mechanism for authentication in place.

Means the idea and the really cool thing about using the same SPfx component in both SPO world as well as MS teams world, is actually not executable. I would also appreciate if that issue makes it into approved backlog as it has impact on architectural designs for future solutions. Using unauthenticated endpoints delivering enteprise data is not an option, actually.

Someone else able to re-produce?

ctxlabeu avatar May 31 '19 16:05 ctxlabeu

hey @beschick , that is unfortunately by design for now. While we are releasing code to fix it you can use the following workaround to make it work on Teams rich client: Note: you have to be Global Tenant Administrator to perform all the steps below Step 1. Visit the "Manage Permissions" Page in SharePoint Tenant Admin Step 2. Go to -> https://aad.portal.azure.com/#blade/Microsoft_AAD_IAM/ActiveDirectoryMenuBlade/RegisteredAppsPreview Step 3. Click on "SharePoint Online Client Extensibility" Web Application Principal Step 4. Click Manifest on the left menu Step 5. Copy the id from the oAuth2Permission array "oauth2Permissions": [ { "adminConsentDescription": "Allow the application to access SharePoint Online Client Extensibility Web Application Principal on behalf of the signed-in user.", "adminConsentDisplayName": "Access SharePoint Online Client Extensibility Web Application Principal", "id": "2143704b-186b-4210-b555-d03aa61823cf", "isEnabled": true, "lang": null, "origin": "Application", "type": "User", "userConsentDescription": "Allow the application to access SharePoint Online Client Extensibility Web Application Principal on your behalf.", "userConsentDisplayName": "Access SharePoint Online Client Extensibility Web Application Principal", "value": "user_impersonation" } ], Step 6. Replace “preAuthorizedApplications” entry with the following json "preAuthorizedApplications": [ { "appId": "00000003-0000-0ff1-ce00-000000000000", "permissionIds": [ "2143704b-186b-4210-b555-d03aa61823cf" ] } ], Step 7. Hit Save.

We will provide official documentation on that workaround as well. Please let us know if that unblocks you.

lucabandMSFT avatar Jun 05 '19 19:06 lucabandMSFT

@lucabandMSFT will this same process work with the SharePoint Mobile app? Seems related to #4073

andrewconnell avatar Jun 06 '19 09:06 andrewconnell

@andrewconnell : you are 100% correct.

lucabandMSFT avatar Jun 06 '19 17:06 lucabandMSFT

Hi @lucabandMSFT, we did try this workaround, but unfortunately it does not work. We know it takes few hours to reflect the changes but the results were same when we checked next morning.

The 'preAuthorizedApplications' was missing in the manifest hence we added it and replaced the 'permissionIds' with the correct value as mentioned in the post.

However, we were not sure what value should be specified for 'appId'. Should it be the id of the app having the endpoints or the SharePoint client extensibility app? We specified the SP client extensibility app id.

Ashish1662 avatar Jun 07 '19 10:06 Ashish1662

Can confirm that the workaround didn't work for us either. We tested the workaround with the Sharepoint App though, and not the Teams client.

chjohan avatar Jun 19 '19 10:06 chjohan

hey @chjohan, if the application is working on the browser but not in the rich clients than it looks like you are hitting the issue discussed here #3923. Please try again at the end of this week and the issue should be then resolved.

@Ashish1662, mind to share the manifest here?

lucabandMSFT avatar Jun 27 '19 06:06 lucabandMSFT

Manifest

Highlighted the ids in red line what we replaced.

After making this change, we waited for around 20 hours and endpoints still don't work in teams client.

Ashish1662 avatar Jun 28 '19 07:06 Ashish1662

Not sure if this is gonna help, but I hit same issue 2-3 months ago, and it was because you needed to enable Dev Preview setting in Teams App. Apparently the aadHttpClient is still in preview (and that could be wrong as my experience was some 2-3 months ago). It worth a try and is easy to test.

teams-dev-preview

luismanez avatar Jul 01 '19 10:07 luismanez

@luismanez I checked but same result. It still throws error. Thanks for sharing your experience though.

Ashish1662 avatar Jul 01 '19 13:07 Ashish1662

@Ashish1662, no: it should be the appID of the client extensibility app principal

lucabandMSFT avatar Jul 01 '19 23:07 lucabandMSFT

This issue has been automatically marked as stale because it has marked as requiring author feedback but has not had any activity for 7 days. It will be closed if no further activity occurs within next 7 days of this comment. Thank you for your contributions to SharePoint Developer activities.

msft-github-bot avatar Jul 09 '19 00:07 msft-github-bot

Commenting here as this shouldn't be closed automatically. This bug currently blocks some interesting scenarios...

BigEaseGueldi avatar Jul 15 '19 10:07 BigEaseGueldi

Correct... that was done automatically by a bot due to the presence of the Needs: Author Feedback label. Fixed...

andrewconnell avatar Jul 15 '19 14:07 andrewconnell

Well, but the issue is currently unactionable as there's no updates after my latest ask so.. what's the meaning of keeping this open at this point?

lucabandMSFT avatar Jul 15 '19 15:07 lucabandMSFT

Arg... you're right. My bad... added the label back, but the issue shouldn't get closed as it's an open issue that's being tracked.

andrewconnell avatar Jul 15 '19 15:07 andrewconnell

Hi @lucabandMSFT! I guess that depends on how you use GitHub. Speaking just for me the procedure was:

  • Struggle with your Web Part in a Teams tab as is uses AAD-secured Azure Functions
  • Find out that it works in the browser
  • Go to https://github.com/SharePoint/sp-dev-docs/issues
  • Find this issue by searching "AadHttpClient" directly, because it's an open one...

And of course it depends on how you understand the status "closed". I was commenting because the bot told me the issue would be closed tomorrow because of inactivity. I somehow connected "closed" with "solved" - and well - it's not solved.

Some of our Azure Functions will do a certificate-secured call to the MS Graph. And they can do things like deleting users, creating tons of MS Teams, .... Having these functions exposed more or less unsecured is ... an open issue ;-)

BigEaseGueldi avatar Jul 15 '19 15:07 BigEaseGueldi