From 7033ec7f402fa4b7df2bf72a5e3dff1df6831f57 Mon Sep 17 00:00:00 2001 From: lyndaidaii <64443925+lyndaidaii@users.noreply.github.com> Date: Fri, 19 Apr 2024 15:46:06 -0700 Subject: [PATCH] add readme for package Microsoft.AspNetCore.Authentication.JwtBearer (#54492) --- .../Authentication/JwtBearer/src/PACKAGE.md | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 src/Security/Authentication/JwtBearer/src/PACKAGE.md diff --git a/src/Security/Authentication/JwtBearer/src/PACKAGE.md b/src/Security/Authentication/JwtBearer/src/PACKAGE.md new file mode 100644 index 000000000000..ac607509e88c --- /dev/null +++ b/src/Security/Authentication/JwtBearer/src/PACKAGE.md @@ -0,0 +1,69 @@ +## About + +Microsoft.AspNetCore.Authentication.JwtBearer is a middleware component designed for ASP.NET Core applications. It facilitates JSON Web Token (JWT) authentication, enabling secure authentication for APIs and web services. This package allows you to validate JWT tokens issued by an authentication server, ensuring secure access to your application's resources. + +## Key Features + + + +* Seamless integration with ASP.NET Core applications. +* Supports JSON Web Token (JWT) authentication. +* Enables secure authentication for APIs and web services. +* Flexible configuration options for token validation parameters. +* Works with .NET Core 3.0 and newer, as well as .NET Standard 2.1. + +## How to Use + + + +```C# +using Microsoft.AspNetCore.Authentication.JwtBearer; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.IdentityModel.Tokens; +using System.Text; + +public void ConfigureServices(IServiceCollection services) +{ + services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) + .AddJwtBearer(options => + { + options.TokenValidationParameters = new TokenValidationParameters + { + ValidateIssuer = true, + ValidateAudience = true, + ValidateLifetime = true, + ValidateIssuerSigningKey = true, + ValidIssuer = "your_issuer", + ValidAudience = "your_audience", + IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes("your_secret_key")) + }; + }); + + // Other configurations... +} +``` +For more detailed configuration options and advanced scenarios, please refer to the blog [JWT Validation and Authorization in ASP.NET Core](https://devblogs.microsoft.com/dotnet/jwt-validation-and-authorization-in-asp-net-core/). + +## Main Types + + + +The main types provided by this library are: + +* `JwtBearerDefaults`: Contains default values for JWT Bearer authentication. +* `JwtBearerEvents`: Events used to handle JWT Bearer authentication events. +* `JwtBearerHandler`: Handles JWT Bearer authentication requests. +* `wtBearerOptions`: Options for configuring JWT Bearer authentication. + +## Additional Documentation + + + +* [Overview of ASP.NET Core authentication](https://learn.microsoft.com/en-us/aspnet/core/security/authentication/?view=aspnetcore-8.0) +* [JwtBearer sample](https://github.com/dotnet/aspnetcore/tree/main/src/Security/Authentication/JwtBearer/samples) + +## Feedback & Contributing + + + +Microsoft.AspNetCore.Authentication.JwtBearer is released as open-source under the [MIT license](https://licenses.nuget.org/MIT). Bug reports and contributions are welcome at [the GitHub repository](https://github.com/dotnet/aspnetcore). \ No newline at end of file