{"id":13655315,"url":"https://github.com/NetDevPack/Security.Identity","last_synced_at":"2025-04-23T12:33:15.895Z","repository":{"id":40759134,"uuid":"269783510","full_name":"NetDevPack/Security.Identity","owner":"NetDevPack","description":".NET DevPack Identity is a set of common implementations to help you implementing Identity, Jwt, claims validation and another facilities","archived":false,"fork":false,"pushed_at":"2024-02-08T01:30:18.000Z","size":239,"stargazers_count":574,"open_issues_count":6,"forks_count":50,"subscribers_count":27,"default_branch":"master","last_synced_at":"2024-11-10T07:38:03.844Z","etag":null,"topics":["access-control","asp-net-core","asp-net-identity","authentication","authorization","claims","custom-authentication","identity","json-web-token","jwt","oauth","roles"],"latest_commit_sha":null,"homepage":null,"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/NetDevPack.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","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},"funding":{"patreon":"eduardopires"}},"created_at":"2020-06-05T21:31:33.000Z","updated_at":"2024-11-06T22:22:26.000Z","dependencies_parsed_at":"2024-08-02T03:12:41.870Z","dependency_job_id":null,"html_url":"https://github.com/NetDevPack/Security.Identity","commit_stats":null,"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NetDevPack%2FSecurity.Identity","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NetDevPack%2FSecurity.Identity/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NetDevPack%2FSecurity.Identity/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NetDevPack%2FSecurity.Identity/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/NetDevPack","download_url":"https://codeload.github.com/NetDevPack/Security.Identity/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250435286,"owners_count":21430254,"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":["access-control","asp-net-core","asp-net-identity","authentication","authorization","claims","custom-authentication","identity","json-web-token","jwt","oauth","roles"],"created_at":"2024-08-02T03:01:02.649Z","updated_at":"2025-04-23T12:33:10.887Z","avatar_url":"https://github.com/NetDevPack.png","language":"C#","funding_links":["https://patreon.com/eduardopires"],"categories":["Security","C# #"],"sub_categories":[],"readme":"\u003cimg src=\"https://repository-images.githubusercontent.com/268701472/8bf84980-a6ce-11ea-83da-e2133c5a3a7a\" alt=\".NET DevPack\" width=\"300px\" /\u003e\r\n\r\nWhat is the .NET DevPack.Identity?\r\n=====================\r\n.NET DevPack Identity is a set of common implementations to help you implementing ASP.NET Identity, JWT, claims validation and another facilities\r\n\r\n[![Codacy Badge](https://app.codacy.com/project/badge/Grade/f1bd42eda59844ea95852606741147fa)](https://www.codacy.com/gh/NetDevPack/NetDevPack.Identity?utm_source=github.com\u0026amp;utm_medium=referral\u0026amp;utm_content=NetDevPack/NetDevPack.Identity\u0026amp;utm_campaign=Badge_Grade)\r\n[![Build status](https://ci.appveyor.com/api/projects/status/e283g9ik4rk3ymsp?svg=true)](https://ci.appveyor.com/project/EduardoPires/netdevpack-identity)\r\n![.NET Core](https://github.com/NetDevPack/NetDevPack.Identity/workflows/.NET%20Core/badge.svg)\r\n[![License](http://img.shields.io/github/license/NetDevPack/NetDevPack.Identity.svg)](LICENSE)\r\n\r\n## Give a Star! :star:\r\nIf you liked the project or if NetDevPack helped you, please give a star ;)\r\n\r\n## Get Started\r\n\r\n| Package |  Version | Popularity |\r\n| ------- | ----- | ----- |\r\n| `NetDevPack.Identity` | [![NuGet](https://img.shields.io/nuget/v/NetDevPack.Identity.svg)](https://nuget.org/packages/NetDevPack.Identity) | [![Nuget](https://img.shields.io/nuget/dt/NetDevPack.Identity.svg)](https://nuget.org/packages/NetDevPack.Identity) |\r\n\r\n\r\n.NET DevPack.Identity can be installed in your ASP.NET Core application using the Nuget package manager or the `dotnet` CLI.\r\n\r\n```\r\ndotnet add package NetDevPack.Identity\r\n```\r\n\r\nIf you want to use our IdentityDbContext (ASP.NET Identity standard) you will need to create the Identity tables. Set your connection string in the `appsettings.json` and follow the next steps:\r\n\r\nAdd the IdentityDbContext configuration in your `startup.cs`:\r\n\r\n```csharp\r\nservices.AddIdentityEntityFrameworkContextConfiguration(options =\u003e \r\n\toptions.UseSqlServer(configuration.GetConnectionString(\"DefaultConnection\"), \r\n\tb=\u003eb.MigrationsAssembly(\"AspNetCore.Jwt.Sample\")));\r\n```\r\n\r\n\u003e**Note:** You must inform the namespace to avoid migration errors\r\n\u003e\r\n\u003e**Note:** You must install the `Microsoft.EntityFrameworkCore.SqlServer` or another provider like `Npgsql.EntityFrameworkCore.PostgreSQL` package to have support from your database. Find the package for your database [here](https://docs.microsoft.com/en-us/ef/core/providers/?tabs=dotnet-core-cli)\r\n\r\nAdd the Identity configuration in `ConfigureServices` method of your `startup.cs`:\r\n\r\n```csharp\r\nservices.AddIdentityConfiguration();\r\n```\r\n\r\n\u003e**Note:** This extension returns an IdentityBuilder to allow you extending the configuration\r\n\r\nAdd the Identity configuration in `Configure` method of your `startup.cs`:\r\n\r\n```csharp\r\napp.UseAuthConfiguration();\r\n```\r\n\r\n\u003e**Note:** This method need to be set between `app.UseRouting()` and `app.UseEndpoints()`\r\n\r\nRun the command to generate the migration files:\r\n\r\n```\r\ndotnet ef migrations add Initial --context NetDevPackAppDbContext --project \u003cYour patch\u003e/\u003cYour Project\u003e.csproj\r\n```\r\n\r\nRun the command to generate the database:\r\n\r\n```\r\ndotnet ef database update --context NetDevPackAppDbContext --project \u003cYour patch\u003e/\u003cYour Project\u003e.csproj\r\n```\r\n\u003e**Note:** If are you using your own `IdentityDbContext` you must change the `NetDevPackAppDbContext` value to your context class name in the commands above.\r\n\r\nAfter execute this steps you will be all set to use the Identity in your Application.\r\n\r\n### Configuring JWT\r\nIf you want to generate JSON Web Tokens in your application you need to add the JWT configuration in `ConfigureServices` method of your `startup.cs`\r\n```csharp\r\nservices.AddJwtConfiguration(Configuration)\r\n        .AddNetDevPackIdentity\u003cIdentityUser\u003e();\r\n```\r\n\r\nSet your `appsettings.json` file with this values:\r\n\r\n```json\r\n\"AppJwtSettings\": {\r\n    \"Audience\": \"MyApplication.Name\"\r\n}\r\n``` \r\nIt's possible to configure some aspects of token\r\n\r\n|Key|Meaning|Default\r\n|--|--|---|\r\n|Expiration| Expiration time (in hours)  | 1 |\r\n|Issuer| The party that \"created\" the token and signed it with its private key. Usually the application Url  | Get current root Url from `HttpContext` |\r\n|Audience| API's that should accept the token. E.g your application Main name. | NetDevPack |\r\n|RefreshTokenExpiration  | Refresh token expiration (In Days) | 30 |\r\n|RefreshTokenType  | `OneTime` or `ReUse` | 30 |\r\n|SecretKey `Deprecated`  | Is your key to build JWT. **Read notes**| Do not use it |\r\n\r\n\u003e**Note:** Now we are using [NetDevPack.Security.Jwt](https://github.com/NetDevPack/Security.Jwt) to generate and Store your keys. It generate a RSA 2048 by default. You can check the project for more info.\r\n\r\n### Generating JWT\r\nYou will need to set a single dependency in your Authentication Controller:\r\n\r\n```csharp\r\npublic AuthController(IJwtBuilder jwtBuilder)\r\n{\r\n    _jwtBuilder = jwtBuilder;\r\n}\r\n```\r\n\r\nAfter user register or login process you can generate a JWT to respond the request. Use our implementation, you just need inform the user email and the dependencies injected in your controller:\r\n\r\n```csharp\r\nreturn _jwtBuilder\r\n\t.WithEmail(email)\r\n    \t.WithRefreshToken()\r\n\t.BuildToken();\r\n```\r\n\r\n\u003e**Note:** This builder can return a single string with JWT or a complex object `UserResponse` if you want return more data than a single JWT string.\r\n\r\n#### Adding Claims to your JWT\r\nYou can call more methods in `JwtBuilder` to provide more information about the user:\r\n\r\n```csharp\r\nreturn _jwtBuilder\r\n    .WithEmail(email)\r\n    .WithJwtClaims()\r\n    .WithUserClaims()\r\n    .WithUserRoles()\r\n    .WithRefreshToken()\r\n    .BuildToken();\r\n```\r\n\r\n|Method|Meaning|\r\n|--|--|\r\n|WithJwtClaims()| Claims of JWT like `sub`, `jti`, `nbf` and others |\r\n|WithUserClaims()| The user claims registered in `AspNetUserClaims` table|\r\n|WithUserRoles()| The user roles (as claims) registered in `AspNetUserRoles` table  |\r\n|BuildToken()| Build and return the JWT as single string  |\r\n\r\nIf you want return your complex object `UserResponse` you need to change the last method to:\r\n\r\n```csharp\r\nreturn _jwtBuilder\r\n    .WithEmail(email)\r\n    .WithJwtClaims()\r\n    .WithUserClaims()\r\n    .WithUserRoles()\r\n    .WithRefreshToken()\r\n    .BuildUserResponse();\r\n```\r\n\r\n## Examples\r\nUse the [sample application](https://github.com/NetDevPack/NetDevPack.Identity/tree/master/src/Samples/AspNetCore.Jwt.Sample) to understand how NetDevPack.Identity can be implemented and help you to decrease the complexity of your application and development time.\r\n\r\n## Compatibility\r\nThe **NetDevPack.Identity** was developed to be implemented in **ASP.NET Core**. It support all .NET versions since 3.1.\r\n\r\n## About\r\n.NET DevPack.Identity was developed by [Eduardo Pires](http://eduardopires.net.br) under the [MIT license](LICENSE).\r\n\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FNetDevPack%2FSecurity.Identity","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FNetDevPack%2FSecurity.Identity","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FNetDevPack%2FSecurity.Identity/lists"}