Skip to content

hamiltonGomes/ms-auth

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 

Repository files navigation

ms-auth API

Authentication and user management microservice. Issues stateless JWT (RSA) and secures endpoints with Spring Security.

Technologies Used

  • Java 21
  • Spring Boot 3
  • Spring Security (OAuth2 Resource Server, JWT, BCrypt)
  • Spring Data JPA
  • PostgreSQL
  • Maven

Why this project

  • Solid, production-friendly security baseline (JWT + RSA, stateless)
  • Simple integration via Authorization: Bearer
  • Clear user lifecycle: create, update, list, lookup, and soft delete

Environment Setup

Prerequisites

  • Java 21 or higher
  • Maven 3.9+
  • PostgreSQL

Configuration

Update src/main/resources/application.properties:

# Database
spring.datasource.url=jdbc:postgresql://localhost:5432/ms_auth_db
spring.datasource.username=your_username
spring.datasource.password=your_password
spring.jpa.hibernate.ddl-auto=update

# JWT Keys (PEM)
jwt.public-key=classpath:keys/public.key
jwt.private-key=classpath:keys/private.key

spring.application.name=ms-auth

Place RSA keys under src/main/resources/keys/. Sample keys exist for local usage only; always replace them in production.

Running the Application

  1. Clone the repository
git clone <repo-url>
  1. Go to the project folder
cd ms-auth
  1. Start the app
mvn spring-boot:run

App available at: http://localhost:8080

Authentication

  • Public endpoints: POST /user/authenticate, POST /user/create
  • Protected endpoints require header: Authorization: Bearer <token>

Endpoints

Authenticate

  • URL: /user/authenticate
  • Method: POST
  • Request:
{
  "username": "alice",
  "password": "123456"
}
  • Response:
{
  "username": "alice",
  "token": "<jwt>",
  "roles": ["ROLE_USER"]
}

Create User

  • URL: /user/create
  • Method: POST
  • Request:
{
  "username": "alice",
  "password": "123456",
  "idProfilePicture": "abc123"
}
  • Response: 201 Created with created user in body

Update User

  • URL: /user/{id}
  • Method: PUT
  • Request (example):
{
  "username": "alice.new",
  "password": "newPassword",
  "idProfilePicture": "xyz789"
}
  • Response: 200 OK with updated user

Get User by ID

  • URL: /user/{id}
  • Method: GET
  • Response: 200 OK with user

Get User by Username

  • URL: /user/by-username/{username}
  • Method: GET
  • Response: 200 OK with user

List Users by Quantity

  • URL: /user/getUsersByQuantity/{quantity}
  • Method: GET
  • Response: 200 OK with list

List All Users

  • URL: /user/
  • Method: GET
  • Response: 200 OK with list

Disable (soft delete) User

  • URL: /user/{id}
  • Method: DELETE
  • Response: 204 No Content (user is marked inactive)

License

This project is licensed under the MIT License.

About

User authentication and management microservice using JWT (RSA) and Spring Security. Implements the complete user lifecycle: creation, update, listing, querying, and logical deletion.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages