MASTER JWT Authentication with Java Spring Boot 3

preview_player
Показать описание
Learn JWT Authentication with an example project for Spring Boot 3. JWT Authentication is the most popular way to implement authentication in your application, and probably one of the more popular questions from beginner to intermediate Spring Boot developers.

We'll go through some flow diagrams to demonstrate where JWT authentication fits into things, then we'll implement with some code - by the end of this, you'll be able to add most of the same objects into your own project with some confidence!

It's gonna be fun! ☕☕

🔗Grab My Other Products Available:

👋🏻Connect with me:

🔗Links & References:

===---=== Chapters ===---===
0:00:00 - Introduction
0:01:03 - Video Outline
0:01:58 - What is JWT?
0:04:02 - JWT Sign Up Flow
0:04:54 - JWT Sign In Flow
0:06:06 - JWT Request Resource Flow
0:09:28 - Opening the Project in IntelliJ
0:12:01 - Start up the Server
0:12:26 - Updating some Application.Properties
0:14:07 - The User Model
0:16:54 - The Role Model
0:18:02 - The User Repository
0:18:45 - PasswordConfig Bean
0:19:39 - Setting up the SecurityConfig
0:26:00 - The UserService
0:28:45 - The JwtAuthenticationFilter
0:36:14 - The JwtService
0:40:50 - Creating a new JWT secret key with Node
0:42:09 - AuthenticationService
0:45:07 - Setting up the DTO's
0:46:15 - Creating some Seed Data
0:47:31 - Looking at the AuthenticationController
0:48:48 - Creating a TestController
0:50:30 - Checking the Database for the Admin User
0:51:14 - Testing Endpoints and JWT with Postman
0:56:53 - Final look at the Database
0:57:08 - Wrapping Up

#springboot #docker #jwt
Рекомендации по теме
Комментарии
Автор

Hey great tutorial!
One tip: Please close the project windows in the left side or zoom out a bit, because it's hard to code along especially when you jump around and the code goes off the screen.

thenstyle
Автор

Awesome Content Please Keep making more videos.
Thumbs Way Way Way Up!

BashunMcGee
Автор

Some thoughts:
It was quite hard to understand the details of what you were doing . The overall picture was quite clear though. I realize this video is aimed at developers that have previous Spring Security knowledge, but even then I think a 2-3 minute summary of what you implemented would have been nice at the end.

Regarding the third party libraries for JWT you used, how come something like that isn't built in or available as a dependency by the Spring team? Also, are there alternatives you can use or are these the go-to for working with JWTs?

Not sure if this will be done in upcoming videos, but what are some next step(s) one could take to make this app more production ready?

I'd definitely prefer React over Angular!

Thanks for the video, good content! :)

jesper
Автор

I am already at the beginning but i feel i will love this video. Would you please give more content for Spring + React projects.

springify_boot
Автор

Do you have any video that just configuring Docker for any Java project, i appreciate that if you have one.

quochung
Автор

This is great tutorial, I would love to see consuming this JWT with ReactJs. Thanks!

mrcoder
Автор

One of the most asked questions for those new to Spring Boot, is "How do I setup JWT Authentication??" Hope this helps you out! Also leave a comment with a frontend framework to use for consuming this JWT token!

wazoowebbytes
Автор

Great tutorial, much appreciated. Would u please put a complete video where there is the spring boot security jwt and refresh tokens and a React frontend with protected routes where if a user registers and logs in there will only see what they are authorized to e.g ADMIN users and ORDINARY users. It will be a bit long but it will be worth it.

obertmudzingwa
Автор

Thank you very much, the tutorial is amazing! And the most important - it works!

ivanbutov
Автор

please make a video on how to implement refresh token

lemueldesousa
Автор

Thanks for this vidéo, i have a question, for example, I have a post table which contains createdby, when creating a new post how can I set createdby by the logged in user as default? thank you for your help

bdiakhaby
Автор

so everything is fine but how can handle spring security exceptions in globally? for example JwtExpiredException, AuthenticationException and so on and how we can pass properly custom message to the client???

elkhanismayilov
Автор

Hi,

Thanks for that nice video. It really helps to me. I want to create my own exception handling class for invalid JWT. I just want to return something like that:
{
"status" : "error",
"message" : "Invalid JWT"
}

with 401 Unauthorized status code instead of that:
{
"timestamp": "2023-08-20T11:37:29.192+00:00",
"status": 401,
"error": "Unauthorized",
"message": "Full authentication is required to access this resource",
"path": "myPath"
}


How can I handle this exception? A video or comment showing implementation for that would be great! I am really stuckj in this problem and I didn't find the right way.

akifhasdemir
Автор

do you can combine springboot security jwt with reactjs, thanks sir

leat
Автор

hey great content, why are we are throwing up the jwt token after signup? if we are using the token provided by login, or what am i missing here?

HappyTest-rrjq
Автор

did you add git ? if you added please send me your git link?

HusanboyJorayev-nd
Автор

Great video! I have one question. How do I secure certain endpoints to specific users? For instance i want @GetMapping api/orders/{customerId} to only be available to customer with customerId?

adrianpuscuta
Автор

I followed your instructions very detailed. I'm happy but I'm getting the last error when checking the database for the admin user. This is my error log:

Error executing DDL "create table users (id bigint not null auto_increment, created_at datetime(6), email varchar(255), first_name varchar(255), last_name varchar(255), password varchar(255), role enum ('ROLE_ADMIN', 'ROLE_USER'), updated_at datetime(6), primary key (id)) engine=InnoDB" via JDBC [No database selected]

I am using a Macbook pro M1 laptop, I don't know if there is any difference if you use a windows computer? Can you help me explain why I followed it but I didn't get the same end result as you?

I intentionally downloaded your source code and then tried it but I still got that error.

everydaydesignui
Автор

the ONLY tutorial on youtube that actually f WORKS from start to end. the ONLY ONE. i ve waisted hours and hours on other tutorial on spring security and jwt tokens, none of them works.

alex
Автор

Hi i am getting Authorization header null error at time of sign in . But we have to generate the token at a time of sign in.

viraldangar