feat(AuthController): Login-Methode mit Body für Verbraucher-APIs hinzugefügt.
This commit is contained in:
parent
79eaa06ed4
commit
7bab2657d4
@ -81,12 +81,12 @@ namespace DigitalData.Auth.API.Controllers
|
||||
}
|
||||
|
||||
private async Task<IActionResult> CreateTokenAsync(ConsumerApiLogin login, bool cookie = true)
|
||||
{
|
||||
if (!await _consumerApiService.VerifyAsync(login.Name, login.Password))
|
||||
return Unauthorized();
|
||||
|
||||
{
|
||||
var api = await _consumerApiService.ReadByNameAsync(login.Name);
|
||||
|
||||
if (api is null || api.Password != login.Password)
|
||||
return Unauthorized();
|
||||
|
||||
if (!_cryptoFactory.TokenDescriptors.TryGet(_apiParams.Issuer, _apiParams.DefaultConsumer.Audience, out var descriptor) || descriptor is null)
|
||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||
|
||||
@ -162,6 +162,20 @@ namespace DigitalData.Auth.API.Controllers
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost()]
|
||||
public async Task<IActionResult> CreateTokenViaBody([FromBody] ConsumerApiLogin login, [FromQuery] bool cookie = false)
|
||||
{
|
||||
try
|
||||
{
|
||||
return await CreateTokenAsync(login, cookie);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "{Message}", ex.Message);
|
||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("check")]
|
||||
[Authorize]
|
||||
public IActionResult Check() => Ok();
|
||||
|
||||
@ -8,7 +8,7 @@ namespace DigitalData.Auth.API.Services
|
||||
{
|
||||
public static IServiceCollection AddConsumerApiServiceFromConfiguration(this IServiceCollection services, IConfiguration configuration, string key = "ConsumerAPIs")
|
||||
{
|
||||
var consumerApis = configuration.GetSection("ConsumerAPIs").Get<List<ConsumerApi>>() ?? throw new InvalidOperationException($"No Consumer list found in {key} in configuration.");
|
||||
var consumerApis = configuration.GetSection("ConsumerAPIs").Get<IEnumerable<ConsumerApi>>() ?? throw new InvalidOperationException($"No Consumer list found in {key} in configuration.");
|
||||
services.AddSingleton(Options.Create(consumerApis));
|
||||
services.AddSingleton<IConsumerApiService, ConfiguredConsumerApiService>();
|
||||
return services;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user