Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/334.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
C# Can';无法获取SharePoint访问令牌_C#_Asp.net_Sharepoint_Oauth_Sharepoint 2013 - Fatal编程技术网

C# Can';无法获取SharePoint访问令牌

C# Can';无法获取SharePoint访问令牌,c#,asp.net,sharepoint,oauth,sharepoint-2013,C#,Asp.net,Sharepoint,Oauth,Sharepoint 2013,我已经在SharePoint 2013中使用AppRegNew.aspx创建了一个应用程序,从中我获得了一个应用程序机密和id。对于这个应用程序,我使用AppInv.aspx设置了对文档列表的读写权限 现在,我想使用另一个项目的应用程序secret和Id来访问文档列表。我正在使用TokenHelper类,如下所示: TokenHelper.GetAppOnlyAccessToken(TokenHelper.SharePointPrincipal, siteUri.Authority, realm

我已经在SharePoint 2013中使用AppRegNew.aspx创建了一个应用程序,从中我获得了一个应用程序机密和id。对于这个应用程序,我使用AppInv.aspx设置了对文档列表的读写权限

现在,我想使用另一个项目的应用程序secret和Id来访问文档列表。我正在使用TokenHelper类,如下所示:

TokenHelper.GetAppOnlyAccessToken(TokenHelper.SharePointPrincipal, siteUri.Authority, realm).AccessToken
但我有一个例外:

远程服务器返回错误:(404)未找到。-请求的命名空间不存在

我调试了TokeHelper类中的代码,发现异常来自此web调用:

其位于方法中:

private static JsonMetadataDocument GetMetadataDocument(string realm)

任何帮助都将不胜感激,谢谢:-)

最后我终于找到了答案。我使用了具有以下权限的SharePoint应用程序:

<AppPermissionRequests AllowAppOnlyPolicy="true">
  <AppPermissionRequest Scope="http://sharepoint/content/sitecollection/web/list" Right="Write">
    <Property Name="BaseTemplateId" Value="101"/>
  </AppPermissionRequest>
</AppPermissionRequests>
然后我使用TokenHelper类,如下所示:

var siteUri = new Uri("my_site_url");
TokenHelper.GetS2SAccessTokenWithWindowsIdentity(siteUri, null);

虽然你让它工作了,但这是两种不同的获得代币的方式虽然你让它工作了,但这是两种不同的获得代币的方式。出现错误的选项是低信任Oauth令牌,该令牌失败是因为GetMetadataDocument(字符串域)在内部使用webclient与ACS对话,如果您在代理环境中工作,则需要显式地将代理设置为webclient.proxy=new WebProxy(“myproxy.com”)。您得到的选项2是通过使用证书而不使用Oauth使其成为一个高度信任的应用程序
var siteUri = new Uri("my_site_url");
TokenHelper.GetS2SAccessTokenWithWindowsIdentity(siteUri, null);