Add basic auth to power bi endpoint
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
using DiunaBIWebAPI.dataImporters;
|
||||
using Google.Apis.Sheets.v4;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
@@ -96,7 +97,7 @@ namespace WebAPI.Controllers
|
||||
}
|
||||
}
|
||||
[HttpGet]
|
||||
[Route("getByNumber/{apiKey}/{number}")]
|
||||
[Route("getForPowerBI/{apiKey}/{number}")]
|
||||
public IActionResult GetByNumber(string apiKey, int number)
|
||||
{
|
||||
if (apiKey != configuration["apiKey"])
|
||||
@@ -105,11 +106,23 @@ namespace WebAPI.Controllers
|
||||
}
|
||||
|
||||
if (
|
||||
!Request.Headers.TryGetValue("D-BI-AUTH", out var authKey)
|
||||
|| authKey != configuration["authKey"])
|
||||
!Request.Headers.TryGetValue("Authorization", out var authHeader))
|
||||
{
|
||||
return Unauthorized();
|
||||
}
|
||||
string[] credentialsArr = authHeader.ToString().Split(" ");
|
||||
if (credentialsArr.Length != 2)
|
||||
{
|
||||
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"])
|
||||
{
|
||||
return Unauthorized();
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
return Ok(db.Layers
|
||||
|
||||
Reference in New Issue
Block a user