How best to use Hangfire with API that requires bearer tokens

Tags: #<Tag:0x00007fe1d7c24f00>

Please note this is nothing to do with the Hangfire dashboard.

I have inherited a product that already uses Hangfire and it works to some extent but there must be a better way of doing what I’m about to describe.

The product uses IdentityServer3. Hangfire is used to queue up background/recurring jobs that are run by a gateway. These methods require a bearer token to run. What has previously been done is that the whole request (including the token) is serialised and sent to hangfire. This works fine until the serialised token in that request expires. Then the job won’t run any more.

Is there a way to have hangfire authenticate with Identity Server at Startup (ie it’s a client) so that we don’t need to do this crazy request serialisation?

This is all .NET 4.5.2

Thanks