I have the SharePoint list url to fetch the data(XML /JSON). To access that url I have username and password.

In IOS native development using nsurl to pass username and password. Able to connect and get the data.

If am use the same in JavaScript HTTP GET or POST. How do authenticate? to get list data

Any one can help me.

1 Answer 1


SharePoint REST API doesnt support authentication. Incase of O365, you can use OAuth concept to get your app authenticated (But you have on-prem environment). So you have to use the concept, which is to create a proxy layer between the App and the SharePoint environment. The best way to is to use WCF Web Service and get the authentication token using that but alternatively (workaround approach) you can use following approach.

  1. Create a new SP Farm Solution and an application page to it (lets name servicemethods.aspx).
  2. Change the application page base class to inherit form UnsecuredLayoutsPageBase, which make your page accessible to even user don't have permission.
  3. Create the static web methods within this page, so that user can call it. The code will look like following:
    [WebMethod] [ScriptMethod(ResponseFormat = ResponseFormat.Json)] public static string yourFunctionName(string name, string password) {.....
  4. Now use the JavaScript/JQuery or native iOS feature to call the web method. The URL will look like http://yourDomain.com/pathToSiteCollection/_layouts/15/SolutionName/servicemethods.aspx/yourFunctionName. If you are using JQ, you can use the ajax data attribute to pass credentials (ex. $.ajax({url: url, data: {name: "domain\user", password: "password"}..... A HTTPS connection is highly recommended for such task.
  5. Now in the web method body, you can use SP client object to check if user is valid or not.
  6. If user is valid, you can generate a token (I use GUID) and make an entry in list about the token. Pass this token to your app. If user is invalid, pass an empty string.
  7. Create all other required web method in same page, and pass the above retrieved token in all calls. Check the list contains token or not, if yes, then process the data and send the response back, else show login to user.
  8. You can add a List Workflow for token list to delete all the items which create 24hrs ago so that user have to login once in a day.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.