Authentication & Authorization in .Net Core 2.1 WepAPI using JWT

hkjhadj1

I am trying to implement JWT Auth in my Core 2.1 webAPI. I'm still learning Core 2.1 and I have worked with MVC5 before. My question is that in MVC5, the AccountControllerwas auto generated along with all the controllers to handle the complete user authentication and authorization process. Now as I'm trying to implement the same thing for my Core 2.1 API, I've realized that they are no longer auto generated. I've searched around and have quite a few resoucrses that are teaching how to implement the functionality but, I remeber everyone would say to do not reinvent the authorization/authentication wheel and use the auto generated code provided by MVC5. Now I could follow the tutorials out there and implement the process myself but pretty much everyone seems to be doing there own implementation. Is this the correct way of doing this? I don't want to implement by following these tutorials and end up with a security loophole in my API.

greygreg87

I struggled with the same issue. I dont' know if it is good way to support authentication/authorization, but I found solution.

Generally web api should be pure api link. However when you:

1) derive form IdentityDbContext in DatabaseContext:

public class DatabaseContext : IdentityDbContext<ApplicationUser>

where ApplicationUser is your own class which derives from IdentityUser:

public class ApplicationUser : IdentityUser

2) do migrations, EF Core will generate for you all tables tha you need

Next, you must setup JWT authorize in your Startup class and create method in your AccountController to generate tokens. Really helpful video link

Is it answer on your question? Or I missed up something. I'm quite new in .NET

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Authorization for JWT bearer in Swashbuckle .NET Core 2

asp.net core 2.0 Authorization is firing before authentication (JWT)

Microservice Authentication and Authorization using JWT

Angular 2 not sending Authorization header using JWT authentication

.NET core JWT authorization failed?

JWT Authorization Failed .net core

ASP.Net Core 2 Ignore JWT authorization for localhost requests

ASP.NET Core Web API + Angular 2 Authorization and Authentication

Windows Authentication Asp.net core 2 database role authorization

How to implement jwt token base authentication with custom policy schema for authorization in .net core?

Firebase Authentication (JWT) with .NET Core

JWT Authentication using a custom attribute in .NET Core Web API

JWT Authentication for .net core 2.2 application not using Identity

Facebook JWT authentication using ASP.NET Core Web API

JWT Authorization in .NET Core -- 401 Error

.NET Core Authorization - Constant 403 on JWT Bearer

ASP.Net Core 5.0 Authentication and Authorization

ASP.NET Core with optional authentication/authorization

.NET Core WebApi Authentication & Authorization via Azure

.Net Core 2.0 Web API using JWT - Adding Identity breaks the JWT authentication

.Net Core 2 JWT, Angular 2 Authorization through roles does not work

Exploring Changes to Authentication and Authorization Setup in .NET 7 API with JWT

How to redirect to log in page on 401 using JWT authorization in ASP.NET Core

transfer JWT Authentication implementation from .net core 2 to asp.net web api 2

Setting up JWT authentication in .NET core 2.0

JWT Authentication and Swagger with .Net core 3.0

Authentication/Authorization using Asp.net Core 2.1 and Identity Server 4

ASP .NET Core Identity default authentication vs JWT authentication

Cookie authentication not working properly with JWT authentication ASP.NET CORE