Adding security
This commit is contained in:
+72
@@ -0,0 +1,72 @@
|
||||
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<WeatherForecastController> _logger;
|
||||
|
||||
private readonly ApiSecurityConfiguration _apiSecurityConfiguration;
|
||||
|
||||
public WeatherForecastController(ILogger<WeatherForecastController> logger, ApiSecurityConfiguration apiSecurityConfiguration)
|
||||
{
|
||||
_logger = logger;
|
||||
_apiSecurityConfiguration = apiSecurityConfiguration;
|
||||
}
|
||||
|
||||
[HttpGet("GetWeatherForecast", Name = "GetWeatherForecast")]
|
||||
public IEnumerable<WeatherForecast> 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<IActionResult> 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<IActionResult> 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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user