Ocelot.JWTAuthorize 0.0.310

There is a newer version of this package available.
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
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Ocelot.JWTAuthorize" Version="0.0.310" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Ocelot.JWTAuthorize --version 0.0.310
#r "nuget: Ocelot.JWTAuthorize, 0.0.310"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// 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


NuGet Badge GitHub license

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": {  
    "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

public class ValuesController : Controller

3. Authorize Project

PM>Install-Package Ocelot.JWTAuthorize

startup.cs,In ConfigureServices method


LoginController.cs _tokenBuilder is dependency injection in AddTokenJwtAuthorize,so it's ITokenBuilder

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 });
             return new JsonResult(new
                 Result = false,
                 Message = "Authentication Failure"

4. Ocelot Project

PM>Install-Package Ocelot.JWTAuthorize

Startup.cs,In ConfigureServices method

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
原来所有项目都移动到**OleVersion**目录下进行保留。新的案例装以.net 5.0为主,一部分对以前案例进行升级,一部分将以前的工作经验总结出来,以供大家参考!
Version Downloads Last updated
0.0.400 12,183 7/19/2018
0.0.310 1,604 7/6/2018
0.0.300 1,605 7/2/2018
0.0.211 2,372 7/2/2018
0.0.201 1,755 7/1/2018
0.0.103 1,719 6/28/2018
0.0.102 1,702 6/25/2018