Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting Authorization header on an HttpClient instance does not work in .NET Core 2.1 #1684

Closed
pereiraarun opened this issue Jun 11, 2018 · 3 comments

Comments

@pereiraarun
Copy link

pereiraarun commented Jun 11, 2018

Testing on .NET Core 2.1 (by setting Target Framework 2.1), the following code results in a 403 Forbidden since the header is not set correctly.
Header is set using the following method:

client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Token", "9ac..b87b20");
var result = client.GetStringAsync("/api/ipam/prefixes/").Result;

Moving back to .NET Core 2.0 (by setting Target Framework 2.0) fixes the issue. The same happens when using RestSharp. Seems there is some bug with HttpClient and setting authorization headers.

Testing through: Vs Professional 2017 (15.7.3) on Windows 10 with the latest updates.

@brockallen
Copy link

Are you sure the scheme is correct? Normally it should be "Bearer" (not "Token") if you're doing an OAuth2 style client.

@pereiraarun
Copy link
Author

The code works as posted in .Net Core 2.0. The code is used for https://netbox.readthedocs.io/en/latest/api/authentication/

$ curl -H "Authorization: Token d2f763479f703d80de0ec15254237bc651f9cdc0" -H "Accept: application/json; indent=4" http://localhost/api/dcim/sites/
{
"count": 10,
"next": null,
"previous": null,
"results": [...]
}

@Petermarcu
Copy link
Member

Issue moved to dotnet/corefx #30349 via ZenHub

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants