Skip to content

Commit

Permalink
Fix build after rebasing
Browse files Browse the repository at this point in the history
  • Loading branch information
raman-m committed Nov 10, 2024
1 parent d0fca0f commit a4e33f4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 18 deletions.
24 changes: 10 additions & 14 deletions src/Ocelot/Authentication/Middleware/AuthenticationMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using Ocelot.Configuration;
using Ocelot.Logging;
using Ocelot.Middleware;
using System;
using System.Security.Claims;

namespace Ocelot.Authentication.Middleware
Expand Down Expand Up @@ -40,23 +39,20 @@ public async Task Invoke(HttpContext httpContext)
Logger.LogInformation(() => $"The path '{path}' is an authenticated route! {MiddlewareName} checking if client is authenticated...");
var token = httpContext.Request.Headers.FirstOrDefault(r => r.Key.Equals("Authorization", StringComparison.OrdinalIgnoreCase));
var cacheKey = "identityToken." + token;
if (!_memoryCache.TryGetValue(cacheKey, out ClaimsPrincipal userClaim))
if (!_memoryCache.TryGetValue(cacheKey, out ClaimsPrincipal principal))
{
var result = await AuthenticateAsync(httpContext, downstreamRoute);

userClaim = result.Principal;
var auth = await AuthenticateAsync(httpContext, downstreamRoute);
principal = auth.Principal;
_memoryCache.Set(cacheKey, principal, TimeSpan.FromMinutes(5));
}

_memoryCache.Set(cacheKey, userClaim, TimeSpan.FromMinutes(5));
if (principal?.Identity == null)
{
SetUnauthenticatedError(httpContext, path, null);
return;
}
httpContext.User = userClaim;
//var result = await AuthenticateAsync(httpContext, downstreamRoute);
//if (result.Principal?.Identity == null)
//{
// SetUnauthenticatedError(httpContext, path, null);
// return;
//}
//httpContext.User = result.Principal;

httpContext.User = principal;
if (httpContext.User.Identity.IsAuthenticated)
{
Logger.LogInformation(() => $"Client has been authenticated for path '{path}' by '{httpContext.User.Identity.AuthenticationType}' scheme.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public DiskFileConfigurationRepositoryTests()
_hostingEnvironment = new Mock<IWebHostEnvironment>();
_changeTokenSource = new Mock<IOcelotConfigurationChangeTokenSource>(MockBehavior.Strict);
_changeTokenSource.Setup(m => m.Activate());
var aspMemoryCache = new AspMemoryCache<FileConfiguration>(new MemoryCache(new MemoryCacheOptions()));
var aspMemoryCache = new DefaultMemoryCache<FileConfiguration>(new MemoryCache(new MemoryCacheOptions()));
_repo = new DiskFileConfigurationRepository(_hostingEnvironment.Object, _changeTokenSource.Object, aspMemoryCache);
}

Expand Down Expand Up @@ -124,9 +124,8 @@ private FileInfo GivenTheUserAddedOcelotJson()

private void GivenTheEnvironmentNameIsUnavailable()
{
_environmentName = null;
_hostingEnvironment.Setup(he => he.EnvironmentName).Returns(_environmentName);
var aspMemoryCache = new AspMemoryCache<FileConfiguration>(new MemoryCache(new MemoryCacheOptions()));
_hostingEnvironment.Setup(he => he.EnvironmentName).Returns(string.Empty);
var aspMemoryCache = new DefaultMemoryCache<FileConfiguration>(new MemoryCache(new MemoryCacheOptions()));
_repo = new DiskFileConfigurationRepository(_hostingEnvironment.Object, _changeTokenSource.Object, aspMemoryCache);
}

Expand Down

0 comments on commit a4e33f4

Please sign in to comment.