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

[BUG] Cannot access internal class AuthenticatedHttpClientHandler #999

Open
wojciechrak opened this issue Nov 12, 2020 · 2 comments
Open

Comments

@wojciechrak
Copy link

wojciechrak commented Nov 12, 2020

Describe the bug
When trying to use authentication handler, AuthenticatedHttpClientHandler like in the readme (ln 570), I get error

'AuthenticatedHttpClientHandler' is inaccessible due to its protection level

Steps To Reproduce (from readme.md)

class LoginViewModel
{
    public async Task LoginAndCallApi()
    {
        var api = RestService.For<IMyRestService>(new HttpClient(new AuthenticatedHttpClientHandler(GetToken)) { BaseAddress = new Uri("https://the.end.point/") });
        var location = await api.GetLocationOfRebelBase();
    }
}

interface IMyRestService
{
    [Get("/getPublicInfo")]
    Task<Foobar> SomePublicMethod();

    [Get("/secretStuff")]
    [Headers("Authorization: Bearer")]
    Task<Location> GetLocationOfRebelBase();
}

Expected behavior
AuthenticatedHttpClientHandler class is public

Version
5.2.1

@wojciechrak wojciechrak added the bug Something isn't working label Nov 12, 2020
@clairernovotny
Copy link
Member

Looks like the docs are out of date with respect to those types -- the functionality is there but you set the authentication delegate on RefitSettings, either AuthorizationHeaderValueWithParamGetter or AuthorizationHeaderValueGetter depending on your needs. The handlers are added in the pipeline when those are set.

Happy to take a PR that updates the docs :)

@clairernovotny clairernovotny added documentation up-for-grabs and removed bug Something isn't working labels Nov 23, 2020
@summersk
Copy link

summersk commented Dec 1, 2020

Could be helpful to draw attention the need for the Authorization header to already be present on the HttpRequestMessage (I think?). Appears that without, any configured settings delegates are not invoked (AuthenticatedHttpClientHandler.cs:23)

Will draft something else up if I get a spare moment - just wanted to drop this in for consideration because that won't be today!

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

No branches or pull requests

3 participants