Research on authorization in SharePoint rest

Source: Internet
Author: User
Tags oauth

Blog Address: Http://blog.csdn.net/FoxDaveWhen we develop a SharePoint app that calls the rest service, you can use OAuth to complete authorization, or you can use a cross-domain library. Here is a note from Microsoft experts. If you are calling SharePoint from a remote managed application that cannot exclusively use client code (HTML and JavaScript), and there is no firewall blocking between SharePoint and the application, you can use the OAuth 2.0 token (using Microsoft Access Control Service (ACS) acts as a security token server. ) will be a good OAuth replacement.    MSDN library article, "SharePoint 2013 Data access Options" (bit.ly/wgvt9l). But these are mostly for SharePoint apps, what do we do when we want to get SharePoint content through rest in our own apps, such as third-party websites, mobile devices, and so on? The author has done the following research, but did not arrive at the final solution, the former asked Jason Huang, later did not have any tidings. Welcome to Daniel can guide, but also welcome a lot of discussion. let me describe the general scenario: remote SharePoint Sites with authentication with the NTLM protocol. All I have to do is get the data by invoking the rest service. This article takes the command-line program as an example to access SharePoint content.
I. How to use network request (WebRequest)
HttpWebRequest request = (HttpWebRequest) webrequest.create ("https://ap.2013.trial.nintex.com/_api/web/");            Request. Accept = "Application/json;odata=verbose";            NetworkCredential mycredential = new NetworkCredential ("Justin.liu1", "3qf0\" GN "," EXT ");            Request. Credentials = mycredential;            WebResponse response = Request. GetResponse ();            Stream stream = Response. GetResponseStream ();            StreamReader sr = new StreamReader (stream);            String content = Sr. ReadToEnd ();
this way to get the data I need, the process of grabbing a packet can see the network request is as follows:??The basic process is as follows:go to the door first, remote SharePoint responds "I'm in", then validates with the provided credentials, validates the pass-through encoding string, and then requests the required data through this encoding string, and the remote SharePoint authentication returns the requested data.
two. Using the client object model Csom approach
NetworkCredential mycredential = new NetworkCredential ("Justin.liu1", "3qf0\" GN "," EXT "); ClientContext CTX = new ClientContext ("https://ap.2013.trial.nintex.com/");            CTx. Credentials = mycredential;            Web Web = ctx. Web;            CTx. Load (web);            CTx. ExecuteQuery ();            string title = web. Title;
This approach also gets the data I need to take a look at the process of grabbing the package:from what we can see, the Csom actually encapsulates the webservice of SharePoint.
three. How to call SharePoint WebService
Site url:https://ap.2013.trial.nintex.com//username:ext\justin.liu1//password:3qf0 "gn var soapenv = string. Format (@ "<?xml version=" "1.0" "encoding=" "Utf-8" "?> <soap:envelope xmlns:xsi=" "http://www.w3.o Rg/2001/xmlschema-instance "" xmlns:xsd= "" Http://www.w3.org/2001/XMLSchema "" xmlns:soap= ""/HTTP/ schemas.xmlsoap.org/soap/envelope/"" > <soap:Body> <login xmlns= "" H                          Ttp://schemas.microsoft.com/sharepoint/soap/"" > <username>{0}</username> <password>{1}</password> </Login> </soap:            Body> </soap:Envelope> "," ext\\justin.liu1 "," 3qf0\ "GN");            byte[] data = Encoding.UTF8.GetBytes (soapenv); HttpWebRequest loginrequest = (HttpWebRequest) webrequest.create ("https://ap.2013.trial.nintex.com/_vti_bin/ AuthenticAtion.asmx ");            loginrequest.headers["soapaction"] = "http://schemas.microsoft.com/sharepoint/soap/Login";            Loginrequest.method = "POST"; Loginrequest.contenttype = "Text/xml;            Charset=utf-8 "; Loginrequest.contentlength = data.            Length;            Stream requeststream = Loginrequest.getrequeststream (); requestStream.Write (data, 0, data.            Length);            Requeststream.close ();            WebResponse loginresponse = Loginrequest.getresponse ();            Stream Loginstream = Loginresponse.getresponsestream ();            StreamReader LSR = new StreamReader (loginstream); String logincontent = LSR.            ReadToEnd (); Requeststream.close ();
the method did not succeed and reported 401 Unauthorized errors: Why I try the third way, because the first two ways should not be applied on the mobile device.
The above is the summary of the previous study, because there are other things to put aside and share, I hope that friends can play a role, but also welcome to discuss the solution together.

Research on authorization in SharePoint rest

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.