update external API credentials
This commit is contained in:
@@ -121,54 +121,6 @@ public class LayersController : Controller
|
||||
}
|
||||
}
|
||||
[HttpGet]
|
||||
[Route("getForPowerBI/{apiKey}/{number:int}")]
|
||||
public IActionResult GetByNumber(string apiKey, int number)
|
||||
{
|
||||
if (apiKey != _configuration["apiKey"])
|
||||
{
|
||||
_logger.LogWarning("PowerBI: Unauthorized request - wrong apiKey for layer {LayerNumber}", number);
|
||||
return Unauthorized();
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if (!Request.Headers.TryGetValue("Authorization", out var authHeader))
|
||||
{
|
||||
_logger.LogWarning("PowerBI: Unauthorized request - no authorization header for layer {LayerNumber}", number);
|
||||
return Unauthorized();
|
||||
}
|
||||
|
||||
var credentialsArr = authHeader.ToString().Split(" ");
|
||||
if (credentialsArr.Length != 2)
|
||||
{
|
||||
_logger.LogWarning("PowerBI: Unauthorized request - wrong auth header format for layer {LayerNumber}", number);
|
||||
return Unauthorized();
|
||||
}
|
||||
|
||||
var authValue = Encoding.UTF8.GetString(Convert.FromBase64String(credentialsArr[1]));
|
||||
var username = authValue.Split(':')[0];
|
||||
var password = authValue.Split(':')[1];
|
||||
if (username != _configuration["powerBI-user"] || password != _configuration["powerBI-pass"])
|
||||
{
|
||||
_logger.LogWarning("PowerBI: Unauthorized request - bad credentials for layer {LayerNumber}", number);
|
||||
return Unauthorized();
|
||||
}
|
||||
|
||||
_logger.LogInformation("PowerBI: Sending data for layer {LayerNumber}", number);
|
||||
|
||||
var layer = _db.Layers
|
||||
.Include(x => x.CreatedBy)
|
||||
.Include(x => x.Records).AsNoTracking().First(x => x.Number == number && !x.IsDeleted);
|
||||
|
||||
return Ok(layer);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_logger.LogError(e, "PowerBI: Error occurred while processing layer {LayerNumber}", number);
|
||||
return BadRequest(e.ToString());
|
||||
}
|
||||
}
|
||||
[HttpGet]
|
||||
[Route("getConfiguration/{apiKey}/{number:int}")]
|
||||
[AllowAnonymous]
|
||||
public IActionResult GetConfigurationByNumber(string apiKey, int number)
|
||||
@@ -197,7 +149,7 @@ public class LayersController : Controller
|
||||
var authValue = Encoding.UTF8.GetString(Convert.FromBase64String(credentialsArr[1]));
|
||||
var username = authValue.Split(':')[0];
|
||||
var password = authValue.Split(':')[1];
|
||||
if (username != _configuration["morska-user"] || password != _configuration["morska-pass"])
|
||||
if (username != _configuration["apiUser"] || password != _configuration["apiPass"])
|
||||
{
|
||||
_logger.LogWarning("Configuration: Unauthorized request - bad credentials for layer {LayerNumber}", number);
|
||||
return Unauthorized();
|
||||
|
||||
Reference in New Issue
Block a user