I created a provider hosted app for SharePoint 2013(OnPrem) which works with the standard "Tokenhelper.cs" to connect to SharePoint.
I use a certificate for authorization which works fine on my app.
Now I also have a TimerJob on the same machine, that needs to communicate with SharePoint. In my TimerJob I do not have any httpContext obviously, which is needed to use the following code:
var spContext = SharePointContextProvider.Current.GetSharePointContext(HttpContext.Current);
using (var appContext = spContext.CreateAppOnlyClientContextForSPHost()) {}
var web=appContext.Web;
clientContext.Load(web);
clientContext.ExecuteQuery();
I can connect using credentials instead:
var appContext= new ClientContext(siteUri);
appContext.Credentials = new NetworkCredential(username, password);
var web=appContext.Web;
clientContext.Load(web);
clientContext.ExecuteQuery();
But I do not want to use any credentials but pure Certificate authentication instead. How can this be done?