Skip to content
Snippets Groups Projects
Commit 1f5467be authored by Petar Hristov's avatar Petar Hristov :speech_balloon:
Browse files

Fix: Authorization error

parent d946f3c0
No related branches found
No related tags found
1 merge request!65Sprint/2021 08
......@@ -23,6 +23,7 @@ namespace Coscine.ApiCommons.Middleware
public async Task Invoke(HttpContext context)
{
bool _authorized = false;
if (context.Request.Path.Value.Contains("TOS"))
{
await _next(context);
......@@ -61,6 +62,8 @@ namespace Coscine.ApiCommons.Middleware
CoscineLoggerMetadata.SetUri(_uri);
// Get the User Id
try
{
var authorization = context.Request.Headers["Authorization"].ToArray();
string bearer = null;
foreach (var line in authorization)
......@@ -81,6 +84,12 @@ namespace Coscine.ApiCommons.Middleware
CoscineLoggerMetadata.SetUserId(userId);
}
}
_authorized = true;
}
catch (Exception ex)
{
_authorized = false;
}
// Get the corrolation Id
context.Request.Headers.TryGetValue("X-Coscine-Logging-CorrelationId", out StringValues clientCorrolationId);
......@@ -182,11 +191,10 @@ namespace Coscine.ApiCommons.Middleware
{
byte[] data;
if (true) // ex.GetType() == typeof(...)
if (!_authorized)
{
context.Response.StatusCode = StatusCodes.Status401Unauthorized;
data = System.Text.Encoding.UTF8.GetBytes($"{ex.GetType()}");
//byte[] data = System.Text.Encoding.UTF8.GetBytes("Invalid authentication. Please try again.");
data = System.Text.Encoding.UTF8.GetBytes("Invalid authentication. Please try again.");
}
else
{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment