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

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

80.926 Lượt nghe
Easy JWT Authentication & Authorization with Spring Security | Step-by-Step Guide
Master JWT authentication and authorization in your Spring Boot application with this detailed, easy-to-follow tutorial, covering everything from setup to best practices. In this video, we'll dive deep into implementing JWT (JSON Web Token) based authentication and authorization in a Spring Boot application. You'll learn how to set up Spring Security for JWT integration, create and validate JWTs for secure user authentication, and implement authorization mechanisms based on user roles. We'll also cover best practices and potential pitfalls to watch out for, ensuring you have a solid understanding of JWT in a Spring Boot context. Whether you're just starting out or are an experienced developer, this tutorial breaks down complex concepts into manageable, step-by-step instructions. By the end of this video, you'll be able to secure your own Spring Boot applications using JWT, enhancing both security and user experience. Topics Covered: ✅ Setting up Spring Security for JWT integration ✅ Creating and validating JWTs ✅ Implementing user authentication and authorization ✅ Managing user roles and permissions ✅ Best practices for JWT implementation ✅ Common pitfalls and how to avoid them ✅ Don't forget to like, share, and subscribe for more tutorials! Other parts of this video series: ▶️ JWT Logout: https://youtu.be/OpSU0VgfkL4 ▶️ Refresh Token: https://youtu.be/nvwKwsJg89E 🎯🎯 *Subscribe to my Newsletter:* https://learnwithiftekhar.substack.com/ ✅ For branding and Business inquiries ► [email protected] ► Join Discord: https://discord.gg/JZmFvSxw 🎉 *Get IntelliJ Idea 100% for 3 Months:* https://www.jetbrains.com/store/redeem/ 👉 *Use Promo Code:* LearnWithIfte 👉 *Master programming by recreating your favorite technologies*: https://app.codecrafters.io/join?via=learnwithiftekhar 💻 *Running Windows on Mac? Get Parallels Desktop with a 20% discount!* 👉 *Use code PARALLELS20 and grab it here:* https://parallels.sjv.io/bOVD3M 📘 Resources Mentioned: 🧑‍💻 Source Code: https://github.com/hello-iftekhar/springJwt ⛔ Background sound: https://share.epidemicsound.com/ia954g 🙊 Here are the tools and resources I use in my videos: ► Recommended Books Clean Code * https://amzn.to/3PS6Cjo HTTP: The Definitive Guide * https://amzn.to/4jthbHb Clean Architecture * https://amzn.to/4avYVZK ► Computer and Monitor New Apple MacBook Pro * https://amzn.to/4atFbWJ Dell 27 INCH Ultrasharp U2719D Monitor * https://amzn.to/4avcsAA Double Arm Stand Desk Mount * https://amzn.to/42umpMP USB C Hub Multiport Adapter * https://amzn.to/4hxlaAz ► Gear Microphone * https://amzn.to/4hbqw4U 🌐 Secure your connection with NordVPN: https://nordvpn.sjv.io/o4zYan IDE I use for coding * IntelliJ Idea Ultimate * VsCode * Sublime 🤚 In case you want to contact me: ❌ My LinkedIn profile: https://www.linkedin.com/in/hossain-md-iftekhar/ ❌ Github: https://github.com/learnwithiftekhar *Note:* Some of the links in this description are affiliate links, and I may earn a small commission if you make a purchase through them. Thank you for your support. 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