Token Authentication In ASP.NET Core 7 With JWT | Clean Architecture

preview_player
Показать описание

Token authentication is a popular approach for authenticating REST APIs. In this video, I'm going to show you how to create a JWT in your ASP.NET Core application. Then, you'll see how to use this token to implement token authentication for your API.

Join my weekly .NET newsletter:

Read my Blog here:

Subscribe for more:

Chapters
0:00 Creating the Login feature
6:28 Login API endpoint to get JWT
8:17 Generating the JWT
15:30 Configuring Authentication in ASP.NET Core
21:28 Inspecting the generated JWT
Рекомендации по теме
Комментарии
Автор


If you run into any issues while trying to implement this, I made two mistakes in the video:
- At 16:00 it should be one call to `UseAuthentication` and one call to `UseAuthorization`
- `JwtBearerOptionsSetup` should implement `IConfigureNamedOptions`

MilanJovanovicTech
Автор

Nice tutorial, especially the solution approach with options is quite pro.
For those who try to use the example code with NET Core 7.0 will not have their JwtBearerOptions initialized thus token validation will fail.
To solve the issue JwtBearerOptionsSetup must derive from

JwtBearerOptionsSetup :

public void Configure(JwtBearerOptions options)
{
= new TokenValidationParameters
{
ValidateIssuer = true,
ValidIssuer = _options.Issuer,
...
};
}

public void Configure(string? name, JwtBearerOptions options)
=> Configure(options);

tosunabi
Автор

What a tutorial !!!! Lacking words to describe this, everything is professionally done !! I like the way you handle errors, I liked the way you use DI and they way you did set up the JwtBearerOptions instance, thanks buddy .

kirwakelvinkering
Автор

Join more than *42, 000+ .NET engineers* already reading my weekly newsletter.
One actionable tip, every Saturday, less than a 5-minute read:

MilanJovanovicTech
Автор

Thank you Milan! Another useful video and excellent quality of the content. Cannot wait to see the Authorization part :)

MXDMND_
Автор

Thanks, Milan, This video helped me to integrate the JWT-based authentication in Clean Architecture. I searched a lot of articles and videos but this one is great 🚀

TheBishalSaha
Автор

I never leave comments on videos, but this one absolutely deserves it. Great tutorial, not the average ‘just get it done’ attitude. So much effort into doing it cleanly and actually teaching proper techniques.

Thank you.

I’m interested in learning more on the command implementation done at 0:50 and your overall project structure and approach.

Are the any further videos on this project?

BSpangenberg
Автор

One of the best tutorial I have watched so far in any topic, very clearly explain all you need, well done

itskills
Автор

you're an artist, man! this is pure art.

ebrahim-s-ebrahim
Автор

Thank you Milan! Excellent quality of the content.

valterdebrito
Автор

As always I learned a lot...can't wait for the next video.💯❤

birukayalew
Автор

This was exactly the video I was hoping for, thank you very much!

roefski
Автор

Great vid as always!
one small mistake at 16:00 you added the Authentication middleware twice and not the Authorisation middleware

Repectful
Автор

I recommend creating a solution from scratch since it is too confuse to understand cause you have already lots of code in your solution.

justfair
Автор

Very interesting video. Waiting for next. Special thanks

danielegiovanetti
Автор

Kindly smashed the ring bell button too. What about token expiration? Should we use refresh token endpoint or there is sliding expiration if we use this method?

newguycho
Автор

This is great for anyone want to go into identity

It will be very good if you continue it as a serie with openid dict 3 and extend it to oauth 2 and openid connect

mahmoudalaskalany
Автор

Absolutley subscribed! Amazing content delivered so well. Thank you.

manofqwerty
Автор

You're the best tutor I ever had, Thanks a lot buddy!

ssudharsan
Автор

Hi Milan,
Thanks for sharing your knowledge with us. It would be really great if you create one guide for handling refresh token

ratnadeepkadam