Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/sharepoint/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sharepoint 401使用仅使用Office Pnp站点核心的应用程序创建现代站点时_Sharepoint_Csom - Fatal编程技术网

Sharepoint 401使用仅使用Office Pnp站点核心的应用程序创建现代站点时

Sharepoint 401使用仅使用Office Pnp站点核心的应用程序创建现代站点时,sharepoint,csom,Sharepoint,Csom,因此,我在这里使用方法2: 我的代码如下: string siteUrl = "https://xx.sharepoint.com/sites/test212/"; string siteUrl2 = "https://xx.sharepoint.com/sites/test2122/"; //Client id and Client secret created through appregnew.aspx and permissions g

因此,我在这里使用方法2:

我的代码如下:

string siteUrl = "https://xx.sharepoint.com/sites/test212/";
            string siteUrl2 = "https://xx.sharepoint.com/sites/test2122/";

            //Client id and Client secret created through appregnew.aspx and permissions granted through appinv.aspx
            var authManager = new OfficeDevPnP.Core.AuthenticationManager();

            //PnP Core method
            ClientContext clientContext = authManager.GetAppOnlyAuthenticatedContext(siteUrl, "xx", "xx");

            var teamNoGroupSiteResult = await clientContext.CreateSiteAsync(new OfficeDevPnP.Core.Sites.TeamNoGroupSiteCollectionCreationInformation()
            {
                Url = siteUrl,
                Title = "Team no group Site Test",
                Description = "Site description",
                Lcid = 1033
            });

            var communicationSiteResult = await clientContext.CreateSiteAsync(new OfficeDevPnP.Core.Sites.CommunicationSiteCollectionCreationInformation()
            {
                Url = siteUrl2,
                Title = "Modern no group Site Test",
                Description = "Site description",
                Lcid 
 });
所以,我在我的租户中创建了仅应用程序注册,然后我尝试了这个代码,它说我未经授权

我得到的错误是:

 {
      "Message": "An error has occurred.",
      "ExceptionMessage": "Token request failed.",
      "ExceptionType": "Microsoft.IdentityModel.SecurityTokenService.RequestFailedException",
      "StackTrace": "   at SharePointPnP.IdentityModel.Extensions.S2S.Protocols.OAuth2.OAuth2S2SClient.Issue(String securityTokenServiceUrl, OAuth2AccessTokenRequest oauth2Request)\r\n   at OfficeDevPnP.Core.Utilities.TokenHelper.GetAppOnlyAccessToken(String targetPrincipalName, String targetHost, String targetRealm)\r\n   at OfficeDevPnP.Core.AuthenticationManager.EnsureToken(String siteUrl, String realm, String appId, String appSecret, String acsHostUrl, String globalEndPointPrefix)\r\n   at OfficeDevPnP.Core.AuthenticationManager.GetAppOnlyAuthenticatedContext(String siteUrl, String realm, String appId, String appSecret, String acsHostUrl, String globalEndPointPrefix)\r\n   at OfficeDevPnP.Core.AuthenticationManager.GetAppOnlyAuthenticatedContext(String siteUrl, String appId, String appSecret)\r\n   at LuloWebApi.Controllers.TenantController.<Test>d__1.MoveNext() in C:\\Users\\levalencia30\\Source\\Repos\\LuloBackend\\TenantManagementWebApi\\Controllers\\TenantController.cs:line 42\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Threading.Tasks.TaskHelpersExtensions.<CastToObject>d__3`1.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Controllers.ApiControllerActionInvoker.<InvokeActionAsyncCore>d__0.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__2.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Filters.AuthorizationFilterAttribute.<ExecuteAuthorizationFilterAsyncCore>d__2.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__1.MoveNext()",
      "InnerException": {
        "Message": "An error has occurred.",
        "ExceptionMessage": "The remote server returned an error: (401) Unauthorized.",
        "ExceptionType": "System.Net.WebException",
        "StackTrace": "   at System.Net.HttpWebRequest.GetResponse()\r\n   at SharePointPnP.IdentityModel.Extensions.S2S.Protocols.OAuth2.OAuth2WebRequest.GetResponse()\r\n   at SharePointPnP.IdentityModel.Extensions.S2S.Protocols.OAuth2.OAuth2S2SClient.Issue(String securityTokenServiceUrl, OAuth2AccessTokenRequest oauth2Request)"
      }
    }
{
“消息”:“发生错误。”,
“ExceptionMessage”:“令牌请求失败。”,
“例外类型”:“Microsoft.IdentityModel.SecurityTokenService.RequestFailedException”,
“StackTrace”:“在OfficeDevPnP.Core.UtilityModel.Extensions.S2S.Protocols.OAuth2.OAuth2sClient.Issue(字符串securityTokenServiceUrl,OAuth2AccessTokenRequest oauth2Request)\r\n在OfficeDevPnPn.Core.Utilities.TokenHelper.GetAppOnlyAccessToken(字符串targetPrincipalName,字符串targetHost,字符串targetRealm)\r\n在OfficeDevPnP.Core.AuthenticationManager.EnsureToken(字符串siteUrl、字符串领域、字符串appId、字符串appSecret、字符串acsHostUrl、字符串globalEndPointPrefix)处\r\n在OfficeDevPnP.Core.AuthenticationManager.GetAppOnlyAuthenticatedContext处(字符串siteUrl、字符串领域、字符串appId、字符串appSecret、字符串acsHostUrl、字符串globalEndPointPrefix)\r\n位于OfficeDevPnP.Core.AuthenticationManager.GetAppOnlyAuthenticatedContext(字符串siteUrl、字符串appId、字符串appSecret)\r\n位于LulowBapi.Controllers.TenantController.d\u 1.MoveNext()在C:\\Users\\levalencia30\\Source\\Repos\\LuloBackend\\TenantManagementWebApi\\Controllers\\TenantController.cs中:第42行\r\n--从引发异常的上一个位置开始的堆栈结束跟踪----\r\n在System.Runtime.CompilerServices.TaskWaiter.ThrowForOnSuccess(任务)\r\n在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)\r\n在System.Threading.Tasks.TaskHelperExtensions.d_u3`1.MoveNext()\r\n---从引发异常的上一个位置开始的堆栈结束跟踪---\r\n在System.Runtime.CompilerServices.TaskAwaiter.ThrowforOnSuccess(任务任务任务)\r\n位于System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)\r\n位于System.Web.Http.Controllers.ApiControllerActionInvoker.d_u0.MoveNext()\r\n---来自引发异常的上一个位置的堆栈结束跟踪---\r\n位于System.Runtime.CompilerServices.TaskAwaiter.ThrowForOnSuccess(任务任务)\r\n位于System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)\r\n位于System.Web.Http.Controllers.ActionFilterResult.d\u 2.MoveNext()\r\n---来自引发异常的上一个位置的堆栈结束跟踪----\r\n位于System.Runtime.CompilerServices.TaskAwaiter.ThrowforOnSuccess(任务任务)\r\n位于System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)\r\n位于System.Web.Http.Filters.AuthorizationFilterAttribute.d\u 2.MoveNext()\r\n--从引发异常的上一个位置开始的堆栈结束跟踪---\r\n位于System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)\r\n位于System.Runtime.CompilerServices.TaskWaiter.HandleNonSuccessAndDebuggerNotification(任务任务)\r\n位于System.Web.Http.Dispatcher.HttpControllerDispatcher.d_u1.MoveNext()“,
“内部异常”:{
“消息”:“发生错误。”,
“ExceptionMessage”:“远程服务器返回错误:(401)未经授权。”,
“ExceptionType”:“System.Net.WebException”,
“StackTrace”:“在System.Net.HttpWebRequest.GetResponse()\r\n在SharePointPnP.IdentityModel.Extensions.S2S.Protocols.OAuth2.OAuth2WebRequest.GetResponse()\r\n在SharePointPnP.IdentityModel.Extensions.S2S.Protocols.OAuth2s.Issue(字符串securityTokenServiceUrl,OAuth2AccessTokenRequest oauth2Request oauth2Request)”
}
}
根据,到目前为止,还不可能使用PnP。在开发分支中对其进行了代码更改,以便您可以复制它并创建自己的CreateSiteAsync扩展方法,并将sitecollection.cs复制到自己的项目中

如果失败,您可以根据相关CreateAsync方法中的代码自己调用RESTAPI


编辑:我无法让只有ClientId和secret才能运行的应用程序运行。请尝试ClientId和Cert方法概述

您不能这样做。您可以尝试在开发分支中更改它的代码。这将允许您复制它并创建CreateSiteAsync扩展方法,只需将siteCollection.cs复制到您的项目中。

您好,您可以共享该应用程序吗您正在使用的XML?您在哪个级别注册了应用程序。它应该在管理中心中创建,并且可以访问租户级别。什么应用程序XML?它具有完整的租户权限您在Appinv.aspx页面中使用的任务XML?为客户端ID生成的客户端机密在一年后过期。应重新生成并分配新的客户端ID这个客户ID。你在这里提到我自己的问题?自我链接