![]() |
VOOZH | about |
dotnet add package OLT.Core.Identity.Abstractions --version 9.0.0-beta-0005
NuGet\Install-Package OLT.Core.Identity.Abstractions -Version 9.0.0-beta-0005
<PackageReference Include="OLT.Core.Identity.Abstractions" Version="9.0.0-beta-0005" />
<PackageVersion Include="OLT.Core.Identity.Abstractions" Version="9.0.0-beta-0005" />Directory.Packages.props
<PackageReference Include="OLT.Core.Identity.Abstractions" />Project file
paket add OLT.Core.Identity.Abstractions --version 9.0.0-beta-0005
#r "nuget: OLT.Core.Identity.Abstractions, 9.0.0-beta-0005"
#:package OLT.Core.Identity.Abstractions@9.0.0-beta-0005
#addin nuget:?package=OLT.Core.Identity.Abstractions&version=9.0.0-beta-0005&prereleaseInstall as a Cake Addin
#tool nuget:?package=OLT.Core.Identity.Abstractions&version=9.0.0-beta-0005&prereleaseInstall as a Cake Tool
Injectable Identity wrapper from IOltIdentity
Abstract wrapper class that requires System.Security.Claims.ClaimsPrincipal. This concept it to be injected
public interface IAppIdentity : IOltIdentity
{
string? MyCustomClaim { get; }
}
public class AppIdentity : OltIdentity, IAppIdentity
{
private readonly IHttpContextAccessor _httpContext;
public AppIdentity(IHttpContextAccessor httpContext)
{
_httpContext = httpContext;
}
public override ClaimsPrincipal Identity => _httpContext?.HttpContext?.User;
public string? MyCustomClaim => GetClaims("MyCustomClaim").FirstOrDefault()?.Value;
}
...
//Note: add to DI
services
.AddScoped<IAppIdentity, AppIdentity>();
// An enum used for a role using custom attribute "CodeAttribute" from OLT.Core.Attribute.Abstractions
public enum SecurityRoles
{
[Code("read-only")]
[Description("View all records")]
ReadOnly = 1000
}
public class BatchServiceIdentity : OltIdentity, IOltIdentity
{
public BatchServiceIdentity()
{
}
public const string SERVICE_NAME = "Batch Service";
public override string NameId => "Unique Id boes into this claim";
public override string Username => SERVICE_NAME;
public override ClaimsPrincipal Identity
{
get
{
var roles = new List<string>();
foreach (SecurityRoles role in Enum.GetValues(typeof(SecurityRoles)))
{
roles.Add(role.GetCodeEnum());
}
return new GenericPrincipal(new GenericIdentity(SERVICE_NAME), roles.ToArray());
}
}
}
public class MyExampleService : OltCoreService, IMyExampleService
{
private readonly IOltIdentity _identity;
public ReportManager(IOltIdentity identity)
{
_identity = identity;
}
public void ExampleMethod()
{
if (_identity.HasRole(SecurityRoles.ReadOnly))
{
//The Identity has the role
}
Debug.WriteLine(_identity.Username);
Debug.WriteLine(_identity.NameId);
Debug.WriteLine(_identity.FirstName);
Debug.WriteLine(_identity.LastName);
}
}
...
//Note: add to DI
services.AddScoped<IOltIdentity, BatchServiceIdentity>();
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 net8.0 is compatible. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 is compatible. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 was computed. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
Showing the top 1 NuGet packages that depend on OLT.Core.Identity.Abstractions:
| Package | Downloads |
|---|---|
|
OLT.EF.Core
Base Context, Context Extensions, Seed Helpers, Entity Interfaces, Base Entity Models |
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 9.0.0-beta-0005 | 139 | 12/2/2024 |
| 8.4.0-beta-0010 | 264 | 11/7/2024 |
| 8.4.0-beta-0005 | 243 | 10/9/2024 |