Skip to main content

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

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;

[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.<b__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)

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.<b__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)

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.<b__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)

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.<b__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)

Source Link

How to get Access Token to Create Modern site using CSOM

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.<b__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)