unit-test-samples icon indicating copy to clipboard operation
unit-test-samples copied to clipboard

Make a query to a sharepoint site in a multi-tenant scenario

Open ayoubqrt opened this issue 2 years ago • 1 comments

Hi thank you for you work, I found some useful resources particularly on your mgwdev-m365-helpers repo. So I wanted to use the sp-react application in a multitenant scenario.

Context :

  • The application in Azure is registered in the 1234xx tenant and configured in multitenant mode
  • The site collection in Sharepoint was created in public mode (so members of the organization can access the site)
  • Added in the site collection a user from another tenant

Scenario :

  • With any account from 1234xx tenant, I can authenticate myself and make requests to sharepoint within the sharepoint Rest API.
  • With a user from another tenant, I can authenticate myself but not make requests to SharePoint, I get this error: {"error_description":"Exception of type 'Microsoft.IdentityModel.Tokens.AudienceUriValidationFailedException' was thrown."}

Have you any ideas, do you think it's possible ?

ayoubqrt avatar Jan 06 '24 10:01 ayoubqrt

Hi Mate :) Great to hear someone finds it useful.

When it comes to guests in such scenario, there is one thing You have to consider - even if Your app is registered as a multitenant, You have to know to which tenant You want to authenticate at runtime level, in other words - when navigating to /auth page, You have to already know to which tenant You want to authenticate to. If not - MS login page will always assume You want to authenticate to Your "main" tenant.

This of course presents a small problem - if You want to keep Your app functioning as multi tenant You have to figure out when user is using the app as a guest, and when as a internal user. I would suggest using link with ?tenantid=<tenant_id> when sharing the link to Your app, than if Your app detects tenant-id in query parameter - it uses it in auth endpoint, if not - go with common (or organizations).

If You are building an app for one customer (or You can handle that with subdomains) - there is no problem :)

Hope that helps :)

mgwojciech avatar Jan 08 '24 07:01 mgwojciech