-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using System.Security.Claims; | ||
|
||
namespace BDMS.Authentication; | ||
|
||
public class LegacyApiAuthenticationMiddleware : IMiddleware | ||
{ | ||
private ILogger<LegacyApiAuthenticationMiddleware> logger; | ||
|
||
public LegacyApiAuthenticationMiddleware(ILogger<LegacyApiAuthenticationMiddleware> logger) | ||
{ | ||
this.logger = logger; | ||
} | ||
|
||
public async Task InvokeAsync(HttpContext context, RequestDelegate next) | ||
{ | ||
Claim? userName; | ||
if (context.Request.Path.StartsWithSegments(new PathString("/api/v1"), StringComparison.OrdinalIgnoreCase)) | ||
{ | ||
userName = context.User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Name); | ||
if (userName is not null) | ||
{ | ||
context.Request.Headers.Authorization = userName.Value; | ||
|
||
await next.Invoke(context).ConfigureAwait(false); | ||
|
||
logger.LogInformation("Authorized user <{UserName}> for legacy api accessing route <{Route}>", userName.Value, context.Request.Path); | ||
return; | ||
Check failure on line 27 in src/api/Authentication/LegacyApiAuthenticationMiddleware.cs GitHub Actions / Run cypress tests (1)
Check failure on line 27 in src/api/Authentication/LegacyApiAuthenticationMiddleware.cs GitHub Actions / Run cypress tests (1)
Check failure on line 27 in src/api/Authentication/LegacyApiAuthenticationMiddleware.cs GitHub Actions / Build and run tests
Check failure on line 27 in src/api/Authentication/LegacyApiAuthenticationMiddleware.cs GitHub Actions / Build and run tests
Check failure on line 27 in src/api/Authentication/LegacyApiAuthenticationMiddleware.cs GitHub Actions / Run cypress tests (2)
Check failure on line 27 in src/api/Authentication/LegacyApiAuthenticationMiddleware.cs GitHub Actions / Run cypress tests (2)
Check failure on line 27 in src/api/Authentication/LegacyApiAuthenticationMiddleware.cs GitHub Actions / Run cypress tests (3)
Check failure on line 27 in src/api/Authentication/LegacyApiAuthenticationMiddleware.cs GitHub Actions / Run cypress tests (3)
Check failure on line 27 in src/api/Authentication/LegacyApiAuthenticationMiddleware.cs GitHub Actions / Run cypress tests (4)
Check failure on line 27 in src/api/Authentication/LegacyApiAuthenticationMiddleware.cs GitHub Actions / Run cypress tests (4)
Check failure on line 27 in src/api/Authentication/LegacyApiAuthenticationMiddleware.cs GitHub Actions / Run cypress tests (5)
Check failure on line 27 in src/api/Authentication/LegacyApiAuthenticationMiddleware.cs GitHub Actions / Run cypress tests (5)
|
||
} | ||
} | ||
|
||
await next.Invoke(context).ConfigureAwait(false); | ||
} | ||
} |