0

I want to use RestSharp to issue Api calls to Gerrit but I'm having trouble with authentication.

For example there is the curl command which works:

curl --digest --user VladDracul:5SAbg1pFWyqsvcs4aB7aGL2lISh8fuOjcoQK9WRGSA http://localhost:8080/a/groups/

but how can I give the --user to a restSharp call?

myAuth = new HttpBasicAuthenticator("VladDracul","5SAbg1pFWyqsvcs4aB7aGL2lISh8fuOjcoQK9WRGSA");
restClient = new RestClient(BaseUrl);
restClient.Authenticator = myAuth;

 var request = new RestRequest(Method.GET);
 request.Resource = "/a/groups/";
 request.AddHeader("Content-type", "application/json");

 var response = restClient.Execute(request);

The response I get is "Unauthorized"

UrsulRosu
  • 487
  • 1
  • 5
  • 15

1 Answers1

0

I found the answer. Adding the line gets it working.

 var request = new RestRequest(Method.GET);
 request.Credentials = new NetworkCredential("VladDracul", "5SAbg1pFWyqsvcs4aB7aGL2lISh8fuOjcoQK9WRGSA");;
 request.Resource = "/a/groups/";
 request.AddHeader("Content-type", "application/json");
UrsulRosu
  • 487
  • 1
  • 5
  • 15