DEV Community

Cover image for Authentication with JSON Web Tokens in .NET Core 3.1

Authentication with JSON Web Tokens in .NET Core 3.1

Patrick God on March 12, 2020

This tutorial series is now also available as an online video course. You can watch the first hour on YouTube or get the complete course on Udemy....
Collapse
 
kjrjessop profile image
Kyle

Hey Patrick, thanks for taking the time to make this awesome series, its one of the best I've found to date! The next sections can't come quick enough!

Any chance you could cover seeding data to a DB so that we can seed the setup data each time a new instance of the application is run? ie. the data like rpg classes which we wouldn't want to recreate each time, but rather just seed the standard 5 or 6 classes that one can choose?

Another idea might be to cover role based calls so that if I am an "admin" user, a call might return different/more data than if I was a "standard" user?

Thanks again and keep the content coming!

PS. In your video series maybe you could also include setup on a Mac? SQL is not available for Mac users so I wasn't able to easily connect to a local DB. It took a little research but I eventually got my SQL DB up and running on a docker image.

Collapse
 
_patrickgod profile image
Patrick God

Hi,

Thank you very much! :)

These are good ideas. I will remember them and probably add them as "bonus" chapters - at least regarding seeding the database and role based authentication.

I'm afraid I don't have a Mac. But maybe I'll add a chapter with SQLite. You can use SQLite on MacOS, hence you wouldn't have to use SQL Server with Docker. The code should stay the same, just the connection string would be different, I guess.

Let me think about this. ;)

Take care,
Patrick

Collapse
 
tintow profile image
Tintow

Hi Patrick,

This is a great series, thanks for the effort you are putting into this.

In this episode, CreateToken is first shown as being declared 'static' but I don't think it should be?

Many thanks!

Collapse
 
_patrickgod profile image
Patrick God

Hello again and thank you very much again. :)

And you are correct again, I removed the static keyword.

Stay healthy!
Patrick

Collapse
 
npiasecki profile image
Nicholas Piasecki

This is the most lucid, clear explanation I could find of how to do this. I'm a long-time .NET developer, but sometimes walking into a new framework there's just so much any abstractions that it's hard to know where to start. Thank you!

Collapse
 
_patrickgod profile image
Patrick God

Thank you very much, Nicholas! :)

Collapse
 
nasierjaffer profile image
nasierjaffer

I have learnt a ton from this series, thank you for selflessly sharing Patrick!

Would you mind showing us how we can go about resetting a users password? The username in my test application is a email address.

I have implemented the following mailkit solution and it works pretty well apart from minor bugs that was fixed in the version I am using - Version="2.10.1

github.com/ffimnsr-ext/article-dem...

Collapse
 
vpvpp profile image
vinod patil

Thank you Patrick for this awesome series..!!
I like the way you have devided the content step by step.

I am still newbie in asp . net core world and learn a lot from this series regarding web api and repository& service pattern.

God bless you...!!

Regards,
Vinod

Collapse
 
_patrickgod profile image
Patrick God

Thank you so much! Means a lot! Really glad the course resonates with you.
And please stay tuned! New updates and a complete new series on Blazor WebAssembly are coming soon. :)
Take care & stay safe,
Patrick

Collapse
 
aaiing profile image
AAI INGENIERIA

Hi Patrick! i trying contact you from Twitter DM and you have disabled sending message, i fowared in graphql-authentication and i need how to show graphql login response with only token and id_user. Help me this problem i pay for it, thanks a lot coleague.

Collapse
 
_patrickgod profile image
Patrick God

Hey,
Thanks for the wait. DMs work now. I do not quite understand your question. Feel free to elaborate, also on Twitter now if you like.
Take care,
Patrick

Collapse
 
metapone profile image
metapone

When you used AddJwtBearer in Startup.cs, the AppSettings token was converted by the GetBytes method of Encoding.ASCII instead of Encoding.UTF8 like in AuthController. But then I tried running it and it still worked. Could you explain to me why?

Collapse
 
aaiing profile image
AAI INGENIERIA

Patrick how much, to learn programming .NET CORE 3.1 GRAPHQL, stage login with JWT via private stream??

Collapse
 
_patrickgod profile image
Patrick God

Happy to help with that. Please send me a DM on Twitter. :)

Collapse
 
markers16123 profile image
markers16123 • Edited

Should we manually manage tokens in this scenario? Is there an article explaining an example of combining middleware with UserStore to work?

Collapse
 
padmanathanramasamy profile image
padmanathan-ramasamy

Please share the GIT location and can you implement role based authentication in this sample.