Generating JWT Tokens | ASP.NET 6 REST API Following CLEAN ARCHITECTURE & DDD Tutorial | Part 2
Вставка
- Опубліковано 25 сер 2024
- Link to the full playlist: • ASP.NET 6 REST API Fol...
Become a Patreon & get the source code: / amantinband
Follow me on 'em socials:
Twitter: / amantinband
LinkedIn: / amantinband
GitHub: github.com/ama...
What is this series?
We'll build a REST API following Clean Architecture & Domain-Driven Design principles completely from scratch.
We will use .NET 6, EF Core, and common patterns such as CQRS, unit of work, repository, mediator, and more 💪🏽
We'll also use some awesome open-source libraries such as MediatR, FluentValidation, ErrorOr, Throw, Mapster, and more.
The developing environment will be visual studio code & dotnet CLI only. We will use awesome vscode plugins for everything from sending HTTP requests to connecting to our SQL database, debugging, and peeking at JWT tokens.
We will code and refactor multiple times to tackle the many concepts I want to teach. When the series will be over, you'll have a good understanding and intuition on how to use these patterns & libraries in your industry-level applications.
How often will a new part come out?
Once or twice a week.
What are we doing today?
We'll create a JWT token generator & use the "Options Pattern" to retrieve the values from the appsettings. We'll then remove the secret and use the "dotnet user-secrets" feature to store our secrets instead.
After this video, you should have a better understanding of the application vs infrastructure layer and what goes where 💪🏽
Do you love hidden gems? Well, if you do and use vscode, you're in for a treat!
#dotnet
Really great mention of using user secrets during development. I think people don't sanitize their sensitive configuration information when committing code.
I've been guilty of this myself until I learned the proper way to do it.
Hands down, the best tutorial on the topic I've found so far!
I'm humbled, thank you 🙏
the same here
i agree
It is true.
You have made the concepts so simple, usually devs don't understand this even after years of experience
Thanks NK! I appreciate your kind words🙏
Thank you for this series. It's really great. no bullshit, no extra explanation, just straight to the point and to the code. I really love it. keep doing this!
Before watching this I was doing clean architecture a different way but I realize I was making a huge mistake and even though it was not really hurting us badly, it could hurt us one day. But this also increased my confidence as I realised I was doing a lot of things right! Thanks a lot for this course and this series. Best of luck to you in the future mate.
I'm really enjoying this series and I love and use the clean architecture organization in nearly all my projects. One thing I've started doing that I offer as a suggestion to you, is making the Infrastructure implementations internal so that the presentation layer can't accidentally use them directly. Only the Dependency Injection class is public to facilitate DI registration.
Thanks Kyle, really happy to hear! I'm planning a video with a few tricks we can do to avoid having infra details leak into the presentation layer. public -> internal is one of them. I won't say the rest cuz it's a spoiler 😁
@@amantinband how exciting! very interested to hear other such tricks :-)
This is the real deal. Thanks for taking your time to do this 🙌
You're welcome, I enjoy making them 😁
the best tutorial I've ever seen in terms of clean architecture & DDD, downloaded and might reference to it several times, thank you sir.
Thanks Zhang 🙏
to me, this was the best video that I've ever seen, I`m eager to see your upcoming videos asap. specially thanks for using user-secrets which makes this video more practical.
Best comment I could get. Thanks, Afsaneh 🤙
One of the most tutorials I have ever seen, thank you 🙏🏻
You are actually a good teacher. Thanks
This is my first time lerning about clean architechture and my mind is swirling already. will try to let the logic and code sync in
after finisihing the first part... that is exactly what i needed... The only thing i do different is using visual studio and all different class library projects, but with very small changes all works perfectly... Thanks
I will be waiting here till the next one comes.. no pressure 🙃🙃
the problem is, that is all so much quick and I'm just blindly copying code without knowing what I'm doing or why.
Wow Amichai!
you are an amazing teacher or content creator, the explanation of the steps and the knowhow is incredible!
Ty very much and keep going ✔✔❤❤
I can't wait to see how this channel will grow in the near future
Same 😁
Thanks Amichai Mantinband. Really appreciates work explanation and approach. it's very insightful.
Great videos, I just want to build a restapi service with authentication, but can not find other tutorials, however these videos helped me!
Please add refresh token and O auth authentication video on this series.
Thanks for this course. It's just second video, I can't wait for more. Keep doing great job 💪
Great speed in videos. You aren't too slow, as some other UA-camrs are. Good explanations of the code.
One note, I think you should discuss or just share your VS Code extensions, if you can. Sometimes I was a little confused - "what? How?" 😀
Thanks Patryk, I'm really happy to hear! I think I covered all the extensions I use (other than vim which is a series of its own 😁). What were you curios about?
@@amantinband do you have any extension for something like 'auto using statements' and for namespaces? I think I don't have that function in my VSCcode. Or am I wrong?
Whoops I completely forgot to talk about all these must have extensions. I think my next video will be all about vscode for .NET developers, where I'll cover all the extensions I love and a few configurations which make life much easier 🙂
@@amantinband it would be great 🙂 not every developer uses VSCode every day 😀
very useful, easy to follow series
tip for those who are used to use the visual studio; like myself, the vs 2022 have the rest client, and the jwt tools; substitute for the jwt decoder, plugins which work just like their vscode counterparts.
once again, thanks for the series.
Why do we need the IDateTimeProvider? I can't see any benefits of this abstraction. The interface has a property named "UtcNow" and the implementation returns, as expected, a UtcNow.
I believe you know what you are doing. But it would be great if you could provide some rationale on this decision.
Great video! I guess it could be a bit better to have some more details in case you do something different in some places for example why JwtSettings is a class and not a record as another models
Jesus this videos has 1k likes and literally 0 dislikes unless the chrome extension is broken, anyway thank you for this amazing video.
Wow working in vscode with those convenient extensions can be a lot of fun.
Excellent article. I request can you please also create a step by step document. It will be very helpful. Thank you very much for your effort to elaborate Clean architecture & DDD.
The way I understood your explanation in the beginning was that the Infrastructure layer can only depend on the application layer for information, yet in this video you use the Domain model in the Infrastructure layer, which shouldn't be since it doesn't depend on the Domain layer.
Perhaps I could have been clearer. Outer layers can use inner layers. You could also reference the Domain layer directly from the infrastructure layer if you'd like
@@amantinband I see. Thank you for that reply.
Superb series please continue.
Very good tutorial!. I found many useful tips for using dotnet cli.
Amazing videos, very high quality. Thanks and keep up the great work.
Hi Amichai, thanks for creating this amazing video, can I know what extensions you have installed that give you these amazing autoCompletion and quick refactor options?
Excellent
Thank you so much.
Can't wait for the next video.
22:21 you’re very welcome 🤣🤪❤️
Thanks for sharing. All videos were amazing.
waiting for part 3, thank you ❤
Github copilot knows so much
Could you please tell me why you built the token generator feature in the infrastructure layer instead of just creating a separate service in the application service layer? Thank you.
You have the same question as mine.
Great video man!
Keep up the great work
You're awesome, thank you for sharing.
great series, thank you for explaining.
Love the series so far, great didactic skills! :)
By the way, do you have the Miro Board (or whatever you're using for the architecture documentation) uploaded somewhere? Would love to add that to my notes!
Awesome content thanks!! It would be really helpful if you could do a video on event sourcing..
It’s in my plans 👍🏼
Quick question - what is the reasoning behind putting the interface in the application layer and the implementation in the Infrastructure layer?
The idea is to put the interfaces close to the part of your code that consume it... application layer in this case.
I'm using the same super-secret-key but when I try to run the register request, it throw an exception saying
> Unable to create KeyedHashAlgorithm for algorithm 'HS256', the key size must be greater than: '256' bits, key has '128' bits. (Parameter 'keyBytes')
I understand the error but I don't understand why it works in the video
Anyway thank you so much, high quality content!
great series.... btw I can't seem to see all these refactorings in vs code, although I did install rosylnator and enabled refactorings.... are u using another extension ?
1. Love how you have a graphical view of the UI/architecture. What do you use to create that?
2. Could you make a video on how you navigate through vscode so fast? Some examples are how you easily bounce between explorer and editor and delete whole word from editor
Thanks!
Great to hear. I create all the visuals in figma.
Most of the code navigation tricks are done with the vim plugin. Since I've been getting many questions about it, I think my next video will be all about vscode extensions for .NET developers
@@amantinband awesome. Thanks and it'll be much appreciated
Best Video for understanding Clean Architecture via implementation.
I want to know which extension or anything you are using for the intelligence of code.
I have a video all about vscode for .NET development: ua-cam.com/video/m9HvsB1-hAo/v-deo.html
Thanks for these incredible tutorials. I look forward to continue following along! I was wondering if you could provide some more info on why creating a date time provider is necessary/preferred. I use DateTimeOffset in almost all my projects, but I've never pulled it out into it's own provider before.
If you use DateTimeOffset then for unit tests. When using DateTime it can also help enforce using UTC only
Thank you for your work!
Hello, Thank you for this training. I do have a question related to JWT implementation. I still don't understand why the JWT implementation needs to be added in the Infrastructure Layer rather than the Application Layer (as a service). Is this a type of constraint?
Absolutely helpful ❤️
At first, thanks so much for this video. Could you share the name of the extensions that you used in VS Code, it looks so powerful to suggest and help develop quickly. is it any AI tools or not?
I need to know the vs code extension that suggests while you are coding. Please :)
Check out my latest video 😉
why is the auth service not implemented in infrastructure? Great playlist btw.
Should Authentication process be a concern of Application or API? Because JWT seems like a web API specific implementation. What if I want to use Application on an async messaging context instead of REST or GraphQL?
Thank youuuuu so muuuuuch!
if you get security key issue please increase key
Not 100% sure, maybe it's my error, but sometimes before minute 10 mark, when we are making additions to BuberDinner.Infrastructure.Authentication DependencyInjection file, it was non-empty, I mean we had services.AddScoped for a different interface.
Thank you very much!
Hi Amichai, Why do we have the Authentication Service implementation in the Application project but not in the Infrastructure project?
Hi, i would really like to see if you can implement identity server on this project on a different video maybe? I keep rewatching this series to implement stuff to my project that i learnt from you.
My english is kinda bad, sory for typos.
Great work, but your elocution is very fast, and I have to slow down the video speed, which affects the sound quality
Why is the IJwtTokenGenerator interface at the application layer? Shouldn't it be in the infrastructure layer?
Great professor. Thanks'
Aaaand YES! Good job! (=
10:11
Why? What value does that add to anything? I don't understand why you created a singleton that encapsulates/ adds a layer of abstaction to one line of code "DateTime.utcnow;"
It would make sense if you would do something constant all over that application with that serviceprovider, let's say add 60 minutes ( and in the future you want to change that to 30 for whatever reason ) but the client still controls how much time to add to utcnow timestamp.
So again, why?
Hi, can you make a video on the basics of jwt
you have this error ==> 'IServiceCollection' does not contain a definition for 'Configuration' even though IntelliSense suggests otherwise
add this nuget package ==> "Microsoft.Extensions.Options.ConfigurationExtensions"
Thanks for this great video. I wanna ask about usign UTC Date times. In generally we can use UTC times in our web api, not only in jwt. So should consumers (SPA or Mobile) of our api convert all dates to local date time?
best idea using secret!!! but how to publish the secrets?
hey thanks for this amazing video, quick question: how do you draw those arrows and rectangles so fast? is there any particular programs you use?
Hi, what extensions do you use in vscode for dotnet development ?
Till now very classic.
Have got one Q: How do we separate this into a microservice design? , coz I see the infrastructure and application the dependencies are being injected.
Thanks, perhaps in the end of the series I'll demonstrate how the service can be split via different methodologies (i.e. Modular Monolith, Microservices etc')
this is good shit!
is it possible without EF can we design DDD in dot.net core?
Thank You!
Hello ,
move to the second video,
I really want how to get the auto-completed or auto-generated code like you do work with intellisense and autogenerated line of codes.
Thank you.
Hey, I have a video all about setting up vscode for .NET: ua-cam.com/video/m9HvsB1-hAo/v-deo.html
Amichai, thank you so so much for such a valuable content!!
i've got one question though... Why have you put IJwtTokenGenerator inside Common-->Interfaces-->Authentication instead of Authentication folder at the top level of Application layer? Is IJwtTokenGenerator going to be used in contexts other than Authentication one? I am new to .Net truth to be told, but have been building client side with angular for a while using DDD, and as far as I understand Common is like Shared, isn't it? Do we have to reduce Common to the minimum only put there 'code entities' sparingly in case we really need to reuse 'em across domains? At least that what I have been doing on FE side..)
at 4:05
what is name of extension that generate code for such as which happened in 4:05 ?
thank you for tutorial , it is really awesome
github copilot (-x)
Great video's! What piece of software do you use to create those diagrams/images? Also curious what you use to box and point during your explanations?! Thank you!
Thanks! All the visuals are created in figma. For drawing on the screen I use ZoomIt. I first saw it used by Scott Hanselman, he has a few videos talking about it if you want to learn more
You Are Amazing
Why use 'SectionName' when there's nameof()?
Are you going to be using entityframework core?
Yup 🙂
Thanks for the great video.. I have a small question, why not put the IJwtTokenGenerator in the "Infrastructure" project instead of "Application" project ?
In Clean Architecture, "infra" concerns are declared and used via interfaces defined in the application layer. The actual implementation sits in the infra layer.
If the interface was defined in the infra layer, it couldn't be used by the application layer since it doesn't reference it
thank you
Do you have the list of extensions that you are using? I've used Visual Studio but I'm new in using Visual Studio Code and the recommendations that appear when you type does not appear on my Visual Studio Code. It's a bit hard without that recommendation setting
Hi, what’s the extension you’re using that is helping you to have this kind of auto-complete like this?
GitHub Co-Pilot. But beware, it's hard to go back 🤓
Hi Amichai Mantinband, thanks for the great tutorial. May I know how you get the auto code suggestion in VS Code?
Good question. I was curious about this
The suggestions are coming from the GitHub Co-Pilot extension
Are you going to make some unit or integration tests for the project?
Yup 👍🏼
Hello Amichai! Nice video!
I have a question: what VSCode extension are you using to launch the http requests, if you be so kind?
Thank you!
Hey Cristiano, I'm using the REST Client extension. I actually have a video about setting up vscode for .NET:
ua-cam.com/video/m9HvsB1-hAo/v-deo.html
Thanks a lot, very useful.
Can you please tell which extensions you have on VS Code?
I think my next video will be all about vscode for .NET developers. I'll cover tips, tricks and all the extensions I use 🙂
I'm looking forward to it :)
Great
In min 17:36, what extension do you used to have wrap parameter options?
Not sure which extension it comes from, perhaps roslynator. I have a video all about setting up vscode for dotnet development. Check it out!
what extensions are you using that is allowing you to do the injection to create the constructor?
I belive this is from the default visual studio
How did you hide the bin and obj folders
I have a video about setting up vscode for .NET in which I cover this (the link will take you to the correct place in the video):
ua-cam.com/video/m9HvsB1-hAo/v-deo.html
What is the program you're using for the visuals at the beginning?
All the visuals are created in figma
Too fast speaking. Not enough clear explanations.
JWT is short for (J)SON (W)eb (T)oken. If you name something JwtTokenGenerator, I'm reading this as "Json web token token generator". It doesn't affect functionality, but it makes my eyelid twitch.
Other then that, great content. Especially the user-secrets part.
Haha yeah that's a good point. That's what happens to me when I see a variable named jwtToken. Perhaps JwtGenerator would be a better name
shouldn't the secret be twice as big? When I use "super-secret-key" as secret I get an error saying that hmacsha256 needs 256 bits while my key has 128. How do you not get this error?
I'm using .NET 8 and had the same problem.
Found it! Replace "super-secret-key" for a longer string, not less than 40 characters and it works like charm.
@@Sergueio 8 bits per character, so you need 32 characters.
Absolutely amazing tutoria..One quick question what is the need to use dateTimeProvider when the there is a method in DateTime.UtcNow.AddMinutes(60);
I just needed a little clarification on this..Really appreciate the content you are providing
It allows mocking the date & time in unit tests and can help enforce using UTC date time