RestSharp - Token authentication

Kévin Buzit picture Kévin Buzit · Mar 19, 2018 · Viewed 13.4k times · Source

I'm trying to send a GET request with a token authentication, but i get an unauthorized response. If i send the same request on Postman, it works.

Here's my code :

string url = string.Format("{0}batchs", MyUrl);
RestClient client = new RestClient(url);
RestRequest getRequest = new RestRequest(Method.GET);
getRequest.AddHeader("Accept", "application/json");
getRequest.AddHeader("Authorization", "token " + MyToken);
getRequest.AddParameter("name", MyName, ParameterType.QueryString);

IRestResponse getResponse = client.Execute(getRequest);

And here's my postman request :

Postman request

Any ideas on how to correct this ?

Thanks !

Answer

Swisscheese picture Swisscheese · Mar 29, 2018

I'm not sure exactly what kind of auth you're using, but I use a firebase token generated at runtime, and this is the only thing I could get to work for me.

request.AddHeader("authorization", "Bearer " + _fireBaseService.AuthToken);