public override void OnActionExecuting(ActionExecutingContext context) { base.OnActionExecuting(context); // Only if in production, where Azure AD is present, add the fetching of the auth token and pass it along. if (Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") == "Production") { client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", Request.Headers["X-MS-TOKEN-AAD-ACCESS-TOKEN"]); clientRating = new RatingsClient(client); clientRatingType = new RatingTypesClient(client); clientRating.BaseUrl = _config.GetValue <string>("APIBaseURL"); clientRatingType.BaseUrl = _config.GetValue <string>("APIBaseURL"); } }
public RatingsController(IConfiguration config) { _config = config; // Only if in production, replace the base URL of the clients that were auto-generated. if (Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") == "Production") { clientRating = new RatingsClient(client); clientRatingType = new RatingTypesClient(client); clientRating.BaseUrl = _config.GetValue <string>("APIBaseURL"); clientRatingType.BaseUrl = _config.GetValue <string>("APIBaseURL"); } else { clientRating = new RatingsClient(client); clientRatingType = new RatingTypesClient(client); } }