Pnpjs: graph.users.getById causes redirect to spfxsinglesignon.aspx

Created on 26 Jan 2021  路  2Comments  路  Source: pnp/pnpjs

Category

  • [ ] Enhancement
  • [ ] Bug
  • [X] Question
  • [ ] Documentation gap/issue

Version

Please specify what version of the library you are using: [ 2.0.12 ]

Please specify what version(s) of SharePoint you are targeting: [ Sharepoint Online ]

Expected / Desired Behavior / Question

Hi.

In the custom SPFx solution I'm working on, we occasionally observe this:

  1. The web part starts loading on https://acme.sharepoint.com/sites/mysite
  2. The user is redirected to https://acme.sharepoint.com/_forms/spfxsinglesignon.aspx
  3. The user is redirected back to https://acme.sharepoint.com/sites/mysite

This redirect causes https://acme.sharepoint.com/sites/mysite to be loaded twice, which to our users is viewed as a bug/hick-up. As this redirect is related to SSO, it typically seems to happen after a period of inactivity.

After some initial analysis, I believe this is the code line that causes the issue:

await graph.users.getById(emailAddress).memberOf();

Is is likely that this function call is what's triggering the redirect? And if so, is there a way to avoid the redirect, so that the whole page doesn't load twice?

code answered question

All 2 comments

Graph API requires some additional auth code bindings, as Graph is an external resource. Are you sure you're following auth notes? https://pnp.github.io/pnpjs/authentication/client-spfx/#connect-to-graph-as-current-user

Thanks for the link. I see that I didn't have this set up in my project. Added it now, and will check to see if the redirect issue goes away.

Was this page helpful?
0 / 5 - 0 ratings