Identifying External Sharing in Site Collections using SPFx
Category
- [x] Bug
Describe the bug
I am currently using "this.context.pageContext.legacyPageContext.guestsEnabled" property to identify if the site collection is shared externally or not. However, when i look at this link https://docs.microsoft.com/en-us/javascript/api/sp-page-context/pagecontext?view=sp-typescript-latest#legacypagecontext. It says that this property is legacy and are encouraged to use the SharePoint Framework TypeScript APIs instead.
I am not able to find a relevant SharePoint Framework TypeScript API to identify the external sharing on site collections so i am submitting in GItHub as per the below Note.
"NOTE: If certain functionality is exposed in the legacyPageContext but does not seem to have a proper TypeScript API, please file an issue on GitHub. The intention is that no modern application should need to rely on the legacyPageContext object."
If there is a relevant SharePoint Framework TypeScript API to achieve this, please share.
Also, i would like to highlight another point that, this property "this.context.pageContext.legacyPageContext.guestsEnabled " returns FALSE when we choose Existing Guests only Option in Admin for external sharing (Attached the below screenshot). However, if i choose the New and Existing Guests option it returns "True", I was expecting "True" for both the selections.

Which property we need to use which returns True for the above selection.
Thanks in advance!
Thank you for reporting this issue. We will be triaging your incoming issue as soon as possible.
Not aware of an API in the SPFx API that contains this property... I think you'll likely want to rely on a REST API call. However, I'm unable to find a REST call that exposes that detail on a site collection... you may need to rely on this legacy context for now... I've sent a few questions around with the REST API engineers & will follow up if I hear anything.
Looks like this property is only available from the tenant admin in O365. This page shows how you can use the CSOM to get this information (https://docs.microsoft.com/en-us/sharepoint/dev/solution-guidance/set-external-sharing-on-site-collections-in-office-365).
If it's only available via tenant admin, that likely means it's not something you'll want to do in an SPFx web part as most people won't have permissions to that setting.
Hi @andrewconnell , Thanks for your response. Indeed, its available in Tenant Admin via CSOM and PowerShell. However, i would like to do this in SPFx extensions. Thanks
I want to achieve this in SPFx properties instead of using CSOM as it involves tenant level permission and it introduces unnecessary risk which would be rejected by a security/risk team also its just for knowing if the site collection is externally shared or not
Closing this issue as "answered". If you encounter a similar issue(s), please open up a new issue. See our wiki for more details: Issue-List: Our approach to closed issues
Thank you for your submission. As explained in our wiki (Issue List: What doesn't belong in the issue list), all new feature requests and change requests to existing features should be posted to the SP Dev UserVoice site. You can learn more about this in our wiki: type:uservoice-request
@NavaneethaDev said:
I want to achieve this in SPFx properties instead of using CSOM as it involves tenant level permission and it introduces unnecessary risk which would be rejected by a security/risk team also its just for knowing if the site collection is externally shared or not
Unfortunately, that's how it works today... it's by design. If you'd like it to work differently, you'll need to submit a user voice request