---
title: "Discussion on \"Spring Boot REST API authentication best practices using JWT\" | Hashnode"
description: "Discussion on \"Spring Boot REST API authentication best practices using JWT\". Token-based API authentication with Spring Security and JWT (JSON Web Token)"
url: "https://hashnode.com/posts/spring-boot-rest-api-authentication-best-practices-using-jwt/61e44ef89f8415199ccaddff"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Spring Boot REST API authentication best practices using JWT](https://blog.iamprafful.com/spring-boot-rest-api-authentication-best-practices-using-jwt?utm_source=hashnode&utm_medium=feed)

Token-based API authentication with Spring Security and JWT (JSON Web Token)

Jan 16, 2022 · 4 min read · blog.iamprafful.com  
Updated Jan 7, 2024  
Read the article

-   [#java](https://hashnode.com/tag/java)
-   [#spring](https://hashnode.com/tag/spring)
-   [#springboot](https://hashnode.com/tag/springboot)
-   [#jwt](https://hashnode.com/tag/jwt)
-   [#rest-api](https://hashnode.com/tag/rest-api)

## Written by

[Prafful Lachhwani](https://hashnode.com/@Prafful)

@Prafful · Pune, India

  
[View profile](https://hashnode.com/@Prafful)

Full Stack Developer | TCS | Winner SIH 2018

Hey there, I'm a developer, technical writer and YouTuber. I currently work as a Full Stack Developer at Amdocs. I have expertise in building full-stack apps using Spring Boot, Vue.js, Laravel, Flutter, MySQL. I am currently learning Next.js, GraphQL and MERN stack.

## Responses 2

Markdown supported · ⌘↵ to post

[Saurabh Singh](https://hashnode.com/@saurabhsingh241)

[Sep 15, 2022](https://hashnode.com/posts/spring-boot-rest-api-authentication-best-practices-using-jwt/61e44ef89f8415199ccaddff/comment/6323759e55fb028b6442a702)

Thanks for the detailed blog I learned a lot. I have only 1 doubt in our JWTFilter implementation.

```
usernamePasswordAuthenticationToken
    .setDetails(new WebAuthenticationDetailsSource()
    .buildDetails(request));

SecurityContextHolder
    .getContext()
    .setAuthentication(usernamePasswordAuthenticationToken);
```

I am not able to understand what these two lines are doing can you explain.

[Ayushi Rawat](https://hashnode.com/@ayushi7rawat)

[Jan 16, 2022](https://hashnode.com/posts/spring-boot-rest-api-authentication-best-practices-using-jwt/61e44ef89f8415199ccaddff/comment/61e45b898a425719c1734d1d)

Very nicely explained!

[Prafful Lachhwani](https://hashnode.com/@Prafful)

[Jan 16, 2022](https://hashnode.com/posts/spring-boot-rest-api-authentication-best-practices-using-jwt/61e44ef89f8415199ccaddff/comment/61e45b898a425719c1734d1d#reply-61e45d4f8a425719c1734d4a)

Glad you liked😁😁
