All Projects → NetDevPack → Security.identity

NetDevPack / Security.identity

Licence: mit
.NET DevPack Identity is a set of common implementations to help you implementing Identity, Jwt, claims validation and another facilities

Projects that are alternatives of or similar to Security.identity

Awesome Iam
👤 Identity and Access Management Knowledge for Cloud Platforms
Stars: ✭ 186 (+12.73%)
Mutual labels:  authentication, jwt, authorization, oauth
Mern Boilerplate
Fullstack boilerplate with React, Redux, Express, Mongoose, Passport Local, JWT, Facebook and Google OAuth out of the box.
Stars: ✭ 112 (-32.12%)
Mutual labels:  authentication, jwt, authorization, oauth
Oauthlib
A generic, spec-compliant, thorough implementation of the OAuth request-signing logic
Stars: ✭ 2,323 (+1307.88%)
Mutual labels:  authentication, authorization, oauth, identity
Cierge
🗝️ Passwordless OIDC authentication done right
Stars: ✭ 1,245 (+654.55%)
Mutual labels:  asp-net-core, authentication, jwt, identity
Spark Pac4j
Security library for Sparkjava: OAuth, CAS, SAML, OpenID Connect, LDAP, JWT...
Stars: ✭ 154 (-6.67%)
Mutual labels:  authentication, jwt, authorization, oauth
Pac4j
Security engine for Java (authentication, authorization, multi frameworks): OAuth, CAS, SAML, OpenID Connect, LDAP, JWT...
Stars: ✭ 2,097 (+1170.91%)
Mutual labels:  authentication, jwt, authorization, oauth
Spring Webmvc Pac4j
Security library for Spring Web MVC: OAuth, CAS, SAML, OpenID Connect, LDAP, JWT...
Stars: ✭ 110 (-33.33%)
Mutual labels:  authentication, jwt, authorization, oauth
Spring Security Pac4j
pac4j security library for Spring Security: OAuth, CAS, SAML, OpenID Connect, LDAP, JWT...
Stars: ✭ 231 (+40%)
Mutual labels:  authentication, jwt, authorization, oauth
Play Pac4j
Security library for Play framework 2 in Java and Scala: OAuth, CAS, SAML, OpenID Connect, LDAP, JWT...
Stars: ✭ 375 (+127.27%)
Mutual labels:  authentication, jwt, authorization, oauth
Aspnetcore2jwtauthentication
Jwt Authentication without ASP.NET Core Identity
Stars: ✭ 218 (+32.12%)
Mutual labels:  asp-net-core, jwt, identity, json-web-token
Cerberus
A demonstration of a completely stateless and RESTful token-based authorization system using JSON Web Tokens (JWT) and Spring Security.
Stars: ✭ 482 (+192.12%)
Mutual labels:  authentication, jwt, authorization, json-web-token
Buji Pac4j
pac4j security library for Shiro: OAuth, CAS, SAML, OpenID Connect, LDAP, JWT...
Stars: ✭ 444 (+169.09%)
Mutual labels:  authentication, jwt, authorization, oauth
Doorkeeper
Doorkeeper is an OAuth 2 provider for Ruby on Rails / Grape.
Stars: ✭ 4,917 (+2880%)
Mutual labels:  authentication, authorization, oauth, identity
Brandenburg
Laravel Authentication Package
Stars: ✭ 79 (-52.12%)
Mutual labels:  authentication, authorization, roles
Ueberauth
An Elixir Authentication System for Plug-based Web Applications
Stars: ✭ 1,259 (+663.03%)
Mutual labels:  authentication, authorization, oauth
Sentinel
A framework agnostic authentication & authorization system.
Stars: ✭ 1,354 (+720.61%)
Mutual labels:  authentication, authorization, roles
Authex
Authex is an opinionated JWT authentication and authorization library for Elixir.
Stars: ✭ 73 (-55.76%)
Mutual labels:  authentication, jwt, authorization
Spring Security React Ant Design Polls App
Full Stack Polls App built using Spring Boot, Spring Security, JWT, React, and Ant Design
Stars: ✭ 1,336 (+709.7%)
Mutual labels:  authentication, jwt, authorization
Warden Github Rails
Use GitHub as authorization and more. Use organizations and teams as means of authorization by simply wrapping your rails routes in a block. Also useful to get a user's details through OAuth.
Stars: ✭ 100 (-39.39%)
Mutual labels:  authentication, authorization, oauth
Stormpath Sdk Php
PHP SDK for the Stormpath User Management and Authentication REST+JSON API
Stars: ✭ 72 (-56.36%)
Mutual labels:  authentication, authorization, oauth
.NET DevPack

What is the .NET DevPack.Identity?

.NET DevPack Identity is a set of common implementations to help you implementing ASP.NET Identity, JWT, claims validation and another facilities

Codacy Badge Build status .NET Core License

Give a Star! ⭐️

If you liked the project or if NetDevPack helped you, please give a star ;)

Get Started

Package Version Popularity
NetDevPack.Identity NuGet Nuget

.NET DevPack.Identity can be installed in your ASP.NET Core application using the Nuget package manager or the dotnet CLI.

dotnet add package NetDevPack.Identity

If 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:

Add the IdentityDbContext configuration in your startup.cs:

services.AddIdentityEntityFrameworkContextConfiguration(options => 
	options.UseSqlServer(configuration.GetConnectionString("DefaultConnection"), 
	b=>b.MigrationsAssembly("AspNetCore.Jwt.Sample")));

Note: You must inform the namespace to avoid migration errors

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

Add the Identity configuration in ConfigureServices method of your startup.cs:

services.AddIdentityConfiguration();

Note: This extension returns an IdentityBuilder to allow you extending the configuration

Add the Identity configuration in Configure method of your startup.cs:

app.UseAuthConfiguration();

Note: This method need to be set between app.UseRouting() and app.UseEndpoints()

Run the command to generate the migration files:

dotnet ef migrations add Initial --context NetDevPackAppDbContext --project <Your patch>/<Your Project>.csproj

Run the command to generate the database:

dotnet ef database update --context NetDevPackAppDbContext --project <Your patch>/<Your Project>.csproj

Note: If are you using your own IdentityDbContext you must change the NetDevPackAppDbContext value to your context class name in the commands above.

After execute this steps you will be all set to use the Identity in your Application.

Configuring JWT

If you want to generate JSON Web Tokens in your application you need to add the JWT configuration in ConfigureServices method of your startup.cs

services.AddJwtConfiguration(Configuration, "AppSettings");

Note: If you don't inform the configuration name the value adopted will be AppJwtSettings

Set your appsettings.json file with this values:

"AppSettings": {
    "SecretKey": "MYSECRETSUPERSECRET",
    "Expiration": 2,
    "Issuer": "SampleApp",
    "Audience": "https://localhost"
}
Key Meaning
SecretKey Is your key to build JWT. This value need to be stored in a safe place in the production way
Expiration Expiration time in hours
Issuer The name of the JWT issuer
Audience The domain that the JWT will be valid. Can be a string collection

Generating JWT

You will need to set some dependencies in your Authentication Controller:

private readonly SignInManager<IdentityUser> _signInManager;
private readonly UserManager<IdentityUser> _userManager;
private readonly AppJwtSettings _appJwtSettings;

public AuthController(SignInManager<IdentityUser> signInManager,
		      UserManager<IdentityUser> userManager,
		      IOptions<AppJwtSettings> appJwtSettings)
{
    _signInManager = signInManager;
    _userManager = userManager;
    _appJwtSettings = appJwtSettings.Value;
}

Note: The AppJwtSettings is our dependency and is configured internally during JWT setup (in startup.cs file). You just need to inject it in your controller.

Note: The SignInManager and UserManager classes is native from Identity and provided in NetDevPack.Identity. You just need to inject it in your controller.

After 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:

return new JwtBuilder()
	.WithUserManager(_userManager)
	.WithJwtSettings(_appJwtSettings)
	.WithEmail(email)
	.BuildToken();

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.

Adding Claims to your JWT

You can call more methods in JwtBuilder to provide more information about the user:

return new JwtBuilder()
    .WithUserManager(_userManager)
    .WithJwtSettings(_appJwtSettings)
    .WithEmail(email)
    .WithJwtClaims()
    .WithUserClaims()
    .WithUserRoles()
    .BuildToken();
Method Meaning
WithJwtClaims() Claims of JWT like sub, jti, nbf and others
WithUserClaims() The user claims registered in AspNetUserClaims table
WithUserRoles() The user roles (as claims) registered in AspNetUserRoles table
BuildToken() Build and return the JWT as single string

If you want return your complex object UserResponse you need to change the last method to:

return new JwtBuilder()
    .WithUserManager(_userManager)
    .WithJwtSettings(_appJwtSettings)
    .WithEmail(email)
    .WithJwtClaims()
    .WithUserClaims()
    .WithUserRoles()
    .BuildUserResponse() as UserResponse;

Note: The safe cast to UserResponse is needed because is a subtype of UserResponse<TKey>.

Examples

Use the sample application to understand how NetDevPack.Identity can be implemented and help you to decrease the complexity of your application and development time.

Compatibility

The NetDevPack.Identity was developed to be implemented in ASP.NET Core 3.1 LTS applications, in the next versions will be add the 2.1 LTS support.

About

.NET DevPack.Identity was developed by Eduardo Pires under the MIT license.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].