Easy JWT Authentication & Authorization with Spring Security | Step-by-Step Guide

JWT Logout: • JWT Logout: The Trick ...
Refresh Token: • Implementing Secure Re...
Welcome to our tutorial where we'll walk you through the seamless integration of JWT (JSON Web Tokens) authentication and authorization into your Spring Boot application using Spring Security and JJWT.
In this step-by-step guide, we'll cover everything you need to know to implement JWT-based security, ensuring your application's data and endpoints are protected with industry-standard authentication and authorization techniques. Whether you're new to Spring Security or looking to enhance your skills, this tutorial is perfect for developers of all levels.
By the end of this video, you'll have a solid understanding of how to set up JWT authentication and authorization in your Spring Boot project, empowering you to build secure and robust applications with ease.
Don't forget to like, share, and subscribe for more insightful tutorials on Spring Boot development! Let's dive in and unlock the power of JWT security with Spring Security and JJWT.
📘 Resources Mentioned:
🧑‍💻 Source Code: github.com/hello-iftekhar/spr...
⛔ Background sound: share.epidemicsound.com/ia954g
🤚 In case you want to contact me:
❌ My LinkedIn profile: / iftekhar-hossain-369bbb6a
❌ Github: github.com/hello-iftekhar
❌ My Fiverr profile: www.fiverr.com/ifte_hsn
I also provide service on Upwork. In case you are interested:
❌ www.upwork.com/freelancers/~0...
Contents:
00:00 Intro
00:14 What are we going to cover
00:55 What is JWT
01:09 JWT like digital passport
01:22 JWT is like Sandwitch
01:35 JWT example
01:38 Header of JWT Token
01:45 JWT Payload
01:59 JWT Signature
02:46 Initialize new Spring Boot Application
03:41 Adding Dependency
05:03 Connecting to database using IntelliJ IDE built-in tool
7:31 Renaming application.properties file
07:46 Configuring Spring Boot for database connection
11:43 Creating user class
15:32 Adding Role class
16:05 Creating Role Class
19:09 Creating UserRepository
23:27 Explanation of Access Modifiers
24:00 Java's Default Access Modifier
27:22 UserDetailsService Implementation
29:45 Add jjwt dependencies in the project
32:05 Creating JwtService
33:42 Generate the token
36:16 Extract Payload/Claim from the token
38:04 Extract username from claim
38:34 Validate the token
40:04 Check if the token is expired
40:55 Creating JWT Filter
47:53 Configuring Spring Security
52:02 Creating AuthenticationController
52:40 Creating AuthenticatinService
59:05 Testing the application

Пікірлер: 212

  • @LearnWithIfte
    @LearnWithIfte4 ай бұрын

    When you are sending a request without a token or with the invalid token you will get a 403 status code. But this should be 401. So I make a video demonstrating how to fix it. you can check it from here: kzread.info/dash/bejne/p5esmNmoZsfWaZs.html

  • @meryemOuyouss2002

    @meryemOuyouss2002

    Ай бұрын

    OK sir thank you so much 👍👍

  • @caiovitor5197
    @caiovitor5197Ай бұрын

    My man, you're a life saver, I was building a auth-server microservice for my college class and spring security wouldn't work. Threw that all way and followed your tips and guides, now it's running and the authentication is the sweetest thing. Thank you so much for your help!!!!

  • @geybriyel2416
    @geybriyel24162 ай бұрын

    Thank you so much! This is very helpful. I've been struggling a lot with implementing JWT-based security on my api during the last quarter of 2023. Almost all tutorials and guides were already outdated and contained a lot of deprecated methods, and reading the documentations were a pain in the ass too. I got stuck with my personal project cz of it. Until now! You saved a lot of beginners, Iftekhar. Thank you!!!

  • @LearnWithIfte

    @LearnWithIfte

    2 ай бұрын

    Thank you for watching. I am glad to know that it was helpful for you.

  • @eneser401
    @eneser4012 ай бұрын

    This tutorial is awesome, i didn't code for 2 years, now i'am back at it, it was very difficult, but this video was everything i needed, thank you so much.

  • @LearnWithIfte

    @LearnWithIfte

    2 ай бұрын

    Thank you for watching. I am glad to know that it was helpful for you.

  • @irule10338
    @irule103383 ай бұрын

    THANK YOU! Best video because you used up-to-date methods and not many deprecated ones like other videos

  • @LearnWithIfte

    @LearnWithIfte

    3 ай бұрын

    I'm glad you found the video helpful!

  • @user13443fg

    @user13443fg

    2 ай бұрын

    true

  • @HemantKumar-xl5dv
    @HemantKumar-xl5dvАй бұрын

    Sir, I understood the concepts well because of your teachings.

  • @naumtinga
    @naumtingaАй бұрын

    Thank you for the updated and detailed tutorial on this subject

  • @UsamaKhan-ct4bc
    @UsamaKhan-ct4bc3 ай бұрын

    Best video so far on Spring Boot security.Respect!

  • @LearnWithIfte

    @LearnWithIfte

    3 ай бұрын

    Thank you for the kind words, glad you enjoyed the video!

  • @user-vs8px9dl4i
    @user-vs8px9dl4i4 ай бұрын

    Love the way you teach simple and perfect keep doing it

  • @LearnWithIfte

    @LearnWithIfte

    4 ай бұрын

    Thank you so much for your kind words! I'm glad you find my teaching style helpful.

  • @zarroukkoussay6455
    @zarroukkoussay64554 ай бұрын

    Great video!! It really helped me, I found difficulties since a long time in security but thanks for help

  • @LearnWithIfte

    @LearnWithIfte

    4 ай бұрын

    Thank you so much! I'm glad the video was helpful for you in overcoming your security difficulties. Keep up the good work!

  • @manoharanrajendiran568
    @manoharanrajendiran568Ай бұрын

    ❤You are making complex to very easy with your professional explanations. 🙌 ❤

  • @shadow.youtube
    @shadow.youtube4 ай бұрын

    Literally I watched lots of videos, didn't understand that much because JWT implementation java a little bit complex and finally got your video sir, this is really amazing for those(like me) who want to understand the architecture behind the implementation and the procedure of implementation. Really appreciate your valuable time and this amazing explanation. Thank a lot sir.

  • @LearnWithIfte

    @LearnWithIfte

    4 ай бұрын

    I'm glad my video could help you understand the complex topic of JWT implementation in Java! It's always great to hear that my explanations are helpful to viewers like you. Thank you for watching and taking the time to leave such a positive comment!

  • @Dulan_M_Herath

    @Dulan_M_Herath

    3 ай бұрын

    same here, watched tons of videos but this one is the best of the best. everything is explained. short and sweet

  • @user13443fg
    @user13443fg2 ай бұрын

    Thankyou, it really worked for me! learned something new 👍

  • @LearnWithIfte

    @LearnWithIfte

    2 ай бұрын

    Thank you for watching.

  • @robertbiro1538
    @robertbiro153822 күн бұрын

    Thanks! It was perfect, ! It really helped me!

  • @saravanankaliyamoorthy49
    @saravanankaliyamoorthy492 ай бұрын

    This really helped me a lot. Thanks for such a tutorial

  • @LearnWithIfte

    @LearnWithIfte

    2 ай бұрын

    Thank you for watching. I am glad to know that it was helpful for you.

  • @saravogelin
    @saravogelin3 ай бұрын

    I really thank you for this tutorial. After searching for a long time this is the first one I found that is no using deprecated mothods for JWT version 12.

  • @LearnWithIfte

    @LearnWithIfte

    2 ай бұрын

    Thank you for watching. I am glad to know that it was helpful for you.

  • @kutlinho
    @kutlinho2 ай бұрын

    That was very useful. Thank you.

  • @ruzibayevich1693
    @ruzibayevich16934 ай бұрын

    bro great job, thank you so much

  • @amodahegde2386
    @amodahegde238623 күн бұрын

    Such a good video and very clear explanation!

  • @andialdryan8470
    @andialdryan84703 ай бұрын

    Perfect video sir, this very help full for me. Thank you for make this video!

  • @LearnWithIfte

    @LearnWithIfte

    2 ай бұрын

    Thank you for watching. I am glad to know that it was helpful for you.

  • @goutamnamdev1304
    @goutamnamdev13043 ай бұрын

    Thank u sir for amazing explanation all concept is Crystal clear 🙌 so Thank you❤❤

  • @LearnWithIfte

    @LearnWithIfte

    3 ай бұрын

    I'm glad the explanation was helpful! Thank you for your kind words.

  • @iRozdobudko
    @iRozdobudko3 ай бұрын

    Great job! You have helped me a lot!

  • @LearnWithIfte

    @LearnWithIfte

    3 ай бұрын

    Thank you for watching. I am glad to know that it was helpful for you.

  • @rouclecasonganyi3084
    @rouclecasonganyi30843 ай бұрын

    I had a hard time finding a tutorial that uses version 12.x.x This one solved my problems Thanks so much

  • @LearnWithIfte

    @LearnWithIfte

    2 ай бұрын

    Thank you for watching. I am glad to know that it was helpful for you.

  • @ASIAZH
    @ASIAZH2 ай бұрын

    very easy to understand. thank you!!

  • @LearnWithIfte

    @LearnWithIfte

    2 ай бұрын

    Thank you for watching.

  • @l0gical998
    @l0gical9984 ай бұрын

    Love this! Keep going brother!

  • @LearnWithIfte

    @LearnWithIfte

    4 ай бұрын

    Thank you so much for the support! Glad you enjoyed the video!

  • @MeuMundoTech
    @MeuMundoTechАй бұрын

    Thanks from Brazil 🎉

  • @SekharBabuBodipudi
    @SekharBabuBodipudi4 ай бұрын

    Keep Going, You are going a long way. All the best

  • @LearnWithIfte

    @LearnWithIfte

    4 ай бұрын

    Thank you for the encouragement!

  • @HabiburRahman-dm5yt
    @HabiburRahman-dm5yt29 күн бұрын

    thanks a lot. Jajakallah khairan

  • @pritambala4471
    @pritambala44713 ай бұрын

    Love your content. Sir please post a video in a week🧡🧡

  • @LearnWithIfte

    @LearnWithIfte

    3 ай бұрын

    Thank you for yout support. I will try my best to do this.

  • @erfannavab9805
    @erfannavab98054 ай бұрын

    Great explanation. Thanks

  • @LearnWithIfte

    @LearnWithIfte

    4 ай бұрын

    Thank you so much for your kind words! I'm glad I could provide a clear explanation for you.

  • @leovelcamiloneto3608
    @leovelcamiloneto36084 ай бұрын

    Simple and clean... 👍👍👍

  • @LearnWithIfte

    @LearnWithIfte

    4 ай бұрын

    Thank you for your comment! I'm glad you appreciate the simplicity and cleanliness of the video. It's always great to hear positive feedback from viewers like you.

  • @TheStarboyVlog
    @TheStarboyVlog3 ай бұрын

    I'm impressed🎉, Just for a suggestion when you write something can you please explain it's purpose so we can also understand it more clearly and it will be helpful for future audiences. ❤

  • @LearnWithIfte

    @LearnWithIfte

    3 ай бұрын

    Thank you. I'll definitely consider explaining the code and its purpose in my future videos.

  • @swannhs
    @swannhs4 ай бұрын

    Please consider a tutorial spring boot with keycloak. Your explanation is really great ❤

  • @LearnWithIfte

    @LearnWithIfte

    4 ай бұрын

    Thank you for the suggestion! I'll definitely consider making a tutorial on Spring Boot with Keycloak.

  • @CarlosGarcia-ll8zc
    @CarlosGarcia-ll8zc4 ай бұрын

    Amazing video!!!🤙

  • @LearnWithIfte

    @LearnWithIfte

    4 ай бұрын

    Thanks!!

  • @user-re1eu1rp7h
    @user-re1eu1rp7h4 ай бұрын

    it's a good one. clean explanation. It would be great if you could include refresh token as well.

  • @LearnWithIfte

    @LearnWithIfte

    4 ай бұрын

    Thank you for your comment! I'm glad you found the explanation helpful. I'll definitely keep your suggestion in mind for future videos.

  • @MahadiHasan-qb9zw
    @MahadiHasan-qb9zw23 күн бұрын

    Its really an amazing detailed video. Will you please enhance it by securing multiple microservices with this JWT authentication ?

  • @inhhoang1542
    @inhhoang1542Ай бұрын

    thanks for your video its very helpful

  • @LearnWithIfte

    @LearnWithIfte

    Ай бұрын

    You are welcome

  • @Rajnish089
    @Rajnish0894 ай бұрын

    Beautifuly explained

  • @LearnWithIfte

    @LearnWithIfte

    4 ай бұрын

    Thank you so much! I'm glad you found the explanation helpful.

  • @Selvin_raja
    @Selvin_rajaАй бұрын

    Thalaiva your great 💥💥

  • @rahulpatil6871
    @rahulpatil68713 ай бұрын

    best explanation and its new methods uimplemented in this video .can you make any end to end project with all validations for learning purpose can you please make it. It will help to lots of students .

  • @LearnWithIfte

    @LearnWithIfte

    2 ай бұрын

    Thank you for watching. I am glad to know that it was helpful for you.

  • @ikac11
    @ikac112 ай бұрын

    thank you so much!!!!!

  • @LearnWithIfte

    @LearnWithIfte

    Ай бұрын

    You're welcome!

  • @InternationalNewsbd
    @InternationalNewsbd4 ай бұрын

    clean explanation

  • @LearnWithIfte

    @LearnWithIfte

    4 ай бұрын

    Thank you for watching! I'm glad you found the explanation helpful.

  • @Luthfihadi666
    @Luthfihadi666Ай бұрын

    damn brooo thanks 😁

  • @kriperek31
    @kriperek312 ай бұрын

    Great video, great job

  • @LearnWithIfte

    @LearnWithIfte

    2 ай бұрын

    Thank you!

  • @WoodPig
    @WoodPig2 ай бұрын

    Your video has been incredibly beneficial to me, and I want to express my sincere gratitude. At around 58:30, wouldn't it be better to use the HTTP status code 201 Created for the /register endpoint?

  • @bhargavmamidi7716
    @bhargavmamidi7716Ай бұрын

    Sir could you please add the refresh token as well to this lecture?? That would be really helpful.. thank you.

  • @krylok989
    @krylok9893 ай бұрын

    Amazing, good english, good explain

  • @LearnWithIfte

    @LearnWithIfte

    3 ай бұрын

    Thank you so much for the kind words, I really appreciate it!

  • 4 ай бұрын

    Very helpfull video! Could you please tell me what Theme you use for IntelliJ? I really like the colors of your editor :)

  • @LearnWithIfte

    @LearnWithIfte

    4 ай бұрын

    I'm glad you found the video helpful! The theme I use for IntelliJ is called Material Theme UI, it's one of my favorites too!

  • @alexkoren7648
    @alexkoren76484 ай бұрын

    👍 Thank you

  • @LearnWithIfte

    @LearnWithIfte

    4 ай бұрын

    Thank you so much for your kind words! I really appreciate your support.

  • @user-re1eu1rp7h
    @user-re1eu1rp7h4 ай бұрын

    celan explanation. It would be great if you could include refresh token as well.

  • @LearnWithIfte

    @LearnWithIfte

    4 ай бұрын

    Thank you for your comment! I'm glad you found the explanation helpful. I'll definitely keep your suggestion in mind for future videos.

  • @nadetdevfullstack7041
    @nadetdevfullstack70414 ай бұрын

    Excellent

  • @LearnWithIfte

    @LearnWithIfte

    4 ай бұрын

    Thank you so much for your kind words! I'm glad you enjoyed the video.

  • @jeevaathecoder
    @jeevaathecoder4 ай бұрын

    Great work sir, if possible make videos on chat applaication suing web socket

  • @LearnWithIfte

    @LearnWithIfte

    4 ай бұрын

    Thanks for the heads up! I'll definitely make a tutorial on this. Keep an eye on my channel for more updates!

  • @PatrickPulfer
    @PatrickPulferАй бұрын

    Thank you @LearnWithIfte!!!! Really helpful for my studies.

  • @LearnWithIfte

    @LearnWithIfte

    Ай бұрын

    Thank you.

  • @atomichub5049
    @atomichub50492 ай бұрын

    hello sir , I implemented jwt using your way for my USER entity class but ! there is one more class i.e VISITOR to that entity I also want to generate and validate token , how can i do so . let me remind you both these classes are two different entity classes and have different tables. hope you understand what i mean and I dont use roles and permission

  • @akadeadahot7067
    @akadeadahot7067Ай бұрын

    hey buddy its like a harry potter stick just wow .... because i have been doing this on today from early morning and stucked at debugging the code why some request permited but still not working and after seeing this tutorial with a source code i just have to change appplication.properties file nothing else and code runs fine. Many thanks for sharing video with us along with latest spring security filter chain implementation without any deprecated warning code. 🙂

  • @LearnWithIfte

    @LearnWithIfte

    Ай бұрын

    Wow. Thank you for watching. I am glad to know that it was helpful for you.

  • @sonnees
    @sonnees3 ай бұрын

    47:03 | 'Reactive' not use "new WebAuthticationDetailsSource", because ServerHttpRequest. pls!

  • @LearnWithIfte

    @LearnWithIfte

    3 ай бұрын

    Please check the source code from github. You will find it in the description.

  • @russellandrady
    @russellandradyАй бұрын

    Tutorial was good sir. Everything worked. But I would be happier if those configurations and other security implementations explained a bit better. I have to find them separately.

  • @LearnWithIfte

    @LearnWithIfte

    Ай бұрын

    Thanks for watching. I will try to add explanation in my future tutorials.

  • @ramazanmashanlo3432
    @ramazanmashanlo34324 ай бұрын

    Thanks for video, and what about cors? If we will call this api from frontend.

  • @LearnWithIfte

    @LearnWithIfte

    4 ай бұрын

    Thanks a lot for watching my video. I will write a blog on this and will share with you here. Hopefully, it will be helpful for you.

  • @billv1425
    @billv142515 сағат бұрын

    I am getting a 401 error. I appreciate the video defining 403 vs 401, but could you do a video that fixes the 401 errors?

  • @arunsara2183
    @arunsara21834 ай бұрын

    Great Explanation. I also got problem in using @PreAutorize like how can we use it in latest versions of spring

  • @LearnWithIfte

    @LearnWithIfte

    4 ай бұрын

    Thanks for your comment! I'm glad you found the explanation helpful. To use @PreAuthorize in the latest versions of Spring, you can simply annotate your method or class with @PreAuthorize and provide the necessary permissions or roles as arguments. Make sure you have the necessary dependencies added to your project as well. Let me know if you have any specific questions!

  • @arunsara2183

    @arunsara2183

    4 ай бұрын

    @@LearnWithIfte yeah but that's the problem i was facing while using @PreAuthorize I got 403 but while setting up role authorization in config file it works fine.

  • @LearnWithIfte

    @LearnWithIfte

    4 ай бұрын

    @@arunsara2183 can you please share your code via github?

  • @muhammedkerek9615
    @muhammedkerek9615Ай бұрын

    Hello , thank you for the explanation when i register the token is generated , but when i try to login it's forbidden and in the database , the password is not hashed it's written as it is do you know why this might be happenning ?

  • @LearnWithIfte

    @LearnWithIfte

    Ай бұрын

    Hey, thanks for watching. Unfortunately I don't have any idea why this is happening. Please check my code on github.

  • @mika-if5wh
    @mika-if5whАй бұрын

    hello, i am able to log in and register but when i use the token to login i receive this error ".HttpMessageNotReadableException: Required request body is missing" and i am unable to log in. any ideas?

  • @meryemOuyouss2002
    @meryemOuyouss2002Ай бұрын

    Thank you sir ,but I have a question when I do register I found thé 401 code but i dont know why???

  • @meryemOuyouss2002

    @meryemOuyouss2002

    Ай бұрын

    It's my fault, thank you so much for this video, now it's working very well

  • @abdur8312
    @abdur83124 ай бұрын

    Thank you for the latest JWT video. I've a doubt, when I try to access the "/demo" page with the bearer token. it's giving 404 error. I've done exactly the same steps you've done in the video. Do you have any idea what could be wrong.

  • @LearnWithIfte

    @LearnWithIfte

    4 ай бұрын

    Can you please share your code?

  • @screwyouguysimgoinghome9835

    @screwyouguysimgoinghome9835

    4 ай бұрын

    I was facing the same issue. But I sorted it out.

  • @dineshkumarsah130
    @dineshkumarsah1303 ай бұрын

    Nice 👍

  • @LearnWithIfte

    @LearnWithIfte

    2 ай бұрын

    Thanks ✌

  • @makamemawe1072
    @makamemawe10722 ай бұрын

    Thank you allah bless you

  • @LearnWithIfte

    @LearnWithIfte

    2 ай бұрын

    Thank you for watching.

  • @user-ss9sn6zr5t
    @user-ss9sn6zr5t4 ай бұрын

    Thank you for your work! I have a question. When you are accessing "/demo" without a token, you get a 403 error. But shouldn't it be a 401 in this case? A 403 means that you are authorized but do not have access, while a 401 means that your token is invalid/empty. How can this issue be solved?

  • @LearnWithIfte

    @LearnWithIfte

    4 ай бұрын

    Thank you so much for your support and for bringing up this question! It's great to see that you're paying attention to the details. You're right, there seems to be a mismatch in the error codes. I'll look into it and work on finding a solution. Your feedback is truly appreciated!

  • @LearnWithIfte

    @LearnWithIfte

    4 ай бұрын

    Hi, I have figured out the solution. We need to add a CustomAccessDeniedHandler to provide 403 error for appropriate cases and also need to add an exception handler in the SecurityFilterChaing method to handle both 401 and 403 status. I have pushed the update to the git. you can check it from github.com/hello-iftekhar/springJwt

  • @LearnWithIfte

    @LearnWithIfte

    4 ай бұрын

    I have made a video fixing this issue. You can check it from here: kzread.info/dash/bejne/p5esmNmoZsfWaZs.html

  • @zayedh8089
    @zayedh80894 ай бұрын

    greate work ,could you do a curd of anything with role (admin and user )with spring angular and token i have some issues in that

  • @LearnWithIfte

    @LearnWithIfte

    4 ай бұрын

    Sure. I will make a tutorial on that soon.

  • @Kamilek96

    @Kamilek96

    4 ай бұрын

    @@LearnWithIfte Refresh tokens and external auth providers would be awesome too! :) Great tutorial

  • @LearnWithIfte

    @LearnWithIfte

    4 ай бұрын

    Thank you for your feedback! I'm glad you found the tutorial helpful. I'll definitely consider covering refresh tokens and external auth providers in future videos.

  • @abhishek_67
    @abhishek_674 ай бұрын

    In company also security services build like this or any difference is there?

  • @LearnWithIfte

    @LearnWithIfte

    4 ай бұрын

    It depends on the requirement. In this video, I have shown the fundamental thing. In the real world companies may require an extra level of security. If you can understand the fundamental level, then you will be able to do the advanced levels of work. But you need to study a lot.

  • @user-tr9eb3kr6j
    @user-tr9eb3kr6j2 ай бұрын

    It would be interesting to see how to host a spring project)

  • @LearnWithIfte

    @LearnWithIfte

    2 ай бұрын

    Thank you for your suggestion! I'll definitely consider making a video on hosting spring boot. Stay tuned for future content!

  • @MiguelContreras-qn2zg
    @MiguelContreras-qn2zgКүн бұрын

    Im having issues with cors not allowing my requests that are coming from my react front end, Im trying to send the POST login request we allowed and cors is blocking me saying "Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource." do you know what could be causing this issue?

  • @LearnWithIfte

    @LearnWithIfte

    22 сағат бұрын

    Hi, you can check this www.baeldung.com/spring-cors

  • @LearnWithIfte

    @LearnWithIfte

    22 сағат бұрын

    this is another excellent resource: spring.io/guides/gs/rest-service-cors

  • @enescagrbayraktutan6329
    @enescagrbayraktutan63294 ай бұрын

    Excellent explanation

  • @LearnWithIfte

    @LearnWithIfte

    4 ай бұрын

    Thank you for your kind words! I'm thrilled that my explanation resonated with you.

  • @enescagrbayraktutan6329

    @enescagrbayraktutan6329

    4 ай бұрын

    @@LearnWithIfte I would loved to see fullstack guide with react to fully cover spring security, like you did in Auth0. Keep up the good work man!

  • @prashupandey1304
    @prashupandey1304Ай бұрын

    Sir my auth header is coming null how to debug it

  • @anjakovacevic2996
    @anjakovacevic29962 ай бұрын

    Hello, could you make a video on how to connect this with Angular app on front?

  • @LearnWithIfte

    @LearnWithIfte

    2 ай бұрын

    Thank you for your suggestion! I'll definitely consider making a on that. Stay tuned for future content!

  • @dinhhuy9714
    @dinhhuy97142 ай бұрын

    hey, ur video has helped me a lot, but i got an eror 'ERROR: column "role" is of type roleenum but expression is of type character varying Hint: You will need to rewrite or cast the expression.' when i tried to insert user into database, pls help, i already altered the column role in database to enum. Tks a lot

  • @LearnWithIfte

    @LearnWithIfte

    2 ай бұрын

    Can you please share your code? You can share your github link. learnwithiftekhar@gmail.com

  • @user-nj5to9yz6p
    @user-nj5to9yz6p4 ай бұрын

    Thanks for the great video! I completely copied your project, a new user registers, a token is issued, but when I try to authorize the user on /demo or amine I get 403, by the way, the same in your previous example, the /login page opens, and on /user and /admin I get 403. Tell me what could be the problem? I’m creating a new project, the dependencies are the same, I copy your code completely, I don’t add anything, but I get 403. Thank you in advance!!!!

  • @LearnWithIfte

    @LearnWithIfte

    4 ай бұрын

    Can you please share your code?

  • @user-nj5to9yz6p

    @user-nj5to9yz6p

    4 ай бұрын

    Oh, I added the code from your repository and it worked! Thank you! Now I’m thinking about how to combine this with thymeleaf)))@@LearnWithIfte

  • @LearnWithIfte

    @LearnWithIfte

    4 ай бұрын

    With thymeleaf you do not need this jwt token. You can check this video kzread.info/dash/bejne/nIShzcV_msW3c7A.htmlsi=u-KrMMBnNBmdu2KD

  • @abdul-razaktwaha1287
    @abdul-razaktwaha12872 ай бұрын

    Sir, what theme are you using please?

  • @LearnWithIfte

    @LearnWithIfte

    2 ай бұрын

    Material UI theme

  • @uiyasser
    @uiyasser2 ай бұрын

    brother, thank you for the video. i did everything as you did from what i understand. using postman, login/registration works. but when i log in and generate a jwt token and use that token to login in i get 401 error. i also get 401 error on every page other than the login/register pages. ive been looking at the source code trying to find a difference but i cant.

  • @LearnWithIfte

    @LearnWithIfte

    2 ай бұрын

    Please double-check the return value of *isValid* method in *JwtService class.* There is a _ "!"_ symbol, you have may missed.

  • @uiyasser

    @uiyasser

    2 ай бұрын

    @@LearnWithIfte i have the "!" symbol, its in "!isTokenExpired" im not sure what else it could be

  • @LearnWithIfte

    @LearnWithIfte

    2 ай бұрын

    Please share your code. learnwithiftekhar@gmail.com

  • @uiyasser

    @uiyasser

    2 ай бұрын

    @@LearnWithIfte i just sent the email, the subject is "github source code of jwt". thank you brother this means a lot

  • @ndjouenkeudikaabelrudy9994
    @ndjouenkeudikaabelrudy99943 ай бұрын

    Hello, what if I want to add more than the username in the JWT payload ?

  • @LearnWithIfte

    @LearnWithIfte

    3 ай бұрын

    You need to some tweak. First inside jwt service class you need to create a method to generate other property. below is an example of the method: Map getMyClaimsMap() { Map extraClaims = new HashMap(); extraClaims.put("hello", "world"); return extraClaims; } then you need to update generateToken method as follows: public String generateToken(User user) { Map claims = getMyClaimsMap(); //get extra properties String token = Jwts .builder() .subject(user.getUsername()) .issuedAt(new Date(System.currentTimeMillis())) .expiration(new Date(System.currentTimeMillis() + 24*60*60*1000 )) .claims(claims) // set extra properties in token payload .signWith(getSigninKey()) .compact(); return token; } Hopefully It will help.

  • @subhashisbhowmik7
    @subhashisbhowmik73 күн бұрын

    Thanks a lot dada springSecurity by default puts UserDetails isAccountNonExpired, isAccNonLocked, isCredentialsNonExpired as true

  • @sreeganesh5219
    @sreeganesh52195 күн бұрын

    Why we are not using @Autowired instead of constructor injection

  • @LearnWithIfte

    @LearnWithIfte

    5 күн бұрын

    You can check this video to understand it: kzread.info/dash/bejne/mImnrbCjd7KaedY.htmlsi=eMrMs8vECrNY90eT

  • @rafaelalfonsocorredorgambi1893
    @rafaelalfonsocorredorgambi18933 ай бұрын

    Hello friend, I need help with the code, it allows me to register and login but when I access the endpoint it gives me a 200, however it does not return anything, but when the token is correct, it may be that it doesn't matter at all.

  • @LearnWithIfte

    @LearnWithIfte

    3 ай бұрын

    Please share your code. You can send me your GitHub link via email. You can find my email in my channel

  • @berkegurel6836
    @berkegurel68362 ай бұрын

    Great tutorial however after ı wrtie the config class ı get 403 for my any POST request include login and register to (yes i disabled csrf)

  • @LearnWithIfte

    @LearnWithIfte

    2 ай бұрын

    Please check if you are sending request with proper request body. Request is case sensitive. You can check the code in my GitHub. Link is in the description.

  • @berkegurel6836

    @berkegurel6836

    2 ай бұрын

    @@LearnWithIfte I found my issue(my 168 bits key does not enough for jwt. I found it when i debugging @EnableWebSecurity(debug = true)) thanks

  • @whiteboardDSA
    @whiteboardDSAАй бұрын

    why do we need to save JWT token into database?

  • @LearnWithIfte

    @LearnWithIfte

    Ай бұрын

    Please check this video. Here I have explained the reason. kzread.info/dash/bejne/gaSHt5KPl8nRfJc.html

  • @mausamrayamajhi5691
    @mausamrayamajhi56916 күн бұрын

    Can we get new video for writing test cases for this project?

  • @LearnWithIfte

    @LearnWithIfte

    6 күн бұрын

    Sure.

  • @snof7602
    @snof76024 ай бұрын

    Soooo cleaaaaaaan 🫡🔥

  • @LearnWithIfte

    @LearnWithIfte

    4 ай бұрын

    Thank you for noticing! I put a lot of effort into keeping everything clean and organized for you all.

  • @imadyasin238
    @imadyasin2383 ай бұрын

    Can we Login without adding the Jwt filter?

  • @LearnWithIfte

    @LearnWithIfte

    3 ай бұрын

    Without JWT filter the full application will become useless. This filter is responsible for filtering out unauthenticated user.

  • @imadyasin238

    @imadyasin238

    3 ай бұрын

    @@LearnWithIfte Thankyou . I know that. I just want to know is that possible?

  • @chandantalreja08
    @chandantalreja084 күн бұрын

    I have seen a lot of videos on JWT and this one again is a different everyone directly jump to the execution of JWD. No one explains how JWT works along with Oauth or standalone how JWT works. No one explains that.

  • @MohammadWaseel-pq5py
    @MohammadWaseel-pq5py3 ай бұрын

    but how can i create multiple roles from database

  • @LearnWithIfte

    @LearnWithIfte

    3 ай бұрын

    For that you need to do some curd operations. I wall try to make a video in future for this.

  • @pe3738
    @pe37383 ай бұрын

    I think that i love you.

  • @sujitkumar2196
    @sujitkumar2196Ай бұрын

    Awesome but the way you implemented is not correct, 1.First user registre then server will send a success response your registration is success now you can login. 2.Then user will login will crendetial now server will send a access token.

  • @ruzibayevich1693
    @ruzibayevich16934 ай бұрын

    can't we continue this project ? I would like to add some stuff that user could do after authorization

  • @LearnWithIfte

    @LearnWithIfte

    4 ай бұрын

    Sure. Just give some suggestions of what tasks you want to do. I will try to make a tutorial on that.

  • @ruzibayevich1693

    @ruzibayevich1693

    3 ай бұрын

    @@LearnWithIfte let's say just a simple project, a user could buy a book from a store which sales only books, I think we don't need to add the payment system and etc, just a user should authorize and buy a book

  • @ruzibayevich1693

    @ruzibayevich1693

    3 ай бұрын

    that would be great if you make a tutorial for that @learnwithiftekhar

  • @pedropierolopezmego1363
    @pedropierolopezmego13632 ай бұрын

    Hi good video, but have error 401Unauthorized; i clone your project and same error, can help me pls

  • @LearnWithIfte

    @LearnWithIfte

    2 ай бұрын

    Please, check the request body. Its case sensitive.

  • @pedropierolopezmego1363

    @pedropierolopezmego1363

    2 ай бұрын

    @@LearnWithIfte JSON parse error: Cannot construct instance of `com.helloIftekhar.springJwt.model.User` (although at least one Creator exists): no String-argument constructor/factory method to deserialize from String value ('firstName')] have that error

  • @LearnWithIfte

    @LearnWithIfte

    2 ай бұрын

    Are you getting this error from my github code?

  • @pedropierolopezmego1363

    @pedropierolopezmego1363

    2 ай бұрын

    ​ @LearnWithIftekhar Yes, I cloned it and got an error. i dont know how to fix it

  • @LearnWithIfte

    @LearnWithIfte

    2 ай бұрын

    Use this request for register user and let me know the result. { "firstName": "john", "lastName": "doe", "username": "john@gmail.com", "password": "john", "role": "USER" }

  • @gomezvillegasdaniel
    @gomezvillegasdaniel4 ай бұрын

    I think you are wrong returning 403 instead of 401 while authenticating with bad credentials... because: authentication is the process of checking if the user exists with valid credentials and it should return 401 in case of wrong credentials instead of 403, authorization is the process of checking if the user has the permissions (given by roles) to access certain resources, and it should return 403 in case that the user has no permissions...

  • @LearnWithIfte

    @LearnWithIfte

    4 ай бұрын

    Yes, you are right about the status code. I have already recorded a new video on It. I will release it soon. However I have already updated my github repo fixing this issue. You can check the fix there.

  • @LearnWithIfte

    @LearnWithIfte

    4 ай бұрын

    Hey, I have made another video where I have shown how to fix this issue. You can check it from here: kzread.info/dash/bejne/p5esmNmoZsfWaZs.html

  • @anshupanda2149
    @anshupanda21494 ай бұрын

    Unpopular question: Which theme sir ?

  • @LearnWithIfte

    @LearnWithIfte

    4 ай бұрын

    Material Oceanic

  • @Tamimahmed_9
    @Tamimahmed_99 күн бұрын

    My reaction as a python developer “🙂💔” Sir please make video on python please 🙏

  • @user-et7vb4ju6v
    @user-et7vb4ju6v3 ай бұрын

    Здесь не хватает русского комментария. Спасибо. Сейчас тяжело найти актуальную JWT.

  • @LearnWithIfte

    @LearnWithIfte

    2 ай бұрын

    Thank you for watching.

  • @eyadhantoly5796
    @eyadhantoly57962 ай бұрын

    1:05:21 Status: 403 Forbidden I did every thing right, why may this happen ?

  • @madhunt378

    @madhunt378

    2 ай бұрын

    same to me

  • @LearnWithIfte

    @LearnWithIfte

    2 ай бұрын

    please share your code via github. you can send mail to learnwithiftekhar@gmail.com

  • @tanushachekkapalli5251

    @tanushachekkapalli5251

    2 ай бұрын

    Same to me

  • @LearnWithIfte

    @LearnWithIfte

    2 ай бұрын

    @@tanushachekkapalli5251 please check the isValid method in the JwtService.java class. many people make mistakes while writing return statements of this method. You can follow the source code from the github

  • @enderutlu791

    @enderutlu791

    Ай бұрын

    Guys i solved my problem. It was on JwtAuthenticationFilter. In the line "if(authHeader == null || !authHeader.startsWith("Bearer "))" i forgot the "!" before the "authHeader.startsWith" function. This causes you to be able to login and register but not use any other endpoint.

  • @soufianch8481
    @soufianch84814 ай бұрын

  • @naumtinga
    @naumtingaАй бұрын

    login returning forbbiden 403

Келесі