PnP Framework - Creating a team site with access token fails
See original GitHub issueHello,
I am trying to create a Modern Team site using PnP Framework, Azure Function with MSI but it fails with the below error.
I have assigned the below permissions to the Azure Function
This works locally when i try to debug but not when deployed as an Azure Function
var azureServiceTokenProvider = new AzureServiceTokenProvider();
string accessToken = await azureServiceTokenProvider.GetAccessTokenAsync("https://tenant.sharepoint.com");
SecureString str = ConvertToSecureString(accessToken);
var authManager = new AuthenticationManager(str);
var context = authManager.GetContext("https://tenant.sharepoint.com");
var teamContext = await context.CreateSiteAsync(
new TeamSiteCollectionCreationInformation
{
Alias = "alias", // Mandatory
DisplayName = "displayName", // Mandatory
Description = "description", // Optional
Classification ="classification", // Optional
IsPublic = false
});
teamContext.Load(teamContext.Web, w => w.Url);
teamContext.ExecuteQueryRetry();
Console.WriteLine(teamContext.Web.Url);
System.Exception: App-Only is currently not supported, unless you provide a Microsoft Graph Access Token. at PnP.Framework.Sites.SiteCollection.CreateAsync(ClientContext clientContext, TeamSiteCollectionCreationInformation siteCollectionCreationInformation, Int32 delayAfterCreation, Int32 maxRetryCount, Int32 retryDelay, Boolean noWait, String graphAccessToken, AzureEnvironment azureEnvironment) at Microsoft.SharePoint.Client.ClientContextExtensions.CreateSiteAsync(ClientContext clientContext, TeamSiteCollectionCreationInformation siteCollectionCreationInformation) at resourcerequest_functions.createsitewithtemplate.CreateSite(ClientContext context, ProcessRequest item, ILogger log)
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (3 by maintainers)
Top GitHub Comments
@sandeepvootoori : app-only based creation of SharePoint sites will go via Microsoft Graph as that’s the only option. We’ll create a Microsoft 365 group and as part of the group creation the SharePoint Site is created as well. This then implies you provide a token for graph.microsoft.com…whereas your code seems to request a token for tenant.sharepoint.com
Hello,
I am having same issue. I use PnPFramework 1.6.0. I get client context via certificaite and clientid,
CreateSiteAsync accepts only one parameter, TeamSiteCollectionCreationInformation. How can I pass graph access token?
Please suggest.