Search code examples
c#.netasp.net-mvcrestful-authentication

HttpBasicAuthenticator Authentication Issue


I have just started to work on 3rd party API Integration. In the Postman Client API Call, I have used authorization key in the header and bearer with token. When I started to integrate with my C# code. I used HttpBasicAuthenticator to authenticate the API with access token. But it automatically appends "basic" as String with the token instead of that I want it to append "bearer".

Can you please help me out. How can I do that?

Help is appreciated. Thanks

client.Authenticator = new HttpBasicAuthenticator(x, string.Format("Bearer {0}",ApiToken));

Solution

  • You are using wrong Authenticator,

    If you want to use Bearer token to access the API Endpoint, you can use JwtAuthenticator

    Try,

    client.Authenticator = new JwtAuthenticator(ApiToken);
    

    Which solve your problem.