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

  Рет қаралды 126,852

Dan Vega

Dan Vega

Күн бұрын

In this tutorial, you are going to learn how to secure your Spring Boot REST APIs using JSON Web Tokens (JWT) with Spring Security.
🔗Resources & Links mentioned in this video:
Blog Post: www.danvega.de...
WebSercurityConfigurerAdapter: • Spring Security withou...
👋🏻Connect with me:
Website: www.danvega.dev
Twitter: / therealdanvega
Github: github.com/dan...
LinkedIn: / danvega
Newsletter: www.danvega/de...
SUBSCRIBE TO MY CHANNEL: bit.ly/2re4GH0 ❤️

Пікірлер: 285
@ParnianAndIlian
@ParnianAndIlian Жыл бұрын
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.
@kaatlev
@kaatlev 2 жыл бұрын
These videos are so concise and easy to follow, appreciate you.
@DanVega
@DanVega 2 жыл бұрын
That makes me so happy. Thank you ☺️
@petrophilip2279
@petrophilip2279 2 ай бұрын
This is a great tutorial. You have a way of explaining complex topics in simple terms. I have subbed to your channel.
@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).
@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.
@rajmohanparayil
@rajmohanparayil 5 ай бұрын
Wow. Learned a lot of very relevant security implementation in a very smooth and clean fashion and in such a short time.
@DanVega
@DanVega 5 ай бұрын
Glad you liked it!
@jy241
@jy241 8 күн бұрын
Thanks for the great video!! It helped me a lot!!!!
@SchefenBaba
@SchefenBaba 8 ай бұрын
Thanks a lot for this tutorial. I have been stuck in other tutorials for hours.
@brethagen7776
@brethagen7776 Жыл бұрын
Straight to the point, no fluff. Looks looks like a bare-minimum implementation.
@rafijlouis2432
@rafijlouis2432 20 күн бұрын
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.
@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.
@kasimgul
@kasimgul Жыл бұрын
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 Жыл бұрын
Thank you for the suggestion, it's already on the backlog. github.com/danvega/office-hours/discussions/27
@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.
@GiftNestah
@GiftNestah Ай бұрын
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 💯💯
@drbulltrader9107
@drbulltrader9107 Жыл бұрын
I really appreciated this video. Wishes your channel get bigger n bigger.
@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.
@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.
@rbelatamas
@rbelatamas Жыл бұрын
thank you so much ❤
@robertinnoelson6378
@robertinnoelson6378 4 ай бұрын
Awesome Dan! Thanks for the rich tutorial
@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 7 ай бұрын
@@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")); }
@franciskinyuru3459
@franciskinyuru3459 Жыл бұрын
Great video my start to spring security wouldn't have been great without this. A big salute.
@temptrue3322
@temptrue3322 Ай бұрын
top quality content. very infomative
@benizraadacudao3020
@benizraadacudao3020 2 жыл бұрын
Thanks for this Dan.
@DanVega
@DanVega 2 жыл бұрын
You’re welcome Ben.
@Justsomeguy492
@Justsomeguy492 Жыл бұрын
finally up to date spring security tutorial :) very good explanation
@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.
@rajansonvane488
@rajansonvane488 Жыл бұрын
Wonderful. Very helpful. Thanks for sharing!!
@DanVega
@DanVega Жыл бұрын
Glad it was helpful!
@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
@sharifyy
@sharifyy 7 ай бұрын
I really enjoyed this video. Thank you for providing such great content.
@leonzer8257
@leonzer8257 2 жыл бұрын
Thank you very much! Greetings from Greece!!!
@DanVega
@DanVega Жыл бұрын
You are welcome!
@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 Жыл бұрын
Thanks for the sub!
@bejobarokah3485
@bejobarokah3485 Жыл бұрын
Thank you for the tutorial
@DanVega
@DanVega Жыл бұрын
You’re welcome 😊
@rizkysiregar
@rizkysiregar 4 ай бұрын
Thanks for sharing dan !
@sajisanjoris2759
@sajisanjoris2759 Жыл бұрын
Thank you Dan! Great work!
@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.
@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.
@toan1nguyen674
@toan1nguyen674 11 ай бұрын
Thanks for asymmetric rsakeys knowledge you've shared.
@alexanderkazeev3729
@alexanderkazeev3729 Жыл бұрын
Thanks for a great tutorial. The article is very useful and helpful.
@fjspitz
@fjspitz Жыл бұрын
Nice tutorial Dan! Thanks a lot.
@rahanimhand6895
@rahanimhand6895 Жыл бұрын
Amazing !!!! Great video, Thanks 👌
@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)
@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
@behzadfazelasl9581
@behzadfazelasl9581 Жыл бұрын
Thanks Dan. it was crystal clear
@EduardoSilva-us1jp
@EduardoSilva-us1jp Жыл бұрын
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 Жыл бұрын
Fantastic! Glad I could help out.
@mrkostya008
@mrkostya008 Жыл бұрын
finally, an informative tutorial that ACTUALLY uses BUILTIN jwt tools, and not some filters and JwtUtility classes to secure an app
@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.
@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 Жыл бұрын
For some reason 99% of tutorials and guides on the internet use that approach instead of resource server.
@tipswithnna6670
@tipswithnna6670 Жыл бұрын
Thanks for sharing about JWT
@mdziakhan5950
@mdziakhan5950 11 ай бұрын
Great Explanation
@samahmahdi5511
@samahmahdi5511 4 ай бұрын
Thanks a lot, can you create new video for spring boot 3
@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!
@neerajagrawal3211
@neerajagrawal3211 5 ай бұрын
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.
@mvlad7402
@mvlad7402 Жыл бұрын
Excellent video! Need to test spring security with Ping Federate.
@gamires
@gamires 6 ай бұрын
Excellent! Thank you.
@svalyavasvalyava9867
@svalyavasvalyava9867 Жыл бұрын
wonderful tutorial, thank toy very much 😊
@dekeyserwilly
@dekeyserwilly 2 жыл бұрын
Thanks, very nice explaind.
@DanVega
@DanVega 2 жыл бұрын
Thank you!
@davidaskatra4140
@davidaskatra4140 Жыл бұрын
You are great man
@DanVega
@DanVega Жыл бұрын
Thank you, David!
@m_jdm357
@m_jdm357 Жыл бұрын
Everything works great!
@pavanramagouni6709
@pavanramagouni6709 Жыл бұрын
Thank you Dan. nicely explained and Really helpful.
@DanVega
@DanVega Жыл бұрын
Glad you enjoyed it!
@starterdev
@starterdev Жыл бұрын
Thanks for the video ❤
@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.
@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();
@fahrican9719
@fahrican9719 Жыл бұрын
great tutorial thanks!
@mehlulinokwara3841
@mehlulinokwara3841 Жыл бұрын
Very good take there.
@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!
@lts8683
@lts8683 2 жыл бұрын
Thanks you. Can please explain also keycloak with spring.
@jeanaimeravomanana9545
@jeanaimeravomanana9545 Жыл бұрын
Great content, really helpful thank you
@SigmaLearningCenter
@SigmaLearningCenter Жыл бұрын
Amazing, thanks a lot!
@alibaba40thvs
@alibaba40thvs Жыл бұрын
Thanks a lot Dan!
@alibaba40thvs
@alibaba40thvs 4 ай бұрын
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
@maxjustmax521
@maxjustmax521 2 жыл бұрын
amazing as usual !
@DanVega
@DanVega 2 жыл бұрын
Thank you my friend 🙏
@menabebawy390
@menabebawy390 Жыл бұрын
I super like your video, I have learned a lot form it
@sakthinivas1840
@sakthinivas1840 11 ай бұрын
Hi Dan, really a good video. One functionality which could be added is adding refresh token feature, thanks
@AntonioCabralNumberOne
@AntonioCabralNumberOne 5 ай бұрын
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!
@illyam689
@illyam689 Жыл бұрын
awesome video! subscribed!
@DanVega
@DanVega Жыл бұрын
Thanks for the sub!
@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
@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!
@bartomiejdziadosz8616
@bartomiejdziadosz8616 Жыл бұрын
That was great! What about video about OAuth2 with Auth/Resource/Client?
@pabloc1519
@pabloc1519 10 ай бұрын
THANK YOU THANK YOU!!!!
@НикитаПосмак
@НикитаПосмак Жыл бұрын
Thank you Dan, it's a greate tutorial for beginners. Can you please make a guide about refreshing jwt please.
@DanVega
@DanVega Жыл бұрын
Noted! I have this suggestion here github.com/danvega/office-hours/discussions/27
@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.
@samirmezhoud1851
@samirmezhoud1851 Жыл бұрын
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 Жыл бұрын
Thank you for the suggestion. I have added it to my content idea list github.com/danvega/office-hours/discussions/29
@samirmezhoud1851
@samirmezhoud1851 Жыл бұрын
@@DanVega thank you
@EazzyWizzi
@EazzyWizzi Жыл бұрын
Great Video, keep up the good work
@DanVega
@DanVega Жыл бұрын
Thanks, will do!
@chanchhaya
@chanchhaya Жыл бұрын
Thank you teacher
@davypaterne
@davypaterne Жыл бұрын
great video very useful
@TheGuroguro12
@TheGuroguro12 9 ай бұрын
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 9 ай бұрын
You are welcome!
@dodgechallenger5606
@dodgechallenger5606 Жыл бұрын
Perfect video. Thank you, Dan! Like+Sub
@amirhosseinbayat9657
@amirhosseinbayat9657 4 ай бұрын
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?
@youssouphafaye1710
@youssouphafaye1710 2 жыл бұрын
hello great video btw can you do a video on opaque token that are stock in database
@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!
@sunhsiang6644
@sunhsiang6644 Жыл бұрын
Good video It's really useful🥰🥰!
@DamLee88
@DamLee88 Жыл бұрын
a video on keycloak and SSo auth? thank you! good video
@DanVega
@DanVega Жыл бұрын
Thank you for the suggestions.
@lilinh9631
@lilinh9631 8 ай бұрын
Hey! Great video! But how did you do to autogenerate code just by typing jwt? Thanks a lot!
@geeekfa3278
@geeekfa3278 11 ай бұрын
awesome
@matyzatka
@matyzatka 2 жыл бұрын
hey, this is one great :) ... but for some reason, this error showed up after trying to run the app (26:36) :( Any ideas?:/ We are forced to use Java 8 which does not include records yet.. so I created RsaKeyProperties class instead.. Parameter 0 of constructor in com.greenfoxacademy.springwebapp.config.RsaKeyProperties required a bean of type 'java.security.interfaces.RSAPublicKey' that could not be found. Action: Consider defining a bean of type 'java.security.interfaces.RSAPublicKey' in your configuration.
@krisztinakover8718
@krisztinakover8718 Жыл бұрын
I have the same problem. What we can use instead of record in java8?
@alexeybb981
@alexeybb981 Жыл бұрын
Try this one @Configuration @ConfigurationProperties(prefix = "rsa") public class RsaKeyProperties { private RSAPublicKey publicKey; private RSAPrivateKey privateKey; public RSAPublicKey getPublicKey() { return publicKey; } public void setPublicKey(RSAPublicKey publicKey) { this.publicKey = publicKey; } public RSAPrivateKey getPrivateKey() { return privateKey; } public void setPrivateKey(RSAPrivateKey privateKey) { this.privateKey = privateKey; } }
@samueloyekunleoluwafemi4704
@samueloyekunleoluwafemi4704 Ай бұрын
When the jar is run manually, there is a filenotfound exception. How do we handle this?
@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?
@oreoluwasomuyiwa4049
@oreoluwasomuyiwa4049 7 ай бұрын
Hi, please can you do a tutorial on combining JWT authentication with google's Oauth2 SSO?
@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.
@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.
The joker favorite#joker  #shorts
00:15
Untitled Joker
Рет қаралды 8 МЛН
Остановили аттракцион из-за дочки!
00:42
Victoria Portfolio
Рет қаралды 3,4 МЛН
Новый уровень твоей сосиски
00:33
Кушать Хочу
Рет қаралды 4,5 МЛН
What Is JWT and Why Should You Use JWT
14:53
Web Dev Simplified
Рет қаралды 1,2 МЛН
DHH - Ruby on Rails, 37signals, and the future of web development
1:09:57
Implementing JWT (JSON Web Tokens) with Spring Security in Springboot App
36:25