Posts

Showing posts from June, 2018

Authenticate users with JWT (JSON Web Tokens) with .Net and TypeScript

Image
When creating web applications, it is a common thing to provide a user login function. And when creating user logins it is required to authenticate them probably using a token which contain the user session data and user role data. When considering the token creation and authenticate it there are several ways and technologies to do and in this blog I would like to explain how to create token and validate it using JWT (JSON Web Tokens). Read about JWT from here There are several packages in NuGet store that provide JWT features and in this article I'm going to use  System.IdentityModel.Tokens.Jwt  Install this in your project using the NuGet package manager. Ok, now let's get started. 1.      Create token Let's create a class to create token when user log in to the system.  Create a hased key of SHA256 to use when crating the token.  using System; using System.Text; using System.IdentityModel.Tokens.Jwt; using Microsoft.IdentityModel.Tokens; priv