public override void InitializeServiceClient <T>(ServiceClient <T> client) { if (!BasicMode) { // For bear mode // Step 1: get challenge response from /v2/ API. THe response Www-Authenticate header is token server URL. string challegeUrl = (LoginUrl.StartsWith("https://") ? "" : "https://") + LoginUrl + (LoginUrl.EndsWith("/") ? "" : "/") + "v2/"; HttpClient runtimeClient = new HttpClient(); HttpResponseMessage response = null; string tokenServerUrl = ""; try { response = runtimeClient.GetAsync(challegeUrl, RequestCancellationToken).GetAwaiter().GetResult(); tokenServerUrl = response.Headers.GetValues("Www-Authenticate").FirstOrDefault(); } catch (Exception e) { Console.WriteLine("v2 call throws exception {0}", e.Message); } if (!String.IsNullOrEmpty(tokenServerUrl)) { // Step 2: present username and password to token server to get access token // TODO: Call token server to get access token return; } } AuthHeader = EncodeTo64(Username + ":" + Password); }