GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - helltree/Ocelot.JWTAuthorize: This project is a JWT Authorize based on Ocelot API Gateway

BranchesTags
Open more actions menu
 
 

Latest commit

 

History

65 Commits
65 Commits

Folders and files

NameName
Last commit message
Last commit date
Ocelot.JWTAuthorize
Ocelot.JWTAuthorize
 
 
.gitattributes
.gitattributes
 
 
.gitignore
.gitignore
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 

Repository files navigation

Ocelot.JWTAuthorize

GitHub

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": {  
    "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 ip =HttpContext.Features.Get<IHttpConnectionFeature>()?.RemoteIpAddress?.ToString();
             var token = _tokenBuilder.BuildJwtToken(claims,ip, DateTime.UtcNow, 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();

TODO

Token Invalid

About

This project is a JWT Authorize based on Ocelot API Gateway

Resources

Readme
MIT license
Activity

Stars

0 stars

Watchers

0 watching

Forks

0 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.