Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot join hub site, because Approval Token is needed #1193

Closed
1 task done
mjonila opened this issue Jun 1, 2023 · 7 comments
Closed
1 task done

Cannot join hub site, because Approval Token is needed #1193

mjonila opened this issue Jun 1, 2023 · 7 comments
Assignees
Labels
area: model 📐 Related to the core SDK models question Further information is requested

Comments

@mjonila
Copy link

mjonila commented Jun 1, 2023

Category

  • Bug

Describe the bug

While using Ctx.Site.JoinHubSiteAsync(hubSite.Id) it spits the error :
This Hub Site requires approval to join. Please resubmit this request with an Approval Token from the Hub Site admin.

Certainly Hub site options have "Require approval for associated sites to join" enabled.
Untitled1

However I see no way to get Approval Token or enter it somehow into JoinHubSiteAsync method. There is PowerAutomate action for getting ApprovalToken, but I don't know how it works.

How to fix this problem ?

Steps to reproduce

In Hub site properties enable "Require approval for associated sites to join" and use JoinHubSiteAsync(hubSiteId) to join a site into a hub.

Expected behavior

Either allow join without token or provide a method to acquire ApprovalToken and feed it into JoinHubSiteAsync method

@jansenbe jansenbe self-assigned this Jun 1, 2023
@jansenbe jansenbe added question Further information is requested area: model 📐 Related to the core SDK models labels Jun 1, 2023
@jansenbe
Copy link
Contributor

jansenbe commented Jun 1, 2023

@mjonila : what permissions did you grant to your Azure AD application? Is the account running the code a site collection admin on the hub site? If not, are you using application permissions?

@mjonila
Copy link
Author

mjonila commented Jun 2, 2023

We run code in Azure Function. The account running the code is AzureAD application with Application permissions of SharePoint --> Sites.FullControl.All.
We do a lot of other things with Site configuration and all others work just fine, except joining to hub site.

In the meantime when I do joining to hub site using same AzureAD app with Powershell - it all works!
This is how I connect using powershell and what I do :
Connect-PnPOnline -Url "https://mytenant.sharepoint.com/sites/MySite" -ClientId 5fdb3165-5ea5-4161-a51c-507cde838e62 -CertificatePath 'C:\projects\Certificates\Certificate.pfx' -CertificatePassword $password -Tenant 'mytenant.onmicrosoft.com'

Add-PnPHubSiteAssociation -site "https://mytenant.sharepoint.com/sites/MySite" -HubSite "https://mytenant.sharepoint.com/sites/HubSite"

Maybe PnP Powershell is doing this using CSOM and PnP Core - using REST API and that's the difference ?
What would be ways to identify the root cause and overcome this error ?

@jansenbe
Copy link
Contributor

jansenbe commented Jun 2, 2023

@mjonila : thanks for the details @mjonila . PS uses a Tenant CSOM call (so you have to have full control or be SharePoint Global Tenant admin) whereas in Core we use the REST call like used via the UI. We need to solve this, I'll do some experimentation as there's an option to request the "approval token". Alternatively the CSOM approach can be used but then via a new method hosted in the Admin library

@mjonila
Copy link
Author

mjonila commented Jun 5, 2023

Thank you for the answer @jansenbe . As I will wait for your testing of getting ApprovalToken using REST, could you please help me find how to join hub site using CSOM ? I cannot find such method in Admin lib, but maybe I'm not looking careful enough ..
Thanks again.

@jansenbe
Copy link
Contributor

jansenbe commented Jun 5, 2023

@mjonila : it's not yet wrapped in our Admin lib, but it's available in OOB CSOM. I plan to wrap the CSOM calls and make them available via our Admin library in the course of this week.

@jansenbe
Copy link
Contributor

@mjonila : I've added a method to the Admin library that under the covers uses the Tenant hub join API. This one will work also in case joining the hub requires approval. This method however requires administrative privileges to work, but as your PS script works this should work as well.

Please test wit next nightly build (version 1.9.73 or higher) and let me know.

@mjonila
Copy link
Author

mjonila commented Jun 13, 2023

Thanks @jansenbe! It is working now.

jansenbe added a commit that referenced this issue Jul 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: model 📐 Related to the core SDK models question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants