Why is a HeaderValue authentication scheme needed?

I set the HttpClient authorization HttpClient as follows:

 httpClient .DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(null, "abc"); 

... but I get an exception:

HeaderValue authentication "scheme" cannot be null.

Why is an AuthenticationHeaderValue scheme needed? Is this required for a specific RFC?

+6
source share
2 answers

The scheme is used to determine which authentication you are using:

  • The main
  • OAuth
  • Channel
  • Digest
  • and etc.

The title will look like this:

 { "key": "Authorization", "value": "<scheme> <parameter>" } 

Try using Postman to find out what is based on the various authentication types supported by HTTP.

+11
source

Sometimes you cannot set an authorization header with a scheme. This also applies to the project I'm currently working on. I need to connect to the API from TOPdesk , but no schema is specified.

The authorization header from TOPdesk should have a value similar to TOKEN id="0d1739df-8952-41c0-94cd-b25287446b22" so I can not use the scheme. I solved the problem by adding an authorization header, as in the following example, and it works like a charm.

 client.DefaultRequestHeaders.Add("Authorization", $"TOKEN id=\"{token}\""); 

I know this is an old question, but I thought that maybe someone in the future would look at this answer and find it useful. I came across this question in exactly the same way.

+3
source

Source: https://habr.com/ru/post/1257992/


All Articles