Major update
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
using MaxInventory.Authentication.Core;
|
||||
using MaxInventory.Authentication.Core;
|
||||
using System.Security.Claims;
|
||||
|
||||
namespace MaxInventory.Authentication.Abstractions
|
||||
|
||||
@@ -1,12 +1,31 @@
|
||||
using MaxInventory.Authentication.Abstractions;
|
||||
using MaxInventory.Authentication.Abstractions;
|
||||
using MaxInventory.Authentication.Configuration;
|
||||
using Microsoft.AspNetCore.Authentication;
|
||||
using Microsoft.AspNetCore.Authentication.Cookies;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Security.Claims;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MaxInventory.Authentication.Core
|
||||
{
|
||||
public sealed class AdminCookieValidationEvents : CookieAuthenticationEvents
|
||||
{
|
||||
// private static readonly string[] GroupClaimTypes =
|
||||
// {
|
||||
// "groups",
|
||||
// "group",
|
||||
// "role",
|
||||
// "roles",
|
||||
// ClaimTypes.GroupSid,
|
||||
// ClaimTypes.Role,
|
||||
// "http://schemas.microsoft.com/ws/2008/06/identity/claims/role",
|
||||
// "http://schemas.xmlsoap.org/claims/Group"
|
||||
//};
|
||||
|
||||
private readonly IPrincipalAccessEvaluator _principalAccessEvaluator;
|
||||
|
||||
public AdminCookieValidationEvents(IPrincipalAccessEvaluator principalAccessEvaluator)
|
||||
@@ -35,6 +54,24 @@ namespace MaxInventory.Authentication.Core
|
||||
context.RejectPrincipal();
|
||||
await context.HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);
|
||||
}
|
||||
//var configuredGroups = (_configuration[AuthEnvironment.AdminGroups] ?? string.Empty)
|
||||
// .Split(';', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);
|
||||
|
||||
|
||||
|
||||
//var principalGroups = identity.Claims
|
||||
// .Where(c => GroupClaimTypes.Contains(c.Type, StringComparer.OrdinalIgnoreCase))
|
||||
// .Select(c => c.Value);
|
||||
|
||||
//var isAdmin = configuredGroups.Length > 0 &&
|
||||
// principalGroups.Any(group =>
|
||||
// configuredGroups.Contains(group, StringComparer.OrdinalIgnoreCase));
|
||||
|
||||
//if (!isAdmin)
|
||||
//{
|
||||
// context.RejectPrincipal();
|
||||
// await context.HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);
|
||||
//}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
{
|
||||
public static class AuthRoles
|
||||
{
|
||||
public const string Admin = "SG-OMB-IT";
|
||||
public const string Admin = "Admin";
|
||||
public const string EditAdd = "EditAdd";
|
||||
public const string View = "View";
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace MaxInventory.Authentication.Core
|
||||
namespace MaxInventory.Authentication.Core
|
||||
{
|
||||
public sealed record PrincipalAccess(bool IsAuthenticated, bool CanView, bool CanEdit, bool CanDelete);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using MaxInventory.Authentication.Abstractions;
|
||||
using MaxInventory.Authentication.Abstractions;
|
||||
using System.Security.Claims;
|
||||
|
||||
namespace MaxInventory.Authentication.Core
|
||||
|
||||
+3
-3
@@ -1,4 +1,4 @@
|
||||
using Microsoft.AspNetCore.Authentication;
|
||||
using Microsoft.AspNetCore.Authentication;
|
||||
using Microsoft.AspNetCore.Authentication.Cookies;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
@@ -42,7 +42,7 @@ namespace MaxInventory.Authentication.Extensions
|
||||
authBuilder.AddCookie(options =>
|
||||
{
|
||||
options.Cookie.Name = "secure-network.auth";
|
||||
options.AccessDeniedPath = "/AccesDenied";
|
||||
options.AccessDeniedPath = "/access-denied";
|
||||
options.EventsType = typeof(AdminCookieValidationEvents);
|
||||
});
|
||||
|
||||
@@ -79,4 +79,4 @@ namespace MaxInventory.Authentication.Extensions
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Triggering release.
|
||||
@@ -73,17 +73,18 @@ public sealed class OidcAuthProvider : IAuthProvider
|
||||
RoleClaimType = roleClaimType
|
||||
};
|
||||
|
||||
options.Events = new OpenIdConnectEvents()
|
||||
{
|
||||
OnRedirectToIdentityProvider = context =>
|
||||
{
|
||||
var builder = new UriBuilder(context.ProtocolMessage.RedirectUri);
|
||||
builder.Scheme = "https";
|
||||
builder.Port = 44374;// 1;
|
||||
context.ProtocolMessage.RedirectUri = builder.ToString();
|
||||
return Task.FromResult(0);
|
||||
}
|
||||
};
|
||||
//This is used for Local Testing
|
||||
//options.Events = new OpenIdConnectEvents()
|
||||
//{
|
||||
// OnRedirectToIdentityProvider = context =>
|
||||
// {
|
||||
// var builder = new UriBuilder(context.ProtocolMessage.RedirectUri);
|
||||
// builder.Scheme = "https";
|
||||
// builder.Port = 443;
|
||||
// context.ProtocolMessage.RedirectUri = builder.ToString();
|
||||
// return Task.FromResult(0);
|
||||
// }
|
||||
//};
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user