0

I am trying to add authentication to api call in Rest sharp version 108.0.2

error : 'authority' should be in Uri format Parameter name: authority

I have upgraded the Restsharp version from 106 to 108 , Then here previously we are using HttpClient but there are some deprecated interfaces in that so i am trying to use RestClient but here i am unable to get below authmechanism.

var response = HttpClient.CallAsync<string>(new HttpClientArgs
        {
            Uri = new Uri(uri),
            Verb = HttpVerb.Put,
            HttpAuthMechanism = HttpAuthMechanism.AzureAd,
            AzureAdConfig = new AzureAdConfig()
            {
                ClientId = ClientID,
                ClientSecret = ClientSecret,
            ResourceId = ResourceID,
            TenantId = TenantID
            },
            Body = JsonConvert.SerializeObject(body)
        });
string Authority = String.Format(TenantID);
        AuthenticationContext ac = new AuthenticationContext(Authority);
        string resourceID = ResourceID;
        string clientID = ClientID;
        try
        {
            UserCredential uc = new UserCredential();
            Task<AuthenticationResult> task = ac.AcquireTokenAsync(resourceID, clientID, uc);
            task.Wait(10000);
            AuthenticationResult result = task.Result;
            string token = result.AccessToken;
            return token;
        }
        catch (Exception ex)
        {
            if (ex.InnerException.Message.ToLower().Contains("interactive authorization"))
            {
                string token = "prompt";
                return token;
            }
            return (ex.Message);
            throw ex;
        }
  • Does this answer your question? ['authority' should be in Uri format Parameter name: authority](https://stackoverflow.com/questions/30404915/authority-should-be-in-uri-format-parameter-name-authority) – Michael Freidgeim Nov 11 '22 at 07:49
  • There's no code here that uses RestSharp, which makes it totally impossible to understand what you are asking. – Alexey Zimarev Nov 23 '22 at 21:17

0 Answers0