question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

PnP Framework - Creating a team site with access token fails

See original GitHub issue

Hello,

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

image

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:closed
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
jansenbecommented, Apr 19, 2021

@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

0reactions
SergiyKostenkocommented, Sep 30, 2021

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error "Token request failed" when connecting to ...
I just built a new console application on .NET Framework 4.8 with latest PnP.Framework pack on a Windows 10 machine and it worked...
Read more >
Getting" Token request failed" with CSOM PnP Framework ...
I am creating a client context and requesting data using an app id and secret. The app registration has all the permissions on...
Read more >
SharePoint OAuth token request failed
I have a console application that connects to a SharePoint site to retrieve some data. It uses a Client ID and Client Secret...
Read more >
Migrating from PnP Sites Core to PnP Framework
NET Standard library only supports access token based auth. Apply minimal code changes to make authentication work.
Read more >
Connect-PnPOnline Error: "Token request failed"
Connect-PnPOnline Error: "Token request failed" is mainly due to the ClientSecret you are using in your application.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found