Retrieve OwinContext/Authenticator for scheduled job

How can I retrieve the current Owin environment or context for a scheduled job executed by Hangfire?

I have Hangfire running in a self-hosted Owin Windows service. It’s configured to use Windows authentication and I can get that to work with the dashboard and custom authentication filter.

I don’t have a RequestContext or HttpRequest for a scheduled job started by Hangfire, right? So, how do I retrieve the current authenticator/credentials?

I guess the standard windows methods for authentication information are all that’s needed.

For submitting new RestSharp requests just use the default NtlmAuthenticator to submit authenticated requests from an enqueued job. Set up the service with a domain account login.

var client = new RestClient(Properties.Settings.Default.BaseAPIUrl)
{
    Authenticator = new NtlmAuthenticator() ,
    PreAuthenticate = true
};

Hmm. You really can’t.

A running job doesn’t have a user in the same sense as an authenticated web request would. The job’s identity comes from the identity its hosting process is running as. In your case whatever user your windows service runs as.

If you want to associate a user with your job. You would need to pass in some logical representation of your user as a job parameter, and it would be up to your job function to pay attention to that value and act accordingly.

There’s no request or response or user or related contexts. A running job is just code running in a process.

Sorry if I misunderstood.

My service requires authentication for any incoming requests to the APIs and scheduled jobs needed to call the APIs. Just using the service’s domain login as shown above and adding local permissions for that account got the job done.