简体   繁体   English

SharePoint 仅应用程序身份验证抛出“远程服务器返回错误:(401)未经授权。”

[英]SharePoint App-Only Authentication throwing “The remote server returned an error: (401) Unauthorized.”

I am trying to make sharepoint authentication using oAuth or App-Only authentication, but it gives error "The remote server returned an error: (401) Unauthorized."我正在尝试使用 oAuth 或 App-Only 身份验证进行 sharepoint 身份验证,但它给出了错误“远程服务器返回错误:(401)未经授权。”

I am using trial sharepoint tenant.我正在使用试用版 sharepoint 租户。

Here is my code snippets:这是我的代码片段:

Using Client id & Client secret:使用客户端 ID 和客户端密码:

string siteUrl = "[Sharepoint-Site-URL]";

//Sharepoint App details
string SPClientId = @"[Client-id]";
string SPClientSecret = @"[Client-secret]";
using (ClientContext context = new OfficeDevPnP.Core.AuthenticationManager().GetAppOnlyAuthenticatedContext(siteUrl, SPClientId, SPClientSecret))
 {
     context.Load(context.Web, t => t.Title);
     context.ExecuteQuery();
     Console.WriteLine(context.Web.Title);
 };

Using AccessToken:使用访问令牌:

 string siteUrl = "[Sharepoint-Site-URL]";
 string realm = TokenHelper.GetRealmFromTargetUrl(new Uri(siteUrl));

 //Get the access token for the URL.  
 string accessToken = TokenHelper.GetAppOnlyAccessToken(TokenHelper.SharePointPrincipal, new Uri(siteUrl).Authority, realm).AccessToken;

 //Create a client context object based on the retrieved access token
 using (ClientContext context = TokenHelper.GetClientContextWithAccessToken(siteUrl, accessToken))
 {
    context.Load(cc.Web, t => t.Title);
    context.ExecuteQuery();
    Console.WriteLine(cc.Web.Title);
 }
enter code here

I referred below articles: https://docs.microsoft.com/en-us/sharepoint/dev/solution-guidance/security-apponly-azureacs https://www.c-sharpcorner.com/article/connect-to-sharepoint-online-site-with-app-only-authentication/我参考了以下文章: https: //docs.microsoft.com/en-us/sharepoint/dev/solution-guidance/security-apponly-azureacs https://www.c-sharpcorner.com/article/connect-to- sharepoint-online-site-with-app-only-authentication/

This could be SharePoint app-only permissions is disabled in your tenant.这可能是 SharePoint 在您的租户中禁用了仅应用权限。

You could run the command to enabel it: Set-SPOTenant -DisableCustomAppAuthentication $false您可以运行命令来启用它: Set-SPOTenant -DisableCustomAppAuthentication $false

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 远程服务器返回错误:(401) Unauthorized。 Twitter oAuth - The remote server returned an error: (401) Unauthorized. Twitter oAuth 远程服务器返回错误:(401)未经授权。 wcf httpbinding基本 - The remote server returned an error: (401) Unauthorized. wcf httpbinding basic 远程服务器返回错误:(401)未授权的sharepoint - The remote server returned an error: (401) Unauthorized sharepoint C#JIRA工作日志更新错误“远程服务器返回错误:(401)未经授权。” - C# JIRA work-log update error “The remote server returned an error: (401) Unauthorized.” System.Net.WebException:远程服务器返回错误:(401)未经授权。 在System.Net.HttpWebRequest.GetResponse() - System.Net.WebException: The remote server returned an error: (401) Unauthorized. at System.Net.HttpWebRequest.GetResponse() 远程服务器返回错误:(401) 未经授权。 在 Visa 开发支付网关 - The remote server returned an error: (401) Unauthorized. In Visa develope payment Gateway 为什么我收到“远程服务器返回错误:(401) 未经授权”。 从这个代码片段? - Why am I getting 'The remote server returned an error: (401) Unauthorized.' from this code snippet? 出现错误:远程服务器返回错误:(401)未经授权。 ,同时将我的网站评论发布到Twitter。 使用C# - Getting error : The remote server returned an error: (401) Unauthorized. , while posting my website comments to twitter. Using C# 错误远程服务器返回错误:(401)未经授权 - Error The remote server returned an error: (401) Unauthorized EWS:“远程服务器返回错误(401)未经授权” - EWS: “The remote server returned error (401) Unauthorized”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM