public ApiClient(
     IRestClientFactory clientFactory,
     string baseUrl,
     AuthorityDetails authDetails,
     ILogger <ApiClient> logger)
 {
     Client      = clientFactory.CreateClient(baseUrl);
     RestFactory = clientFactory;
     if (authDetails != null)
     {
         Token = GetToken(authDetails);
     }
     Logger = logger;
 }
        protected virtual TokenResponse GetToken(AuthorityDetails authDetails)
        {
            var client  = RestFactory.CreateClient(authDetails.ClientUrl);
            var request = RestFactory.CreateRequest("token", Method.POST);

            request.AddHeader("Content-Type", "application/x-www-form-urlencoded");
            request.AddHeader("Accept", "application/json");
            request.AddParameter("grant_type", "client_credentials");
            request.AddParameter("resource", authDetails.ResourceUrl);
            if (!string.IsNullOrEmpty(authDetails.Scope))
            {
                request.AddParameter(JwtClaimTypes.Scope, authDetails.Scope);
            }
            client.Authenticator = new HttpBasicAuthenticator(authDetails.ClientId, authDetails.ClientSecret);
            var response = client.Execute <TokenResponse>(request);

            return(response?.Data);
        }