{"id":19992866,"url":"https://github.com/catcherwong/Nancy.Authentication.JwtBearer","last_synced_at":"2025-05-04T12:30:27.775Z","repository":{"id":130595209,"uuid":"97355545","full_name":"catcherwong/Nancy.Authentication.JwtBearer","owner":"catcherwong","description":":fireworks:A JwtBearer authentication provider for Nancy.","archived":false,"fork":false,"pushed_at":"2018-01-10T03:45:05.000Z","size":64,"stargazers_count":26,"open_issues_count":0,"forks_count":4,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-11T18:53:05.822Z","etag":null,"topics":["authentication","json-web-token","jwt","nancy","nancyfx"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/catcherwong.png","metadata":{"files":{"readme":"README-zh.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-07-16T02:46:17.000Z","updated_at":"2021-07-09T14:20:07.000Z","dependencies_parsed_at":"2023-06-03T03:30:16.806Z","dependency_job_id":null,"html_url":"https://github.com/catcherwong/Nancy.Authentication.JwtBearer","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/catcherwong%2FNancy.Authentication.JwtBearer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/catcherwong%2FNancy.Authentication.JwtBearer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/catcherwong%2FNancy.Authentication.JwtBearer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/catcherwong%2FNancy.Authentication.JwtBearer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/catcherwong","download_url":"https://codeload.github.com/catcherwong/Nancy.Authentication.JwtBearer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252333947,"owners_count":21731301,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["authentication","json-web-token","jwt","nancy","nancyfx"],"created_at":"2024-11-13T04:52:21.417Z","updated_at":"2025-05-04T12:30:27.320Z","avatar_url":"https://github.com/catcherwong.png","language":"C#","funding_links":[],"categories":["C\\#"],"sub_categories":[],"readme":"[English](./README.md)\n\n# Nancy.Authentication.JwtBearer\n\n![NuGet Version](https://img.shields.io/nuget/v/Nancy.Authentication.JwtBearer.svg)\n\n[![Build status](https://ci.appveyor.com/api/projects/status/6jeqlrrjh8f5enjy?svg=true)](https://ci.appveyor.com/project/catcherwong/nancy-authentication-jwtbearer)\n\n为Nancy提供JwtBearer授权验证的一个扩展。\n\n这个组件基于.NET Standard 2.0，并且已经可以在NuGet上下载安装了！\n\nNuGet上最新的版本已经同时支持.NET Standard 2.0 和 .NET Framework 4.5.2了。\n\n您可以通过下面的链接访问这个Package相关的信息：\n\n\u003chttps://www.nuget.org/packages/Nancy.Authentication.JwtBearer\u003e\n\n# 快速上手\n\n## 安装NuGet包\n\n```\nInstall-Package Nancy.Authentication.JwtBearer\n```\n\n## 在Bootstrapper类中配置JwtBearer相关信息\n\n在这一步主要是配置启用JwtBearer验证，需要实例化一个**JwtBearerAuthenticationConfiguration**对象，这个对象包括了JwtBearer验证的相关配置信息。\n\n最后需要调用IPipelines的扩展方法去启用JwtBearer。\n\n相关配置参数说明 \n\n参数名 | 说明\n---|---\nTokenValidationParameters  | Token验证所需要的参数\nChallenge  |  HTTP头部WWW-Authenticate字段的配置\n\n示例代码如下：\n\n```csharp\npublic class Bootstrapper : Nancy.DefaultNancyBootstrapper\n{\n    protected override void ApplicationStartup(TinyIoCContainer container, IPipelines pipelines)\n    {\n        base.ApplicationStartup(container, pipelines);\n\n        var keyByteArray = Encoding.ASCII.GetBytes(\"Y2F0Y2hlciUyMHdvbmclMjBsb3ZlJTIwLm5ldA==\");\n        var signingKey = new SymmetricSecurityKey(keyByteArray);\n\n        var tokenValidationParameters = new TokenValidationParameters\n        {\n            // The signing key must match!\n            ValidateIssuerSigningKey = true,\n            IssuerSigningKey = signingKey,\n\n            // Validate the JWT Issuer (iss) claim\n            ValidateIssuer = true,\n            ValidIssuer = \"http://www.c-sharpcorner.com/members/catcher-wong\",\n\n            // Validate the JWT Audience (aud) claim\n            ValidateAudience = true,\n            ValidAudience = \"Catcher Wong\",\n\n            // Validate the token expiry\n            ValidateLifetime = true,\n\n            ClockSkew = TimeSpan.Zero\n        };\n\n        var configuration = new JwtBearerAuthenticationConfiguration\n        {\n            TokenValidationParameters = tokenValidationParameters,\n            Challenge = \"Guest\"//if not use this,default to Bearer\n        };\n\n        pipelines.EnableJwtBearerAuthentication(configuration);\n    }\n}\n```\n\n## 在Module中添加授权验证\n\n只需要在Module中添加`this.RequiresAuthentication();`即可。\n\n示例代码如下：\n\n```csharp\npublic class MainModule : Nancy.NancyModule\n{\n    public MainModule()\n    {\n        this.RequiresAuthentication();\n\n        Get(\"/\", _ =\u003e \n        {\n            return \"From JwtBearer Authentication\";\n        });\n    }\n}\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcatcherwong%2FNancy.Authentication.JwtBearer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcatcherwong%2FNancy.Authentication.JwtBearer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcatcherwong%2FNancy.Authentication.JwtBearer/lists"}