Skip to content
Discussion options

You must be logged in to vote

Refit does not auto-pick a handler based on whether an HttpContext is present. Each Refit client is bound to one HttpClient with one handler chain, so you decide which auth applies by which client you resolve. Two common patterns:

  1. Two separate Refit clients, one per grant type.
    Register the same interface twice as keyed clients (Refit supports AddKeyedRefitClient), each with its own DelegatingHandler:
// User-delegated (needs HttpContext)
services.AddKeyedRefitClient<IMyApi>("delegated")
        .ConfigureHttpClient(c => c.BaseAddress = baseUri)
        .AddHttpMessageHandler<DelegatedAuthHandler>();

// Machine-to-machine (client credentials, no HttpContext)
services.AddKeyedRefitClient<

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by glennawatson
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants