Тёмный

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

Dan Vega
Подписаться 56 тыс.
Просмотров 116 тыс.
50% 1

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.dev/blog/2022/09/...
WebSercurityConfigurerAdapter: • Spring Security withou...
👋🏻Connect with me:
Website: www.danvega.dev
Twitter: / therealdanvega
Github: github.com/danvega
LinkedIn: / danvega
Newsletter: www.danvega/dev/newsletter
SUBSCRIBE TO MY CHANNEL: bit.ly/2re4GH0 ❤️

Наука

Опубликовано:

 

8 сен 2022

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 277   
@intellopitt
@intellopitt Год назад
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 :)
@fabricio.entringer
@fabricio.entringer Год назад
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.
@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).
@bobgner
@bobgner Год назад
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 Год назад
Thank you Bob. Glad I could help out.
@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
@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.
@kurzgefasst2816
@kurzgefasst2816 Год назад
Same, Docs mentioned some stuff that are new but honestly Spring Boot Docs is not for Beginner.
@franciskinyuru3459
@franciskinyuru3459 Год назад
Great video my start to spring security wouldn't have been great without this. A big salute.
@SchefenBaba
@SchefenBaba 4 месяца назад
Thanks a lot for this tutorial. I have been stuck in other tutorials for hours.
@kozi-corner
@kozi-corner Год назад
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 Год назад
Thank you Abdelhamid. I hope this clears it up for you.
@kaatlev
@kaatlev Год назад
These videos are so concise and easy to follow, appreciate you.
@DanVega
@DanVega Год назад
That makes me so happy. Thank you ☺️
@drbulltrader9107
@drbulltrader9107 Год назад
I really appreciated this video. Wishes your channel get bigger n bigger.
@brethagen7776
@brethagen7776 Год назад
Straight to the point, no fluff. Looks looks like a bare-minimum implementation.
@jirivrba3800
@jirivrba3800 Год назад
Thanks Dan, really educative content that's very well and clearly presented. Exactly what I was looking for!
@DanVega
@DanVega Год назад
Thank you, glad I could help out.
@mohamadsharifi2353
@mohamadsharifi2353 4 месяца назад
I really enjoyed this video. Thank you for providing such great content.
@Justsomeguy492
@Justsomeguy492 Год назад
finally up to date spring security tutorial :) very good explanation
@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.
@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.
@alexanderkazeev3729
@alexanderkazeev3729 Год назад
Thanks for a great tutorial. The article is very useful and helpful.
@sajisanjoris2759
@sajisanjoris2759 Год назад
Thank you Dan! Great work!
@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.
@robertinnoelson6378
@robertinnoelson6378 22 дня назад
Awesome Dan! Thanks for the rich tutorial
@rajmohanparayil
@rajmohanparayil 2 месяца назад
Wow. Learned a lot of very relevant security implementation in a very smooth and clean fashion and in such a short time.
@DanVega
@DanVega 2 месяца назад
Glad you liked it!
@fjspitz
@fjspitz Год назад
Nice tutorial Dan! Thanks a lot.
@monjurmorshed2854
@monjurmorshed2854 Год назад
U have a nice way to explain, great work!!!
@DanVega
@DanVega Год назад
I appreciate that Monjur. I make videos that I would enjoy watching and I’m glad others are learning from them as well.
@behzadfazelasl9581
@behzadfazelasl9581 Год назад
Thanks Dan. it was crystal clear
@tabancosmos2235
@tabancosmos2235 Год назад
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.
@leonzer8257
@leonzer8257 Год назад
Thank you very much! Greetings from Greece!!!
@DanVega
@DanVega Год назад
You are welcome!
@jeanaimeravomanana9545
@jeanaimeravomanana9545 Год назад
Great content, really helpful thank you
@svalyavasvalyava9867
@svalyavasvalyava9867 10 месяцев назад
wonderful tutorial, thank toy very much 😊
@rizkysiregar
@rizkysiregar Месяц назад
Thanks for sharing dan !
@rajansonvane488
@rajansonvane488 Год назад
Wonderful. Very helpful. Thanks for sharing!!
@DanVega
@DanVega Год назад
Glad it was helpful!
@benizraadacudao3020
@benizraadacudao3020 Год назад
Thanks for this Dan.
@DanVega
@DanVega Год назад
You’re welcome Ben.
@toan1nguyen674
@toan1nguyen674 8 месяцев назад
Thanks for asymmetric rsakeys knowledge you've shared.
@midewestmond9442
@midewestmond9442 Год назад
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!
@rahanimhand6895
@rahanimhand6895 10 месяцев назад
Amazing !!!! Great video, Thanks 👌
@pavanramagouni6709
@pavanramagouni6709 Год назад
Thank you Dan. nicely explained and Really helpful.
@DanVega
@DanVega Год назад
Glad you enjoyed it!
@starterdev
@starterdev Год назад
Thanks for the video ❤
@mvlad7402
@mvlad7402 Год назад
Excellent video! Need to test spring security with Ping Federate.
@kyriakosmandalas2121
@kyriakosmandalas2121 Год назад
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 Год назад
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)
@aayush481
@aayush481 Год назад
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.
@tipswithnna6670
@tipswithnna6670 Год назад
Thanks for sharing about JWT
@fahrican9719
@fahrican9719 Год назад
great tutorial thanks!
@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
@gamires
@gamires 2 месяца назад
Excellent! Thank you.
@bejobarokah3485
@bejobarokah3485 Год назад
Thank you for the tutorial
@DanVega
@DanVega Год назад
You’re welcome 😊
@mdziakhan5950
@mdziakhan5950 8 месяцев назад
Great Explanation
@user-zw4ki9tw4e
@user-zw4ki9tw4e 9 месяцев назад
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.
@menabebawy390
@menabebawy390 8 месяцев назад
I super like your video, I have learned a lot form it
@AleksandarT10
@AleksandarT10 Год назад
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 Год назад
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 4 месяца назад
@@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")); }
@SigmaLearningCenter
@SigmaLearningCenter Год назад
Amazing, thanks a lot!
@edwardm4348
@edwardm4348 10 месяцев назад
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.
@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.
@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?
@dekeyserwilly
@dekeyserwilly Год назад
Thanks, very nice explaind.
@DanVega
@DanVega Год назад
Thank you!
@mehlulinokwara3841
@mehlulinokwara3841 Год назад
Very good take there.
@arlekino65
@arlekino65 10 месяцев назад
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!
@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?
@m_jdm357
@m_jdm357 Год назад
Everything works great!
@maxjustmax521
@maxjustmax521 Год назад
amazing as usual !
@DanVega
@DanVega Год назад
Thank you my friend 🙏
@neerajagrawal3211
@neerajagrawal3211 Месяц назад
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.
@user-qd5np7sl2z
@user-qd5np7sl2z Год назад
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.
@rarecase3666
@rarecase3666 14 дней назад
You are right.... Spring Security tutorials shows that people try to understand but cannot make it working... Spring Security Team also makes it very challenging to build something with it. Thank you, Dave, for your tutorial - it really helped to make it working.
@andrean40
@andrean40 9 дней назад
is this tutorial outdated?
@victoradepoju5510
@victoradepoju5510 7 дней назад
No ​@@andrean40
@marekj3759
@marekj3759 9 месяцев назад
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
@illyam689
@illyam689 Год назад
awesome video! subscribed!
@DanVega
@DanVega Год назад
Thanks for the sub!
@szalaytamas3184
@szalaytamas3184 Год назад
your outro music is so good
@sakthinivas1840
@sakthinivas1840 7 месяцев назад
Hi Dan, really a good video. One functionality which could be added is adding refresh token feature, thanks
@alitariq143
@alitariq143 9 месяцев назад
Thanks a lot Dan!
@alitariq143
@alitariq143 23 дня назад
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
@lts8683
@lts8683 Год назад
Thanks you. Can please explain also keycloak with spring.
@rbelatamas
@rbelatamas Год назад
thank you so much ❤
@sunhsiang6644
@sunhsiang6644 Год назад
Good video It's really useful🥰🥰!
@dodgechallenger5606
@dodgechallenger5606 Год назад
Perfect video. Thank you, Dan! Like+Sub
@davidaskatra4140
@davidaskatra4140 Год назад
You are great man
@DanVega
@DanVega Год назад
Thank you, David!
@davypaterne
@davypaterne Год назад
great video very useful
@EazzyWizzi
@EazzyWizzi Год назад
Great Video, keep up the good work
@DanVega
@DanVega Год назад
Thanks, will do!
@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!
@mrkostya008
@mrkostya008 Год назад
finally, an informative tutorial that ACTUALLY uses BUILTIN jwt tools, and not some filters and JwtUtility classes to secure an app
@pabloc1519
@pabloc1519 7 месяцев назад
THANK YOU THANK YOU!!!!
@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?
@bartomiejdziadosz8616
@bartomiejdziadosz8616 Год назад
That was great! What about video about OAuth2 with Auth/Resource/Client?
@AntonioCabralNumberOne
@AntonioCabralNumberOne 2 месяца назад
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!
@alexgutjahr
@alexgutjahr Год назад
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 Год назад
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.
@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 9 месяцев назад
can't fix it even using Customizer.withDefaults();
@chanchhaya
@chanchhaya Год назад
Thank you teacher
@lilinh9631
@lilinh9631 4 месяца назад
Hey! Great video! But how did you do to autogenerate code just by typing jwt? Thanks a lot!
@vintage8
@vintage8 Год назад
Hey, great video. I learned very valuable things from your videos. I was wondering how can I do the following: I have a 'tokenVersion' column in my users table. Every time User logs out or refreshes the token I'm going to increase it by 1. When the JWT is decoded and if it's valid I want to check if the tokenVersion in the JWT and in the DB matches. If it matches request can continue if not I want to throw 401.
@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
@user-qt6kq8sh8r
@user-qt6kq8sh8r Год назад
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
@ryanwakabayashi1758
@ryanwakabayashi1758 Год назад
I love your videos! I had a question on how you would approach deploying this application. I am trying to deploy to AWS beanstalk, but I'm having difficulties with the RSA .pem files. I have been trying to add the public and private keys as an environment property in elastic beanstalk, but am having difficulties because it is a string value and not a file. I also tried to add a key converter with @Component and @ConfigurationPropertiesBinding, but I still get a failed convert from string to RSAPublicKey. What do you think should be the approach/best practice to remedy this?
@user-en7qc9dt8p
@user-en7qc9dt8p Год назад
저도 이에대한 같은 오류가 발생했습니다 어떻게 해결할 수 있는지 궁금합니다
@ankanghosh169
@ankanghosh169 10 месяцев назад
Hii Dan, I love ur tutorials.. my question is how can i create a seperate authentication servuce using jwt. And then use that is a seperate client service to secure endpoint? Thanks..
@MrMCchanel
@MrMCchanel Год назад
Great video! Is there a way to user roles with the currente JWT configuration in this video?
@DanVega
@DanVega Год назад
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
@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!
@amirhosseinbayat9657
@amirhosseinbayat9657 25 дней назад
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?
@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.
@youssouphafaye1710
@youssouphafaye1710 Год назад
hello great video btw can you do a video on opaque token that are stock in database
@USONOFAV
@USONOFAV Год назад
Great video as always! I got two questions though: Why does it needs to be annotated with @EnableWebSecurity. Is it like automatic once you added SecurityFilterChain in the app context? Can I create public and private key using keytool instead of openssl?
@DanVega
@DanVega Год назад
It isn't automatic. Spring Boot will actually add it for you if you forgot it but I like to be explicit with it. If you don't want to use OpenSSL and you're just using self-signed certs you can generate them with code. I have an example of that in the following repository. github.com/danvega/jwt-username-password
@ValentynHruzytskyi
@ValentynHruzytskyi Год назад
Great video! Thanks! Could you explain: you have showed the project creation with the spring starter io source. But, after project was created, you show 2 pom files - problem in that the spring.starter actually created only one single pom. How to I have to understand and follow your solution? And the main issue - I have implemented all steps and this solution doesn't work: yes, I received token, but this token doesn't work for other requests - I have receiving 401 error for all following requests. Now I try to understand the difference - and the difference only in the pom files between your and my code. But you are not explained them
@DesasterUA
@DesasterUA Год назад
Sir, how did you automatically generate the tests? Was it the Copilot?
@samahmahdi5511
@samahmahdi5511 Месяц назад
Thanks a lot, can you create new video for spring boot 3
@yannickmussche5068
@yannickmussche5068 Год назад
Dear Dan, I followed your tutorials to set up the new Spring security. Helas, the one thing I cannot get working is that the roles get authenticated. Is it possible to make a video in which you explain the spring security setup with jwt tokens and a hiberante database authentication with roles?
@budsyremo
@budsyremo Год назад
Hi Dan , glad i found your tutorial but my problem is the spring's documentation. It is awful . How do you go about in reading the documentation. I have a question , I want to implement this as a microservice , so what should be the logic behind it ? Everytime a user hits my request he/she will be entering username and password and I will be granting a token to the client. Once the client gets that token how will i forward that token from my microservice to this authentication microservice ?
Далее
Legendary KNOCKOUT
00:44
Просмотров 1,9 млн
Аварийный выход
00:38
Просмотров 808 тыс.
What Is JWT and Why Should You Use JWT
14:53
Просмотров 1,1 млн
Spring Security, demystified by Daniel Garnier Moiroux
2:36:00
Для фанатов SEGA MEGADRIVE - Anbernic RG ARC
14:23
Для фанатов SEGA MEGADRIVE - Anbernic RG ARC
14:23