UzunTec.API.Authentication.Engine
3.1.4
See the version list below for details.
dotnet add package UzunTec.API.Authentication.Engine --version 3.1.4
NuGet\Install-Package UzunTec.API.Authentication.Engine -Version 3.1.4
<PackageReference Include="UzunTec.API.Authentication.Engine" Version="3.1.4" />
<PackageVersion Include="UzunTec.API.Authentication.Engine" Version="3.1.4" />
<PackageReference Include="UzunTec.API.Authentication.Engine" />
paket add UzunTec.API.Authentication.Engine --version 3.1.4
#r "nuget: UzunTec.API.Authentication.Engine, 3.1.4"
#:package UzunTec.API.Authentication.Engine@3.1.4
#addin nuget:?package=UzunTec.API.Authentication.Engine&version=3.1.4
#tool nuget:?package=UzunTec.API.Authentication.Engine&version=3.1.4
UzunTec API Authentication
Libraries and a sample REST API that help .NET developers add JWT Bearer authentication to ASP.NET Core applications. Token responses use snake_case property names (access_token, expires_in, token_type) for compatibility with common OAuth2-style clients and Identity Server–like payloads.
Repository layout
| Project | Purpose |
|---|---|
| UzunTec.API.Authentication.Engine | netstandard2.0 library: issue JWTs, configure JWT Bearer validation, DI extension for IServiceCollection. Packaged as UzunTec.API.Authentication.Engine (NuGet metadata in the .csproj). |
| UzunTec.API.Authentication.RestAPI | ASP.NET Core 3.1 sample API: token endpoint pattern, [Authorize] examples, Swagger UI with Bearer security. |
Solution file: UzunTec.API.Atuhentication.sln (note the filename spelling).
Requirements
- .NET Core SDK 3.1 (for the sample web project)
- For consuming only the Engine library: any host that supports
netstandard2.0and the referenced ASP.NET Core / JWT packages
Quick start (sample API)
From the repository root:
dotnet restore UzunTec.API.Atuhentication.sln
dotnet run --project UzunTec.API.Authentication.RestAPI/UzunTec.API.Authentication.RestAPI.csproj
By default the app listens on http://localhost:5000 (see Properties/launchSettings.json). Open http://localhost:5000/swagger to try the API.
Example flows in the sample
Obtain a token —
GET /api/user/{user}- For
admin, the sample returns a token with extra claims and theWritePermissionrole. - For other users, a simpler token is returned.
- For
Call a protected endpoint — Send header:
Authorization: Bearer <access_token>GET /api/anyobject— requires any authenticated user.GET /api/anyobject/{id}— requires roleWritePermission.
Inspect token payload (sample) —
GET /api/user/tokenDatawith Bearer token returns the JWT payload (implementation relies on the Engine’s token reader during validation).
Using the Engine in your own API
1. Reference the project or NuGet package
Add a project reference to UzunTec.API.Authentication.Engine, or install the published package UzunTec.API.Authentication.Engine (version and feed as defined by your team).
2. Configure AuthSettings in appsettings
Bind a section named to match your code (the sample uses AuthSettings):
{
"AuthSettings": {
"JtiCode": "your-jti-identifier",
"Audience": "YourAudience",
"Issuer": "YourIssuer",
"TokenExpireTimeInSeconds": 7200,
"SignatureKey": "your-secret-key-for-hmac-minimum-length-per-algorithm",
"IgnoreSignature": false,
"SignatureAlgorithm": "http://www.w3.org/2001/04/xmldsig-more#hmac-sha256"
}
}
AuthenticationConfig defaults SignatureAlgorithm to HMAC SHA-256. For RSA, set it to http://www.w3.org/2001/04/xmldsig-more#rsa-sha256; the Engine will generate an RSA key pair when issuing tokens (see Authenticator).
3. Register services in Startup
services.AddAuthenticationEngine(Configuration.GetSection("AuthSettings"));
Then in the pipeline (order matters):
app.UseAuthentication();
app.UseAuthorization();
Use [Authorize] and [Authorize(Roles = "...")] on controllers or actions as usual.
4. Issue tokens from your login or token endpoint
Inject Authenticator and call:
GenerateToken(string userCode)GenerateToken(string userCode, IReadOnlyDictionary<string, string> claims, IEnumerable<string> roles)
Returned TokenData exposes:
Access_token— JWT stringExpires_in— lifetime in seconds (from config)Token_type— e.g."Bearer"
Security notes
- Replace sample SignatureKey, Issuer, Audience, and JtiCode with production values; never commit real secrets. Prefer user secrets, environment variables, or a secret manager in development.
IgnoreSignature: truedisables signing key validation — useful only for special test scenarios, not production.TokenExpireTimeInSeconds: 0disables lifetime validation in the bearer options; use with care.- In production, keep HTTPS enabled and set
RequireHttpsMetadataappropriately if you harden JWT bearer options beyond the sample.
Building the NuGet package
The Engine project has GeneratePackageOnBuild enabled. Building the Engine produces a .nupkg under the output folder (typical path: bin/Debug or bin/Release).
dotnet pack UzunTec.API.Authentication.Engine/UzunTec.API.Authentication.Engine.csproj -c Release
License and attribution
Package metadata in the Engine project lists © 2020 Uzun Technology and repository https://github.com/uztec/api-auth. Add or adjust a LICENSE file in this repo if you need an explicit open-source license text.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. 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. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Microsoft.AspNetCore.Authentication.Abstractions (>= 2.2.0)
- Microsoft.AspNetCore.Authentication.JwtBearer (>= 2.2.0)
- Microsoft.Extensions.Configuration.Abstractions (>= 3.1.10)
- Microsoft.Extensions.Configuration.Binder (>= 3.1.10)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 3.1.10)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.