Angular 2 and .NET Web API Authentication

What is the best way to have a username and password authentication system that works between Angular 2 and the .NET Web API?

+6
source share
3 answers

First of all, try to avoid using self-accepted methods. The most commonly used approach is to use Json web token . https://jwt.io/ There, when you log in, return the token to angular2, and then pass it on every request. There are many examples of implementation and libraries. https://github.com/auth0/angular2-jwt

How to use JWT in MVC application for authentication and authorization?

+7
source

The best way is to use a package called IdentityServer. I wrote a tutorial on it, but using one of my older versions, however this will give you a good idea:

https://www.linkedin.com/pulse/securing-net-core-web-api-identityserver4-resource-owner-dalvandi

+1
source

Best practice is to use basic authentication and put your username and password in the header. On the client side, you must add the username and password in the header:

 var user = 'user'; var password = 'password'; var base64encodedData = new Buffer(user + ':' + password).toString('base64'); 

Add this header to all your HTTP requests:

 'Authorization': 'Basic ' + base64encodedData 

On the server side, this link can help you decrypt your username and password. Do not forget to prevent Man in an average attack , https is required for the api.

-4
source

Source: https://habr.com/ru/post/1015549/


All Articles