r/SpringBoot • u/Mental_Gur9512 • Dec 26 '25
Question JWT implementation for beginners, I am looking for one clear and correct source
Hi everyone,
I’m looking for a high-quality but simple resource that explains how to properly implement JWT authentication.
I’ve been searching, but I keep finding different explanations, and I want to learn this the correct way, not just copy bad snippets.
Also, how big are the differences between Spring Boot 2, 3, and 4 regarding JWT and Spring Security?
Thanks in advance!
24
Upvotes
3
u/Wolfrik50 Dec 26 '25
I can provide you code for custom JWT implementation using all the spring security classes and also how to do that using oauth2 resource server
1
u/nikhilb_it Dec 27 '25
Below is a good repository to learn. It covers all details and with good documentation. Its having older version of spring boot but the way explanation is given is superb.
https://github.com/murraco/spring-boot-jwt
1
u/No_Objective_2196 Dec 27 '25
ChatGPT is great for generating specific codes snippet like this
3
u/eli_li Dec 31 '25
If you are having issue to understand how JWT authentication works, I assume you might need some knowledge on spring security in general because JWT is just a filter among the authentication filter chains. So i suggest you go through a Spring Security In Action Volume 01 or 02 (* prefered) by Launrentiu Spilca, once you complete this book not only you'll understand how it works but also be an expert in spring security and oauth2 implementations on both sides.
1
u/hellocodingworld Dec 26 '25
Check it from Think Constructive YT - https://www.youtube.com/playlist?list=PLcs1FElCmEu2eecQE2SuuXsAjmmB7qbPy
1
u/deividas-strole Dec 26 '25
I watched this guy on YouTube and it was pretty easy to understand. https://www.youtube.com/watch?v=KxqlJblhzfI From my personal experience, try watching one author's video, and if you're still confused, watch another author's video. A couple of different explanations sometimes help to build a full picture.
1
u/Ali_Ben_Amor999 Dec 28 '25
Unfortunately all the JWT videos I've seen do not implement jwt correctly or at least securely. They build a version and you need to learn/explore the rest. The best high quality resource will be the JWT specification itself. Learn about the different algorithms and their pros and cons. Learn how to use a pair of refresh/access token pattern. Learn how to revoke tokens and detect potential token theft. After learning these you can implement it on spring you need a filter + a service that keep track of generated and revoked tokens
1
u/toasti3 Dec 28 '25
this tutorial helped me. there is a way to let the spring framework do the work instead of implementing custom filters and third party jwt libraries like most tutorials show.
https://www.danvega.dev/blog/spring-security-jwt
1
u/Shake_Sufficient Dec 28 '25
I can provide a sample source code of a custom implementation for JWT generation with Spring Security and Spring Auth Server, I will just need some time to extract it from context.
Regarding Spring versions, for 2.x, the Auth Server was builtin Spring Security but the team decided to remove the Auth Server capabilities in 3.x onwards. But luckily, the team supported an open source implementation of Spring Auth Server which wires very nicely with Spring Security and gives you some freedom with your JWT generation and so on.
So far, I understand you have seen many implementations with nimbus and similar techniques. While they still remain highly valid, taking a look at Auth servers might be helpful. If that’s not what you require, feel free to ask as well.
1
u/two_wheel_soul Dec 26 '25
so many youtube channels r there on this .. just ask chatgpt or google..
u need to resource could be 2 microservice(ideally) or both resource in one microservice.
Decode the JWT Token, decide whether given roles has authority to access the resource.
PS: By Resource here i mean HTTP VERB APS eg. GET /dosomething, POST /doSomething
0
u/[deleted] Dec 26 '25
[deleted] — view deleted comment
1
u/[deleted] Dec 27 '25
[removed] — view removed comment