Spring Security JWT: How to secure your Spring Boot REST APIs with JSON Web Tokens

  Рет қаралды 130,257

Dan Vega

Dan Vega

Күн бұрын

Пікірлер: 285
@ParnianAndIlian
@ParnianAndIlian 2 жыл бұрын
Hi Dan, This is the tutorial that was missing in 2022. Thanks a lot. I was struggling with those outdated tutorials and dependencies to make a working solution. this saved me lots of time. Looking forward to your next videos.
@Scorpion2321-o9o
@Scorpion2321-o9o Жыл бұрын
Same, Docs mentioned some stuff that are new but honestly Spring Boot Docs is not for Beginner.
@rajmohanparayil
@rajmohanparayil 7 ай бұрын
Wow. Learned a lot of very relevant security implementation in a very smooth and clean fashion and in such a short time.
@DanVega
@DanVega 7 ай бұрын
Glad you liked it!
@voiceofeverything
@voiceofeverything Жыл бұрын
Great video. This is like the only one guide about this topic that is quite easy to follow and does not break your spirit (I have tried to follow like 2 different videos just to realize half way into 3 hour videos that implementation was changed/got deprecated and I wasted my time).
@kaatlev
@kaatlev 2 жыл бұрын
These videos are so concise and easy to follow, appreciate you.
@DanVega
@DanVega 2 жыл бұрын
That makes me so happy. Thank you ☺️
@kozi-corner
@kozi-corner 2 жыл бұрын
Thank you so much..I was just working on a project and had a lot of difficulties understanding JWT, I opened youtube and I found your video. How lucky I am!
@DanVega
@DanVega 2 жыл бұрын
Thank you Abdelhamid. I hope this clears it up for you.
@brethagen7776
@brethagen7776 Жыл бұрын
Straight to the point, no fluff. Looks looks like a bare-minimum implementation.
@bobgner
@bobgner 2 жыл бұрын
Thank you for making this tutorial. As you mentioned in the beginning there are so many more complicated ways of doing out there because the are not using what is built in to Spring Security. I unfortunately had used one of those more complicated ways so now I'm going to use what I learned in your tutorial to simplify my project code!
@DanVega
@DanVega 2 жыл бұрын
Thank you Bob. Glad I could help out.
@kasimgul
@kasimgul 2 жыл бұрын
Thank you for this, Dan. I would love to see a follow up video for implementing "Refresh Token" on top of this :) I know people will love it.
@DanVega
@DanVega 2 жыл бұрын
Thank you for the suggestion, it's already on the backlog. github.com/danvega/office-hours/discussions/27
@AleksandarT10
@AleksandarT10 2 жыл бұрын
Great video! Really helpful to get people started with latest Spring Security stuff and JWT! Few questions/comments though: 1. It would be good if you can extend the github repo and add a branch which shows the symmetric key approach - i guess it would be easy for the Decoder as u mentioned, but would like to see how to change the Encoder 2. Maybe to make it more realistic instead of HttpBasic - it would be good to have a UserNamePassword Authentication where the user calls an endpoint with username/password as body and the token generation happens based on that 3. Building on top of 2), it would be great if this gets connected to a database where hashing + salting is used as this can be used as a starter for real projects 4. Having roles in the example/video would be great Looking forward to your next video Dan!
@DanVega
@DanVega 2 жыл бұрын
Great suggestions. Thank you Aleksander
@lukamaletic9557
@lukamaletic9557 Жыл бұрын
Is there any tutorial that would build on top of this I need the DB connection for users...
@NARESHBHADKE
@NARESHBHADKE 9 ай бұрын
@@lukamaletic9557 You could inject UserDetailsService in SecurityConfig rather than InMemoryUserDetails @Bean public UserDetailsService userDetailsService() { return username -> userRepository .findByUsername(username) .orElseThrow(() -> new UsernameNotFoundException("user not found")); }
@GiftNestah
@GiftNestah 2 ай бұрын
Just what I needed after struggling with an issue whereby a single user's token expiry invalidates all other users' valid tokens leading to error 403 even for authenticated users. Thanks a lot for this 💯💯
@SchefenBaba
@SchefenBaba 9 ай бұрын
Thanks a lot for this tutorial. I have been stuck in other tutorials for hours.
@luisferdev
@luisferdev Жыл бұрын
thank you Dan, this video help me a lot to understand how to generate JWT in Spring. the only one site where I found the explanation with the new version of spring security and works. regards from Colombia
@DanVega
@DanVega Жыл бұрын
Thank you! I'm glad my videos are helping.
@fabricio.entringer
@fabricio.entringer 2 жыл бұрын
Hello @Dan, it's amazing! Great video. Please keep producing videos regarding Spring Security, I think it's a black hole in the Spring modules. A lot of specific concepts and it deserves good videos with good explanations like yours. Congratulation and thanks for sharing the content.
@Learn_with_cosmos
@Learn_with_cosmos Жыл бұрын
I am a nodejs and Golang API. I found this tutorial very help for my current work using Spring-boot. One thing about Spring-boot is that, when you use Spring-Boot with higher version some errors like this shows up: This error occurs in the NimbusJwtDecoder.validateJwt method of the org.springframework.security.oauth2.jwt.NimbusJwtDecoder class. The NimbusJwtDecoder class is used to decode JSON Web Tokens (JWTs) and is part of the Spring Security OAuth 2.0 framework.
@franciskinyuru3459
@franciskinyuru3459 Жыл бұрын
Great video my start to spring security wouldn't have been great without this. A big salute.
@petrophilip2279
@petrophilip2279 3 ай бұрын
This is a great tutorial. You have a way of explaining complex topics in simple terms. I have subbed to your channel.
@mrkostya008
@mrkostya008 Жыл бұрын
finally, an informative tutorial that ACTUALLY uses BUILTIN jwt tools, and not some filters and JwtUtility classes to secure an app
@drbulltrader9107
@drbulltrader9107 Жыл бұрын
I really appreciated this video. Wishes your channel get bigger n bigger.
@SD-gw5vm
@SD-gw5vm Жыл бұрын
Thanks for sharing this. I used your example to solve a problem I was working on and it worked. You are a lifesaver
@intellopitt
@intellopitt 2 жыл бұрын
Amazing, how simple it is when explained by experts. Thanks for the great content. Well explained, with the right level of details to understand without getting overwhelmed. I still have to review the blog post if I am not missing any details. Looking forward for the next video :)
@midewestmond9442
@midewestmond9442 2 жыл бұрын
Nice video you just earn a subscriber I actually love the fact you don't define another class just to write another method like other youtubers do
@DanVega
@DanVega 2 жыл бұрын
Thanks for the sub!
@marekj3759
@marekj3759 Жыл бұрын
Very good video, if anybody haven't mentioned yet, it would be good to replace inMemory user with UserDetailsService on data base. Additionally securing rest api with roles. Video would be a bit longer than 1hours, but woud cover topic from A to Z
@alexgutjahr
@alexgutjahr 2 жыл бұрын
I'm guilty of rolling up my custom solution, pulling in a third party library. Thanks for this video, Dan! Gotta refactor a bit!
@DanVega
@DanVega 2 жыл бұрын
Thanks Alex. Hope the refactor goes smooth.
@IvanRandomDude
@IvanRandomDude 2 жыл бұрын
For some reason 99% of tutorials and guides on the internet use that approach instead of resource server.
@rafijlouis2432
@rafijlouis2432 2 ай бұрын
Hi Dan, I love the way you explain and it’s much better than a lot of tutorials i have gone through. I have searched in udemy for a springboot course by you but i see it’s outdated. It would be wonderful if you could create a new course or atleast a series of videos of spring topics. Thank you.
@Justsomeguy492
@Justsomeguy492 Жыл бұрын
finally up to date spring security tutorial :) very good explanation
@arlekino65
@arlekino65 Жыл бұрын
Thank you Dan. I meant A LOT! Would you consider to create a video for those like me with a title "How to read Spring documentation and connect things together"? Lol. Thanks again!
@x2TruNation
@x2TruNation Жыл бұрын
Hey Dan, New question, obviously us as viewers are following along and just basically copying the code that you write down - but you seem to know exactly what we need and why we need it. Are there any resources you can point me to that could potentially help me understand the architecture of spring security in more detail but also how you learned this to a point where you just know what you need to use? Bit of a loaded question, but i’m keen to learn as much as possible. Right now all it feels like is that i’m copying code from you without truly understanding why we’re doing certain things. Cheers
@aayush481
@aayush481 2 жыл бұрын
Hi Dan, can you also please talk about how spring mvc works internally, like dispatcher servlet, how by default exceptions are handled in rest apis etc.
@robertinnoelson6378
@robertinnoelson6378 5 ай бұрын
Awesome Dan! Thanks for the rich tutorial
@sharifyy
@sharifyy 8 ай бұрын
I really enjoyed this video. Thank you for providing such great content.
@neerajagrawal3211
@neerajagrawal3211 6 ай бұрын
Great information. I think a simple video will also be helpful which explains how to protect API using Okta or Keycloak since in most situations you don’t write authorization server yourself.
@kyriakosmandalas2121
@kyriakosmandalas2121 2 жыл бұрын
Great tutorial and topic. Really clears things out. Would be great to show next how to update JWT to include user's roles and permissions. And of course looking forward for Spring Authorization server!
@DanVega
@DanVega 2 жыл бұрын
I actually set the authority and I believe in the repo there is an example of checking for it at the method level. If there isn’t let me know (I’m away from my computer at the moment)
@toan1nguyen674
@toan1nguyen674 Жыл бұрын
Thanks for asymmetric rsakeys knowledge you've shared.
@jirivrba3800
@jirivrba3800 2 жыл бұрын
Thanks Dan, really educative content that's very well and clearly presented. Exactly what I was looking for!
@DanVega
@DanVega 2 жыл бұрын
Thank you, glad I could help out.
@alx1024
@alx1024 Жыл бұрын
Hi! Great video, like all your videos! Especially now that Spring Security 6 is mixed in with older tutorials on the web this is very helpful. A suggestion: this is now already deprecated: ".oauth2ResourceServer(OAuth2ResourceServerConfigurer::jwt)" and has to be replaced with ".oauth2ResourceServer((oauth2) -> oauth2.jwt(Customizer.withDefaults())". Also a question, how do you get this snippet-functionality at 30:00?
@rohitbhandari1873
@rohitbhandari1873 Жыл бұрын
can't fix it even using Customizer.withDefaults();
@monjurmorshed2854
@monjurmorshed2854 2 жыл бұрын
U have a nice way to explain, great work!!!
@DanVega
@DanVega 2 жыл бұрын
I appreciate that Monjur. I make videos that I would enjoy watching and I’m glad others are learning from them as well.
@EduardoSilva-us1jp
@EduardoSilva-us1jp 2 жыл бұрын
Amazing. I used to secure my smalls projects implementing jwt encoder/decoder with the help of libraries like jjwt directly, as well as overriding filter methods from classes/interfaces such as UsernamePasswordAuthenticationFilter, OncePerRequestFilter. But this way you showed us has simplified it a lot. One more subscriber!
@DanVega
@DanVega 2 жыл бұрын
Fantastic! Glad I could help out.
@mvlad7402
@mvlad7402 Жыл бұрын
Excellent video! Need to test spring security with Ping Federate.
@jy241
@jy241 Ай бұрын
Thanks for the great video!! It helped me a lot!!!!
@arnaudpoutieu1331
@arnaudpoutieu1331 Жыл бұрын
Many thanks, Dan. Your content is quite valuable for someone like me harnessing input to get better at building Enterprise grade applications. Merci beaucoup!!!
@DanVega
@DanVega Жыл бұрын
I appreciate the kind words Arnaud.
@rajansonvane488
@rajansonvane488 2 жыл бұрын
Wonderful. Very helpful. Thanks for sharing!!
@DanVega
@DanVega 2 жыл бұрын
Glad it was helpful!
@NikolaosZer
@NikolaosZer 2 жыл бұрын
Thank you very much! Greetings from Greece!!!
@DanVega
@DanVega 2 жыл бұрын
You are welcome!
@alexanderkazeev3729
@alexanderkazeev3729 Жыл бұрын
Thanks for a great tutorial. The article is very useful and helpful.
@benizraadacudao3020
@benizraadacudao3020 2 жыл бұрын
Thanks for this Dan.
@DanVega
@DanVega 2 жыл бұрын
You’re welcome Ben.
@WilliamEk-m4v
@WilliamEk-m4v Жыл бұрын
First, thank you for such a comprehensive explanation of the new spring security. I'm going to take minor issue with it because, as with just about every tutorial I've seen for spring boot security, the user logon and Jwt generation is in the same sever as the Jwt consumer for endpoint security. This would never happen in the wild and creates confusion as to which SecurityConfig configurations are needed for each.
@fjspitz
@fjspitz Жыл бұрын
Nice tutorial Dan! Thanks a lot.
@temptrue3322
@temptrue3322 2 ай бұрын
top quality content. very infomative
@sajisanjoris2759
@sajisanjoris2759 Жыл бұрын
Thank you Dan! Great work!
@sakthinivas1840
@sakthinivas1840 Жыл бұрын
Hi Dan, really a good video. One functionality which could be added is adding refresh token feature, thanks
@szalaytamas3184
@szalaytamas3184 Жыл бұрын
your outro music is so good
@paulo__vieira
@paulo__vieira Жыл бұрын
For me as a complete beginner it was so easy to follow. Thanks for this tutorial, it was really helpful.
@DanVega
@DanVega Жыл бұрын
You're very welcome!
@AntonioCabralNumberOne
@AntonioCabralNumberOne 6 ай бұрын
Hi Dan. Since we're already on Spring Boot 3.2+ would you mind an update video on this matter? Keep up the good work!
@behzadfazelasl9581
@behzadfazelasl9581 Жыл бұрын
Thanks Dan. it was crystal clear
@rahanimhand6895
@rahanimhand6895 Жыл бұрын
Amazing !!!! Great video, Thanks 👌
@НикитаПосмак
@НикитаПосмак 2 жыл бұрын
Thank you Dan, it's a greate tutorial for beginners. Can you please make a guide about refreshing jwt please.
@DanVega
@DanVega 2 жыл бұрын
Noted! I have this suggestion here github.com/danvega/office-hours/discussions/27
@bejobarokah3485
@bejobarokah3485 2 жыл бұрын
Thank you for the tutorial
@DanVega
@DanVega 2 жыл бұрын
You’re welcome 😊
@tipswithnna6670
@tipswithnna6670 Жыл бұрын
Thanks for sharing about JWT
@rizkysiregar
@rizkysiregar 6 ай бұрын
Thanks for sharing dan !
@svalyavasvalyava9867
@svalyavasvalyava9867 Жыл бұрын
wonderful tutorial, thank toy very much 😊
@bartomiejdziadosz8616
@bartomiejdziadosz8616 2 жыл бұрын
That was great! What about video about OAuth2 with Auth/Resource/Client?
@shariqshaikh5715
@shariqshaikh5715 Жыл бұрын
Thank you so much for such a great Video Dan, One suggestion I would give is Please try to make video a little more short I know you are videos are so helpful but they can be a little more concise
@DanVega
@DanVega Жыл бұрын
Thanks for the tip!
@mdziakhan5950
@mdziakhan5950 Жыл бұрын
Great Explanation
@lts8683
@lts8683 2 жыл бұрын
Thanks you. Can please explain also keycloak with spring.
@pavanramagouni6709
@pavanramagouni6709 Жыл бұрын
Thank you Dan. nicely explained and Really helpful.
@DanVega
@DanVega Жыл бұрын
Glad you enjoyed it!
@mohamedibrahim1836
@mohamedibrahim1836 Жыл бұрын
Also to use the authorization as a micro service and export it, import it in multiple application across the company portfolio for a aligned one platform!
@m_jdm357
@m_jdm357 Жыл бұрын
Everything works great!
@edwardm4348
@edwardm4348 Жыл бұрын
Great video! You make it so easy to grasp the concept. A quick question. How would you secure the APIs using JWT if the application is using (username & password) in some cases and also biometrics authentication in other cases.
@samahmahdi5511
@samahmahdi5511 6 ай бұрын
Thanks a lot, can you create new video for spring boot 3
@menabebawy390
@menabebawy390 Жыл бұрын
I super like your video, I have learned a lot form it
@mehlulinokwara3841
@mehlulinokwara3841 Жыл бұрын
Very good take there.
@gamires
@gamires 7 ай бұрын
Excellent! Thank you.
@starterdev
@starterdev Жыл бұрын
Thanks for the video ❤
@dekeyserwilly
@dekeyserwilly 2 жыл бұрын
Thanks, very nice explaind.
@DanVega
@DanVega 2 жыл бұрын
Thank you!
@davidaskatra4140
@davidaskatra4140 Жыл бұрын
You are great man
@DanVega
@DanVega Жыл бұрын
Thank you, David!
@jeanaimeravomanana9545
@jeanaimeravomanana9545 Жыл бұрын
Great content, really helpful thank you
@fahrican9719
@fahrican9719 Жыл бұрын
great tutorial thanks!
@alibaba40thvs
@alibaba40thvs Жыл бұрын
Thanks a lot Dan!
@alibaba40thvs
@alibaba40thvs 5 ай бұрын
Guys take a look at its RFC they have a nice diagrammatic brief of these terms such as Resource Owner, Authorization Server, Resource Server, and Client
@rbelatamas
@rbelatamas Жыл бұрын
thank you so much ❤
@TheGuroguro12
@TheGuroguro12 11 ай бұрын
thank you very much !!! this is bread and butter even honey. if anybody wondering how to configure http basic to be used only for /token and all other endpoints with bearer check Den Vega -> how to create multiple spring security multiple configuration
@DanVega
@DanVega 11 ай бұрын
You are welcome!
@SigmaLearningCenter
@SigmaLearningCenter Жыл бұрын
Amazing, thanks a lot!
@maxjustmax521
@maxjustmax521 2 жыл бұрын
amazing as usual !
@DanVega
@DanVega 2 жыл бұрын
Thank you my friend 🙏
@andytael
@andytael 2 жыл бұрын
Fantastic content! A couple of suggestions request is to extend this video (or create a new one) where you actually secure a couple of REST endpoints using JWTs. Perhaps use the Spring Cloud Config Server to store the keys and the username and password or even better the Hashicorp Vault?
@DanVega
@DanVega 2 жыл бұрын
Thank you for the suggestion. I have added it to my content suggestion list. github.com/danvega/office-hours/discussions/30
@roman_mf
@roman_mf Жыл бұрын
Seconded Spring Cloud Config Server!
@youssouphafaye1710
@youssouphafaye1710 2 жыл бұрын
hello great video btw can you do a video on opaque token that are stock in database
@samirmezhoud1851
@samirmezhoud1851 2 жыл бұрын
Thank you Dan! It is a great video. I wood like if you can provide a video showing how to consume these API from an other Spring boot Web application using Feign client how with JWT (aut he ti cation for the web app is throw the same api )
@DanVega
@DanVega 2 жыл бұрын
Thank you for the suggestion. I have added it to my content idea list github.com/danvega/office-hours/discussions/29
@samirmezhoud1851
@samirmezhoud1851 2 жыл бұрын
@@DanVega thank you
@dodgechallenger5606
@dodgechallenger5606 Жыл бұрын
Perfect video. Thank you, Dan! Like+Sub
@marouaniAymen
@marouaniAymen Жыл бұрын
Thanks for this video, it is like a revelation for me. But I think it would be better if we used HTTPS instead of HTTP for our endpoint URLs because of the BASIC type login.
@techystuffs371
@techystuffs371 Жыл бұрын
Awesome tutorial as always. I have quick one... When using assymetric encryption do we use the private key to encrypt the data or the public key? With the little knowledge I have on encryption, I'm pretty sure we use the public key for encryption and the private key for decryption.
@EazzyWizzi
@EazzyWizzi Жыл бұрын
Great Video, keep up the good work
@DanVega
@DanVega Жыл бұрын
Thanks, will do!
@illyam689
@illyam689 Жыл бұрын
awesome video! subscribed!
@DanVega
@DanVega Жыл бұрын
Thanks for the sub!
@DamLee88
@DamLee88 Жыл бұрын
a video on keycloak and SSo auth? thank you! good video
@DanVega
@DanVega Жыл бұрын
Thank you for the suggestions.
@SD-gw5vm
@SD-gw5vm Жыл бұрын
Are you able to create another video using the other method you mentioned. Where we do not manually create the keys?
@chanchhaya
@chanchhaya Жыл бұрын
Thank you teacher
@gerogsg2698
@gerogsg2698 Жыл бұрын
Very good your video!!! I have a question for you: since you said that this is the beginning with jwt and not the goal, what other functions can I do with jwt?
@amirhosseinbayat9657
@amirhosseinbayat9657 5 ай бұрын
Hey Dan, it's amazing, but is there any mechanism in order the user logged out of the system, how we can invalidate the user token?
@HerrKaleu777
@HerrKaleu777 Жыл бұрын
Great video! Thanks a lot! I just have one question though: In Postman, you use bearer token as authorization type. The dropdown also offers "JWT token". Why did you not choose this option and took "bearer token" instead?
@DanVega
@DanVega Жыл бұрын
I just don't think I realized there was a JWT option. At the end of the day it should be sent via bearer token so that option might just be a shortcut to do the same thing.
@HerrKaleu777
@HerrKaleu777 Жыл бұрын
@@DanVega Thanks for the quick response and for clearing things up!
@rajibahmed-i2x
@rajibahmed-i2x Жыл бұрын
First off awesome video Dan. I have seen no code/logic on the resource server side to validate token. Is this optional on resource server end or its a must.
@lilinh9631
@lilinh9631 9 ай бұрын
Hey! Great video! But how did you do to autogenerate code just by typing jwt? Thanks a lot!
@mattymedia3624
@mattymedia3624 Жыл бұрын
hello dan, thanks for such a good content, this topic is complex but thanks to you I have been able to understand it better. I only have a small question, why is it necessary to disable csrf?
@MrMCchanel
@MrMCchanel 2 жыл бұрын
Great video! Is there a way to user roles with the currente JWT configuration in this video?
@DanVega
@DanVega 2 жыл бұрын
You can set the roles as part of the claim. I do have something on the backlog to create some content around this. If you want to add more to this you can. github.com/danvega/office-hours/discussions/8
@josemanueldopereiro5957
@josemanueldopereiro5957 2 жыл бұрын
Hello Dan, do you always need to encrypt ? If you care only on integrity and not on confidentiality of the token wouldn't be enough with signing the token (JWS vs JWE) ? Thanks!
@DanVega
@DanVega 2 жыл бұрын
A JWT would just be a base64 encoded string without the encryption. You absolutely need to protect it.
They Chose Kindness Over Abuse in Their Team #shorts
00:20
I migliori trucchetti di Fabiosa
Рет қаралды 3,2 МЛН
風船をキャッチしろ!🎈 Balloon catch Challenges
00:57
はじめしゃちょー(hajime)
Рет қаралды 20 МЛН
🕊️Valera🕊️
00:34
DO$HIK
Рет қаралды 19 МЛН
Elza love to eat chiken🍗⚡ #dog #pets
00:17
ElzaDog
Рет қаралды 18 МЛН
Spring boot 3.0 - Secure your API with JWT Token [2023]
2:01:46
Bouali Ali
Рет қаралды 156 М.
What is JWT authentication ?  Learn jwt authentication with spring security ?
10:59
Spring Boot + Spring Security + JWT from scratch - Java Brains
39:29
Implementing JWT (JSON Web Tokens) with Spring Security in Springboot App
36:25
What is JWT? JSON Web Tokens Explained (Java Brains)
14:53
Java Brains
Рет қаралды 1 МЛН
They Chose Kindness Over Abuse in Their Team #shorts
00:20
I migliori trucchetti di Fabiosa
Рет қаралды 3,2 МЛН