{"id":22685131,"url":"https://github.com/kartikmehta8/java-spring-auth","last_synced_at":"2026-04-16T12:01:40.031Z","repository":{"id":264951181,"uuid":"850722062","full_name":"kartikmehta8/java-spring-auth","owner":"kartikmehta8","description":"Spring Boot application that implements JWT-based authentication with MongoDB, featuring secure user registration, login, and token validation using Spring Security","archived":false,"fork":false,"pushed_at":"2024-09-01T15:42:56.000Z","size":157,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-01-15T17:02:13.758Z","etag":null,"topics":["authentication","java","jwt","spring-boot"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kartikmehta8.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-09-01T15:42:46.000Z","updated_at":"2024-09-01T15:43:43.000Z","dependencies_parsed_at":"2024-11-27T00:17:34.609Z","dependency_job_id":null,"html_url":"https://github.com/kartikmehta8/java-spring-auth","commit_stats":null,"previous_names":["kartikmehta8/java-spring-auth"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/kartikmehta8/java-spring-auth","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kartikmehta8%2Fjava-spring-auth","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kartikmehta8%2Fjava-spring-auth/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kartikmehta8%2Fjava-spring-auth/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kartikmehta8%2Fjava-spring-auth/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kartikmehta8","download_url":"https://codeload.github.com/kartikmehta8/java-spring-auth/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kartikmehta8%2Fjava-spring-auth/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31884929,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-16T11:36:10.202Z","status":"ssl_error","status_checked_at":"2026-04-16T11:36:09.652Z","response_time":69,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["authentication","java","jwt","spring-boot"],"created_at":"2024-12-09T22:13:16.469Z","updated_at":"2026-04-16T12:01:40.012Z","avatar_url":"https://github.com/kartikmehta8.png","language":"Java","readme":"# Spring Boot JWT Authentication\n\nThis project is a Spring Boot application that demonstrates how to implement JWT-based authentication. The application uses MongoDB as the database for storing user information and implements the following features:\n\n- User registration\n- User login with JWT token generation\n- JWT token validation for secure endpoints\n\n## Features\n\n- **Spring Security**: Configured to secure the application and manage authentication.\n- **JWT (JSON Web Token)**: Used for stateless authentication.\n- **BCrypt Password Encoding**: Ensures that user passwords are securely stored.\n- **MongoDB**: Used as the database for storing user credentials.\n\n## Getting Started\n\n### Installation\n\n1. **Setup MongoDB**:\n   - If using MongoDB Atlas, replace the connection string in `application.properties` with your own.\n   - If using a local MongoDB instance, ensure MongoDB is running locally on the default port.\n\n2. **Update `application.properties`**:\n   - Add the MongoDB connection string.\n   - Set up any additional properties as needed.\n\n3. **Build and run the application**:\n\n    ```bash\n    ./mvnw spring-boot:run\n    ```\n\n    or\n\n    ```bash\n    ./gradlew bootRun\n    ```\n\n### Endpoints\n\n![register](./assets/register.png)\n- **POST `/api/auth/register`**: Register a new user.\n    - **Request Body**:\n    ```json\n    {\n        \"email\": \"user@example.com\",\n        \"password\": \"password123\"\n    }\n    ```\n\n    - **Response**:\n    ```json\n    \"User registered successfully\"\n    ```\n\n![login](./assets/login.png)\n- **POST `/api/auth/login`**: Authenticate a user and generate a JWT token.\n    - **Request Body**:\n    ```json\n    {\n        \"email\": \"user@example.com\",\n        \"password\": \"password123\"\n    }\n    ```\n\n    - **Response**:\n    ```json\n    {\n        \"token\": \"jwt-token-here\"\n    }\n    ```\n\n### Explanation of Key Components\n\n#### 1. Security Configuration\n\nThe security configuration class sets up Spring Security to use JWT tokens for authentication. It defines the security filter chain, password encoder, and authentication manager.\n\n#### 2. JWT Authentication Filter\n\nThis filter intercepts incoming requests and checks for the presence of a JWT token in the `Authorization` header. If a valid token is found, it sets the authentication in the security context.\n\n#### 3. JWT Utility Class\n\nThis utility class handles the creation, validation, and parsing of JWT tokens. It uses a secure key generated by `Keys.secretKeyFor(SignatureAlgorithm.HS512)`.\n\n#### 4. User Service\n\nThis service class manages user registration, authentication, and loading user details. It uses `BCryptPasswordEncoder` for password encoding and validation.\n\n#### 5. Auth Controller\n\nThe controller exposes endpoints for user registration and login. It interacts with the `UserService` to handle registration and authentication and uses the `JwtUtil` to generate and return JWT tokens.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkartikmehta8%2Fjava-spring-auth","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkartikmehta8%2Fjava-spring-auth","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkartikmehta8%2Fjava-spring-auth/lists"}