It is impossible to do everything with SharePoint Restful API without using SOM. So, I have to implemented a custom Restful API. I will call this method via enpoint like this
http://myservername/_api/exportservice/students
However, when I call a method within the custom API, it will throw authentication error. I debug into this function and see that the ClientContext requires to pass a credential to execute. I can pass the credential to the client context, but I do not know how to pass the current credential from the SharePoint Context. This means that in this case, I have login to SharePoint already, and the method called needs to execute under this credential.
ClientContext context = new ClientContext("http://101hoanvd");context.Credentials = new NetworkCredential("username", "132456", "domain");I also cannot obtain CurrentUser by following code since they are two different contexts.
var user = SPContext.Current.Web.CurrentUser;
Can I use obtained DigestToken from SharePoint page to pass to the API method in order to pass the credential or something like that to the context inside custom API method?
Thanks,
Hoan.