Login API with JWT token Authentication in Asp .NET Core 6.0 Web API

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey guys welcome to my channel in this session we are going to see how to implement JWT token in our DOT net core 6.0 web API before starting the session guys if you are new to my Channel please hit the Subscribe button and ring the bell icon for future notification and if you ended up liking my video give me a like and give me a suggestion in the comment box let's get started so what is authentication authentication technology provide access control for systems by checking to see if the user credential match the credential in the database of authorized users which we are going to see today and what is JWT JWT stand for Json web token is a object which is used to securely transfer information over the web between two partners like the web API and the client client may be a web or Android or a um uh Windows system it can be used for an authentication system and can be also used for information exchange the token is mainly composed with header payload and signature and these are separated by Dot the Json web token or JWT token is simply a Json payload containing particular claim the key property of JWT is that order to confirm if they are valid only we need to look the token itself so this is all about the theory part of Jesus download token for this session we are going to use a nuget package that is Microsoft dot asp.net core Dot authentication.jw2brr so for this session I am given a table a TBL user where full name email ID password designation created that is there so I am going to authorize this authenticate this user by checking the email ID and password so I have created this application where if you see and they have we have um this weather forecast by default con API and we have get all product if I'm executing this one I am getting the product detail from my table from TBR product from this table I have two API here one is get all product and one is get product by code so if I am post by code it will send me the single product okay and I have one more API which is name as post login detail here I am getting the token or I will get the token in the post login detail here if you go to login controller I am checking with the TBL users email ID and password and I'm using here insomnia from testing my API so if you see my local This is My URL 5186 and so if I send here so it is coming in valid credential so if you go to the TBL user so let's say I'm giving Alex so email ID will be Alex at demo.com and password will be one two three four five six so if I send now so it is coming login success access token is not coming so in this part now we are going to implement how to generate the action token and one more API we will get products where we are getting the product list we will go to authenticate this one okay so for this we are going to use this nuget package jwtp error stop the application from running go to our nuget package manager that so here it is 7.0 and it's for DOT net core 7.0 I'm going to use the last one 6.0.13 select this and install okay foreign .json file here we need to add our JWT details so if you see this one Rd comma then we can add our jwd detail foreign detail which is key is your audience and subject so so I'm giving the subject as service token okay now next part is we need to go to our program.cs file I'm going to modify here I'm going to R1 Builder dot service we need to configure service here so I have added Builder dot service dot R authentication jwtbr default it need a using statement so using Microsoft asp.co.authentication.j root beer here token parameter I am using the option is service header metadata service I'll be save token and token validation here I am taking the valid audience from my half setting.json file audience and issuer okay in this issue a signing key I am using symmetric security key which is using system.txt it is taking that 0 voltage from my offsetting.json file right now one more thing we need to do before running the application after the app authorization of dot use Authentication right so our configuration is done we have added our nuget package we have added zerubility details in our offset indoor Json we have configured our Builder dot service and we have configured our app Dot use authentication now next part is we need to go to our login controller in this section I am just printing user Dot login success right in user message but if we go to this particular model there is one more properties called token I am going to display the token after login success so for that I am going to create one more method so I'm just keeping public thing get token in this part I am going to pass the same user model here so it will be user model user data I am giving in this section I am giving birth claims equal to new claims where it takes JWT register it will add system.identitymodel.token in claim suction also security dot claim okay next section is this user data so let's give Edge view data like this so okay I have given ID foreign generate Constructor hold on so order The Constructor here I'm taking these configurations so it is also taking configuration.jwts object which is our offsetting.json this object token okay next thing is I'm keeping like Bar Key equal to symmetric key symmetric security key then sign in token I am taking the configuration from J root is sure and audience now here I am getting the token value with JWT security token Handler right token now I am returning this one okay right I am going to keep inside my so I've given like underscore user data Dot access token equal to this so let's run the application and see we are getting the access token or not okay guys I just did one modification I remove the function here and added my code inside the direct the apis okay so it got run now you can see our API got running so go to our API tester so get all products check it is working or not it is still working so how we can without talking it is working so we can go to our controller section here we can keep authorized right now run the application and we see it is working without token or not then we will generate the token and we'll pass the token to this controller this API and we'll see it is coming unauthorized now go to post record you can see I'm giving exact HP user ID and password from the table so I am getting the token so in this case I am taking these tokens generated token and going to my get API so here authorizations I am adding drr token I am giving the token as this now keeping send so now yes we are getting 200 we are getting the record so in this way we can Implement JWT token authentication system in our DOT net core 6.0 web API guys I will keep this application source code Link in the video description you can also download and check it out and guys if you like this video give me the thumbs up and share this video with your friends thank you very much
Info
Channel: Biswa Ranjan
Views: 17,753
Rating: undefined out of 5
Keywords: JWT, ASP.NET CORE, WEB API, DotNet CORE, core, .Net Core 6.0, .Net Core 6.0 JWT Token, .Net Core 6.0 JWT Token Authentication, Dot Net Core 6.0, Dot Net Core 6.0 JWT Token, Dot Net Core 6.0 JWT Token Authentication, .Net Core 6.0 Web API, .Net Core 6.0 Web API JWT Token, .Net Core 6.0 Web API JWT Token Authentication, Dot Net Core 6.0 Web API, Dot Net Core 6.0 Web API JWT Token, Dot Net Core 6.0 Web API JWT Token Authentication, Learn .NET, Learn Dot Net
Id: hcDjvCk47dg
Channel Id: undefined
Length: 13min 35sec (815 seconds)
Published: Wed Jan 11 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.