Rest API中的SharePoint 2013远程身份验证 [英] SharePoint 2013 remote authentication in Rest API

查看:109
本文介绍了Rest API中的SharePoint 2013远程身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图从具有硬编码用户ID和密码的独立应用程序中使用SharePoint Rest API。
使用此方法可以正常运行。但我们正在尝试对当前登录用户(在独立应用程序中)进行身份验证,并使用Rest Call发送一些标头,以便SharePoint自行执行身份验证和授权,并向当前用户提供


Authorization < span style ="font-size:1.23em"> 持票人 < access_token>

Authorization:Bearer<access_token>

对当前用户进行身份验证。但文章中还提到该解决方案仅针对
SharePoint Online,而不是针对SharePoint内部部署(在我的情况下为SharePoint 2013)。 / span>

to authenticate the current user. But it is also mentioned in the article that the solution is specific to SharePoint Online only and not to the SharePoint On-Premise (SharePoint 2013 in my case).

所以我的问题是如何在SharePoint 2013中做同样的事情( 内部部署)

注意:


  1.      
    我想使用Rest API只是不想使用CSOM或JSOM
  2.      
    我不想创建任何提供商托管的应用程序(如果它是一种方式)
  3.      
    如果我在独立应用程序页面中的I-Frame中打开任何SharePoint页面,是否可以从那里获取一些cookie或令牌,然后传递给我的独立应用程序
    返回。 我是否可以将这些信息从我的独立应用程序传递到SharePoint,可以对登录用户进行身份验证。实际上,我想从我的独立应用程序将登录用户上下文传递给SharePoint。 
  1.       I want to use Rest API only don't want to use CSOM or JSOM
  2.       I don't want to create any provider hosted app (if it is a way)
  3.       If I open any SharePoint page in an I-Frame in my stand alone application page, is there way to grab some cookies or token from there and then pass to my standalone application back.  Can I pass these information from my standalone application to SharePoint can  authenticate the login user.  Actually I want to pass login user context to SharePoint from my standalone application. 

推荐答案

您好,

在内部部署中,我们可以使用NetworkCredential传递REST请求的凭据。

In on-premise, we can use NetworkCredential to pass the Credentials for the REST request.

以下代码供您参考:

var siteUrl = "http://sp2013/sites/team";
var listName = "CustomList";
var loginName = @"domain\username";
var password = "xxx";

HttpWebRequest endpointRequest = (HttpWebRequest)HttpWebRequest.Create(siteUrl+"/_api/web/lists/getByTitle('"+listName+"')/items");

endpointRequest.Method = "GET";
endpointRequest.Accept = "application/json;odata=verbose";
NetworkCredential cred = new System.Net.NetworkCredential(loginName,password);
endpointRequest.Credentials = cred;
HttpWebResponse endpointResponse = (HttpWebResponse)endpointRequest.GetResponse();
try
{
	WebResponse webResponse = endpointRequest.GetResponse();
	Stream webStream = webResponse.GetResponseStream();
	StreamReader responseReader = new StreamReader(webStream);
	string response = responseReader.ReadToEnd();
	JObject jobj = JObject.Parse(response);
	JArray jarr = (JArray)jobj["d"]["results"];
	foreach (JObject j in jarr)
	{
		Console.WriteLine(j["Title"]);
	}
	responseReader.Close();
	Console.ReadLine();
}
catch (Exception e)
{
	Console.Out.WriteLine(e.Message); Console.ReadLine();
}

更多信息:

https://www.c-sharpcorner.com/UploadFile/Roji.Joy/working- with-sharepoint-2013-rest-api-in-aC-Sharp-managed-code /

最好的问候,

丹尼斯


这篇关于Rest API中的SharePoint 2013远程身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆