mayne92 / ASPNETCore2JwtAuthentication

Jwt Authentication without ASP.NET Core Identity 2.0

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Jwt Authentication without ASP.NET Core Identity 2.0

jwtauth

A Jwt based authentication sample for ASP.NET Core 2.0 without using the Identity system. It includes:

  • Users and Roles tables with a many-to-may relationship.
  • A separated EF Core data layer with enabled migrations.
  • An EF Core 2.0 based service layer.
  • A Db initializer to seed the default database values.
  • An account controller with Jwt and DB based login, custom logout and refresh tokens capabilities.
  • 2 sample API controllers to show how user-roles can be applied and used.
  • A Jwt validator service to show how to react to the server side changes to a user's info immediately.
  • An Angular 6.0+ Client. It contains:
    • A JWT-based Login page.
    • Handling how and where to store the tokens.
    • How to handle refresh tokens mechanism, using reactive timers.
    • How to validate the expiration date of a token.
    • How to decode an access token and extract the user's roles from it.
    • Authorizing access to a module via a route guard based on the user's roles.
    • How to hide or display different parts of a page based on the user's roles.
    • Adding a JWT token to the HTTP requests required authorized access automatically.
    • Handling server side unauthorized errors automatically.

How to run the Angular 6.0+ Client

  • Update all of the outdated global dependencies using the npm update -g command.
  • Install the Angular-CLI.
  • Open a command prompt console and then navigate to src/ASPNETCore2JwtAuthentication.AngularClient/ folder.
  • Now run the following commands:
npm install
_2-ng-build-dev.bat
  • Then open another command prompt console and navigate to src/ASPNETCore2JwtAuthentication.WebApp/ folder.
  • Now run the following commands:
dotnet restore
dotnet watch run

About

Jwt Authentication without ASP.NET Core Identity 2.0

License:Apache License 2.0


Languages

Language:C# 48.0%Language:TypeScript 36.7%Language:HTML 12.1%Language:JavaScript 1.2%Language:Ruby 0.7%Language:Batchfile 0.5%Language:CSS 0.4%Language:PowerShell 0.3%