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

Failed to get accesstoken with AADTokenProvider on SharePoint mobile app

Open LeemansBE opened this issue 7 years ago • 8 comments

Category

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

Expected or Desired Behavior

I created a SharePoint Framework 1.7 webpart which uses the AadTokenProviderFactory to generate an accesstoken. We've tested this on all browsers (desktop and mobile) and this is working as expected.

Observed Behavior

However, when opening a page containing the webpart on the SharePoint mobile app (Version 3.8.0) the webpart receives an error:

"TypeError: Failed to fetch"

Steps to Reproduce

this.context.aadTokenProviderFactory
    .getTokenProvider()
    .then((tokenProvider: AadTokenProvider): Promise<string> => {
      // retrieve access token for the enterprise API secured with Azure AD
      return tokenProvider.getToken('[Azure AD app ID]');
    })
    .then((accessToken: string): void => {    
      alert(accessToken);
    }).catch(error => {        
        alert('error: ' + error);      
    });

Also tried to update the AD app manifest with

"preAuthorizedApplications": [
    {
        "appId": "00000003-0000-0ff1-ce00-000000000000",
        "permissionIds": [
            "[PERMISSION ID]"
        ]
    }
]

but still no luck.

Any ideas?

LeemansBE avatar Jun 03 '19 08:06 LeemansBE

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

msft-github-bot avatar Jun 03 '19 08:06 msft-github-bot

@LeemansBE said:

Also tried to update the AD app manifest with

What do you mean by this... where did you do this? Are you saying you're modifying the Azure AD app manifest in the Azure AD Admin Portal? If so, that will not have an impact here...

Where is the error coming from... when you obtain the token provider (the first then()) or when you try to get the token?

andrewconnell avatar Jun 04 '19 15:06 andrewconnell

Hi @andrewconnell

Jep that is correct. I've tried to follow the steps described here

Obtaining the token provider seems to be going well. The error is thrown when we try to get the token. It's actually quite hard to debug as this works well on all browsers (dekstop and mobile) but only fails when rendered in the SharePoint app (Android).

LeemansBE avatar Jun 04 '19 15:06 LeemansBE

We can also confirm we have had issues when using the SharePoint app and using the Graph authentication package. Works fine when in the browser on the same Android/iOS device but fails to auth in the SP app. I will query my team for further info and get back to you.

CPritch avatar Jun 06 '19 08:06 CPritch

According to #4013, @lucabandMSFT said this same process should work for the mobile app.

@lucabandMSFT is it the same AppID for the mobile app?

andrewconnell avatar Jun 06 '19 17:06 andrewconnell

yes, exactly the same. as we load the SharePoint page in an iFrame in the Mobile app (or Team). it's the page that goes to AAD to fetch the token.. which means that it is the same appID.

lucabandMSFT avatar Jun 06 '19 17:06 lucabandMSFT

closing this as a dupe of #4013

lucabandMSFT avatar Jul 01 '19 23:07 lucabandMSFT

Issues that have been closed & had no follow-up activity for at least 7 days are automatically locked. Please refer to our wiki for more details, including how to remediate this action if you feel this was done prematurely or in error: Issue List: Our approach to locked issues

msft-github-bot avatar Jan 24 '20 12:01 msft-github-bot