Zapnologica
Zapnologica

Reputation: 22556

How to Get a custom header value from an HttpAuthenticationContext

I am busy implementing and Authentication filter:

public Task AuthenticateAsync(HttpAuthenticationContext context, CancellationToken cancellationToken)
    {
        var request = context.Request;

        // Receive token from the client. Here is the example when token is in header:
        var token = request.Headers.FirstOrDefault(x => x.Key == "Token").Value.ToString();   //["Token"];

How do I get the header called token ? Because the above code doesn't work. I am guessing this is because its not a standard header.

Upvotes: 1

Views: 3199

Answers (2)

Carntel
Carntel

Reputation: 429

You should actually use

request.Headers.Authorization.Parameter;

Upvotes: 0

Suraj Shrestha
Suraj Shrestha

Reputation: 106

request.Headers.GetValues("token");

Upvotes: 3

Related Questions