YG.Authentication
2.2.2
See the version list below for details.
dotnet add package YG.Authentication --version 2.2.2
NuGet\Install-Package YG.Authentication -Version 2.2.2
<PackageReference Include="YG.Authentication" Version="2.2.2" />
<PackageVersion Include="YG.Authentication" Version="2.2.2" />
<PackageReference Include="YG.Authentication" />
paket add YG.Authentication --version 2.2.2
#r "nuget: YG.Authentication, 2.2.2"
#:package YG.Authentication@2.2.2
#addin nuget:?package=YG.Authentication&version=2.2.2
#tool nuget:?package=YG.Authentication&version=2.2.2
YG.Authentication
YG.Authentication provides authentication and authorization for Blazor applications using either a local JWT-based identity system or OpenID Connect (OIDC) Single Sign-On.
Features:
Local JWT Authentication Authentication and authorization for Blazor applications using JWT claims. Works with or without a WebAPI. BCrypt password hashing support. Login through WebAPI: api/loginEncr (BCrypt) api/login (plain text) Direct authentication without a WebAPI: _authEncr.Authenticate(...) _auth.Authenticate(...) Built-in authorization support for protected pages. WebAPI endpoints: api/login api/auth
OpenID Connect (OIDC) Single Sign-On
Starting July 2026, YGAuthentication is renamed to YG.Authentication, and it also supports OpenID Connect providers such as Auth0, Microsoft Entra ID (Azure AD), Okta, Keycloak, and other standards-compliant identity providers.
Simply add your OIDC configuration to appsettings.json and register the services.
YG.Authentication Service Registration:
builder.Services.AddYGOpenIdConnect(config);
builder.Services.AddScoped<IYGOpenIdConnectEventHandler, YourCustomOpenIdConnectUserHandler>();
Middleware:
app.MapYGOpenIdConnectEndpoints(config);
Hosting Your Own Identity Provider
You can either use the built-in local JWT identity system or integrate with an external OpenID Connect provider.
If you need help getting started, feel free to reach out:
Email: cs@yogigrantz.com CodeMentor: Yogi Grantz
Installation
Include YG.Authentication package in the project file
Source code:
The sample project YGEnvAuthenticationTestApp contains 4 sample login pages:
Login 1: Direct authentication without encrypted password Login 2: Direct authentication with encrypted password Login 3: WebAPI authentication without encrypted password Login 4: WebAPI authentication with encrypted password Login 5: OpenIDC authentication with external login page hosted at IDP
Usage
.csproj file:
<PropertyGroup> <TargetFramework>net8.0</TargetFramework> <Nullable>enable</Nullable> <ImplicitUsings>disable</ImplicitUsings> </PropertyGroup>
<ItemGroup> <PackageReference Include="Blazored.LocalStorage" Version="4.5.0" /> <PackageReference Include="Newtonsoft.Json" Version="13.0.3" /> <PackageReference Include="YG.Authentication" Version="2.2.2" /> </ItemGroup>
AppSettings.json for custom jwt:
{
"AuthName": "AnyNameOfYourChoice",
"LoginPage": "/Login"
}
AppSettings.json OpenIDC:
"YGAuthentication": {
"OpenIdConnect": {
"Provider": "Auth0",
"Domain": "yourtenant.us.auth0.com",
"ClientId": "xxxxxxxx",
"ClientSecret": "xxxxxxxx",
"LoginPath": "/login?redirectUri=/",
"LogoutPath": "/logout",
"CallbackPath": "/signin-oidc",
"SignedOutCallbackPath": "/signout-callback-oidc",
"SignedOutRedirectUri": "/",
"ClaimsIssuer": "Auth0",
"DefaultRedirectPath": "/",
"CookieExpireDays": 2
}
},
For OIDC, the middleware should follow this sequence: ---------------------
// OpenIDC - Auth0 ----------------
builder.Services.AddYGOpenIdConnect(builder.Configuration);
// For checking user role against local database, create DI class that inherits from IYGOpenIdConnectEventHandler
// Then Register it in DI, like this:
builder.Services.AddScoped<IYGOpenIdConnectEventHandler, YourCustomHandler>();
// code all the necessary actions upon successful login and logout in this class: YourCustomHandler - name it appropriately to suit your needs
var app = builder.Build();
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.MapControllerRoute(
name: "mvc",
pattern: "{controller}/{action}/{id?}");
app.MapBlazorHub();
app.MapFallbackToPage("/_Host");
app.UseAuthentication();
app.UseAuthorization();
app.MapYGOpenIdConnectEndpoints(builder.Configuration);
app.Run();
// if you ever need help setting this up, please connect and message me in LinkedIn: Yogi Grantz
Dependencies
<ItemGroup> <PackageReference Include="BCrypt.Net-Next" Version="4.0.3" /> <PackageReference Include="Blazored.LocalStorage" Version="4.5.0" /> <PackageReference Include="Microsoft.AspNetCore.Mvc.Abstractions" Version="2.2.0" /> <PackageReference Include="Microsoft.AspNetCore.Mvc.Formatters.Json" Version="2.2.0" /> <PackageReference Include="Microsoft.Extensions.Http" Version="8.0.0" /> <PackageReference Include="Microsoft.IdentityModel.Tokens" Version="8.0.2" /> <PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="8.0.2" /> </ItemGroup>
Contributing
Any new ideas on how to enhance this class without adding much complexity, please adhere to SOLID principle
License
This project is licensed under the MIT License(LICENSE).
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- BCrypt.Net-Next (>= 4.0.3)
- Blazored.LocalStorage (>= 4.5.0)
- Microsoft.AspNetCore.Authentication.OpenIdConnect (>= 8.0.0)
- Microsoft.AspNetCore.Mvc.Abstractions (>= 2.2.0)
- Microsoft.AspNetCore.Mvc.Formatters.Json (>= 2.2.0)
- Microsoft.Extensions.Http (>= 8.0.0)
- Microsoft.IdentityModel.Tokens (>= 8.0.2)
- System.IdentityModel.Tokens.Jwt (>= 8.0.2)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Updated Readme.md