public AccountManagerAccessTokenAccessor(IOptions <SFCCEnvironment> envOptions, IHttpClientFactory clientFactory, ILogger <AccountManagerAccessTokenAccessor> logger) { _environment = envOptions.Value; _environment.IsValidEnvironment(throwOnInvalid: true); _environment.HasClientCredentials(throwOnInvalid: true); _clientFactory = clientFactory; _logger = logger; }
private HttpClient GetClient() { HttpClient client; if (_env.HasClientCredentials()) { // use client provided by account manager integration client = _clientFactory.CreateClient("ClientCredentialsGrant"); } else { // Fallback behavior if no client credentials are available for the environment client = _clientFactory.CreateClient("BasicAuth"); var byteArray = Encoding.ASCII.GetBytes($"{_env.Username}:{_env.Password}"); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(byteArray)); } client.BaseAddress = new Uri($"https://{_env.Server}"); return(client); }