using Flurl; using Flurl.Http; using LCU.Library.Internal.ApiSecurity.Constants; using LCU.Library.Internal.ApiSecurity.Models; using Microsoft.AspNetCore.Mvc; namespace IntegrationTestApiOne.Controllers; [ApiController] [Route("[controller]")] public class WeatherForecastController : ControllerBase { private static readonly string[] Summaries = new[] { "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" }; private readonly ILogger _logger; private readonly ApiSecurityConfiguration _apiSecurityConfiguration; public WeatherForecastController(ILogger logger, ApiSecurityConfiguration apiSecurityConfiguration) { _logger = logger; _apiSecurityConfiguration = apiSecurityConfiguration; } [HttpGet("GetWeatherForecast", Name = "GetWeatherForecast")] public IEnumerable Get() { return Enumerable.Range(1, 5) .Select(index => new WeatherForecast { Date = DateTime.Now.AddDays(index), TemperatureC = Random.Shared.Next(-20, 55), Summary = Summaries[Random.Shared.Next(Summaries.Length)] }) .ToArray(); } [HttpGet("RunTestApiKeyAuthenticatedRequest", Name = "RunTestApiKeyAuthenticatedRequest")] [ProducesResponseType(200)] [ProducesResponseType(500)] public async Task RunTestApiKeyAuthenticatedRequest() { var client = "TestTenantOne"; var apiKey = _apiSecurityConfiguration.InternalApiKeySet[client]; var result = await "https://localhost:32003" .AppendPathSegment("WeatherForecast") .AppendPathSegment("GetWeatherForecast") .WithHeader(HeaderKeys.ApiKey, apiKey) .WithHeader(HeaderKeys.Client, client) .GetAsync(); return Ok(result.ResponseMessage.Content.ReadAsStringAsync().Result); } [HttpGet("RunTestApiKeyAuthenticatedRequestUsingMadeUpCreds", Name = "RunTestApiKeyAuthenticatedRequestUsingMadeUpCreds")] [ProducesResponseType(200)] [ProducesResponseType(500)] public async Task RunTestApiKeyAuthenticatedRequestUsingMadeUpCreds() { var result = await "https://localhost:32003" .AppendPathSegment("WeatherForecast") .AppendPathSegment("GetWeatherForecast") .WithHeader(HeaderKeys.ApiKey, "MadeUpApiKey") .WithHeader(HeaderKeys.Client, "MadeUpClient") .GetAsync(); return Ok(result.ResponseMessage.Content.ReadAsStringAsync().Result); } }