Ocelot.JWTAuthorize
0.0.310
See the version list below for details.
dotnet add package Ocelot.JWTAuthorize --version 0.0.310
NuGet\Install-Package Ocelot.JWTAuthorize -Version 0.0.310
<PackageReference Include="Ocelot.JWTAuthorize" Version="0.0.310" />
paket add Ocelot.JWTAuthorize --version 0.0.310
#r "nuget: Ocelot.JWTAuthorize, 0.0.310"
// Install Ocelot.JWTAuthorize as a Cake Addin
#addin nuget:?package=Ocelot.JWTAuthorize&version=0.0.310
// Install Ocelot.JWTAuthorize as a Cake Tool
#tool nuget:?package=Ocelot.JWTAuthorize&version=0.0.310
Ocelot.JWTAuthorize
This library is used in the verification project when Ocelot is used as an API gateway. In the Ocelot project, the API project, the verification project, and the injection function can be used.
1. add the following sections to the appsetting. Json file for each project
{
"JwtAuthorize": {
"Secret": "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890",
"Issuer": "ocelot",
"Audience": "everyone",
"PolicyName": "permission",
"DefaultScheme": "Bearer",
"IsHttps": false,
"RequireExpirationTime": true
}
}
2. API Project
PM>Install-Package Ocelot.JWTAuthorize
Startup.cs,In ConfigureServices method
services.AddApiJwtAuthorize((context) =>
{
return true;//validate permissions return(permit) true or false(denied)
});
API Controller, "permission" is PolicyName of appsettion.json
[Authorize("permission")]
public class ValuesController : Controller
3. Authorize Project
PM>Install-Package Ocelot.JWTAuthorize
startup.cs,In ConfigureServices method
services.AddTokenJwtAuthorize();
LoginController.cs _tokenBuilder is dependency injection in AddTokenJwtAuthorize,so it's ITokenBuilder
[HttpPost]
public IActionResult Login([FromBody]LoginModel loginModel)
{
if (loginModel.UserName == "gsw" && loginModel.Password == "111111")
{
var claims = new Claim[] {
new Claim(ClaimTypes.Name, "gsw"),
new Claim(ClaimTypes.Role, "admin")
};
//DateTime.Now.AddSeconds(1200) is expiration time
var token = _tokenBuilder.BuildJwtToken(claims, DateTime.Now.AddSeconds(1200));
return new JsonResult(new { Result = true, Data = token });
}
else
{
return new JsonResult(new
{
Result = false,
Message = "Authentication Failure"
});
}
}
4. Ocelot Project
PM>Install-Package Ocelot.JWTAuthorize
Startup.cs,In ConfigureServices method
services.AddOcelotJwtAuthorize();
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. |
.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 (>= 2.1.1)
- Microsoft.AspNetCore.Authentication.JwtBearer (>= 2.1.1)
- Microsoft.AspNetCore.Authorization (>= 2.1.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories (2)
Showing the top 2 popular GitHub repositories that depend on Ocelot.JWTAuthorize:
Repository | Stars |
---|---|
migomiddle/xms
基于.netcore的跨平台应用框架,包含众多常用模块,易上手、易扩展,xms可理解为x(可扩展的/任意的)m(管理)s(系统)
|
|
axzxs2001/Asp.NetCoreExperiment
原来所有项目都移动到**OleVersion**目录下进行保留。新的案例装以.net 5.0为主,一部分对以前案例进行升级,一部分将以前的工作经验总结出来,以供大家参考!
|