Skip to content

๐Ÿ” SpringJWT Repository Explore my SpringJWT repository, where Iโ€™ve delved into the world of JSON Web Tokens (JWT). ๐Ÿš€

Notifications You must be signed in to change notification settings

Jeet-Codes/SpringJwt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

7 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Spring JWT Token Creation and Security Authentication

Overview

This repository demonstrates how to create and manage JSON Web Tokens (JWT) for secure authentication in a Spring-based application. JWTs are widely used for stateless authentication, allowing users to authenticate without relying on server-side sessions.

Features

  1. JWT Token Creation:

    • We'll cover how to generate JWTs upon successful user login.
    • The token will contain user-specific claims (such as username, roles, and expiration time).
  2. Token Validation and Authentication:

    • Learn how to validate incoming JWTs.
    • Implement security filters to authenticate requests based on valid tokens.

Getting Started

  1. Prerequisites:

    • Install Java and Maven.
    • Set up a Spring Boot project.
  2. Clone this Repository:

    git clone https://github.com/Jeet-Codes/SpringJwt.git
    
  3. Configuration:

    • Configure your Spring Security settings in application.properties or application.yml.
    • Define your secret key for JWT signing.
  4. User Authentication:

    • Implement user authentication (e.g., via username/password or OAuth2).
    • Upon successful authentication, issue a JWT.
  5. Token Validation:

    • Create a filter to validate incoming JWTs.
    • Extract user details from the token.
  6. API Endpoints:

    • Define protected endpoints that require valid JWTs.
    • Handle unauthorized access.

Usage

  1. Register/Login:

    • Register a user or log in using your preferred authentication method.
    • Receive a JWT upon successful login.
  2. Access Protected Endpoints:

    • Include the JWT in the Authorization header of your requests.
    • Access protected resources (e.g., user profile, restricted APIs).

Example Code

// Example of JWT creation
String token = Jwts.builder()
    .setSubject(username)
    .claim("roles", roles)
    .setExpiration(expirationDate)
    .signWith(SignatureAlgorithm.HS512, secretKey)
    .compact();

Contributing

Feel free to contribute by opening issues or submitting pull requests. Let's make this repository better together!


About

๐Ÿ” SpringJWT Repository Explore my SpringJWT repository, where Iโ€™ve delved into the world of JSON Web Tokens (JWT). ๐Ÿš€

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages