0

I tried to create "modern" site using CSOM method "ManipulateModernTeamSite(string accessToken)", but I am getting invalid Access Token. I have created Azure Hosted app to create Modern site. App is installed in one of the SharePoint Site with App-only Access policy. This App has SharePoint Online Administrator Access. When User submit the request it should create Modern site. I am using below code snippet to get Access token but I am getting Invalid access token. Please let me know how to get access token to create Modern site. Any Quick Solution to resolve this issue is Appreciable. Thanks.

Current code snippet to get access token getting invalid access token:

var tenantStr = hostWebUrl.ToLower().Replace("-my", "").Substring(8);

tenantStr = tenantStr.Substring(0, tenantStr.IndexOf("."));

var tenantAdminUri = new Uri(String.Format("https://{0}-admin.sharepoint.com", tenantStr));

string realm = TokenHelper.GetRealmFromTargetUrl(tenantAdminUri);

var accessToken = TokenHelper.GetAppOnlyAccessToken(TokenHelper.SharePointPrincipal, tenantAdminUri.Authority, realm).AccessToken;

Error: [07.19.2017 02:44:09] Error at CreateSiteCollection : Code: InvalidAuthenticationToken Message: Access token validation failure.

Inner error

[07.19.2017 02:44:09] Error is: at Microsoft.Graph.HttpProvider.d__19.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Graph.BaseRequest.d__36.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Graph.BaseRequest.d__32`1.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at OfficeDevPnP.Core.Framework.Graph.UnifiedGroupsUtility.<>c__DisplayClass4_0.d.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at OfficeDevPnP.Core.Framework.Graph.UnifiedGroupsUtility.CreateUnifiedGroup(String displayName, String description, String mailNickname, String accessToken, String[] owners, String[] members, Stream groupLogo, Boolean isPrivate, Int32 retryCount, Int32 delay) at Takeda.SelfService.AppOnlyWeb.Helper.ManipulateModernTeamSite(ClientContext ctx, SiteRequestInformation siteInfo, String hostWebUrl)

1

Resource URL is wrong..https://{0}-admin.sharepoint.com. you need to use https://graph.microsoft.com since you are targeting Microsoft Graph API.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.