Skip to content

sahilmemon7/stock_auth_svc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Stock Auth API

Java Spring MySQL Docker

Maintenance

License: MIT

API to handle JWT user authentication.

Stack

  • Java 21
  • Maven
  • Spring Boot
  • Spring Web
  • Spring Validation
  • Jakarta Validation
  • Spring Data JPA
  • MySQL Connector
  • Spring Security
  • JWT API
  • JWT Implementation
  • JWT Jackson
  • Spring Dotenv
  • Lombok
  • Spring Test
  • H2 Database
  • MacOS DNS Resolver
  • Docker

Setup

  • Install dependencies:
./mvnw clean install
  • Pull Docker MySQL image for running database server:
docker pull mysql:latest
  • Create an external volume for storing MySQL data:
docker volume create stock_auth_volume
  • Run the container:
docker compose up -d
  • Start the application:
./mvnw spring-boot:run
  • Stop the container:
docker compose down

Endpoints

Requests can be made to perform the following actions:

  • Register User
  • Authenticate User
  • Refresh Token

Register User

Request

curl --location 'localhost:8080/api/v2/auth/register-user' \
--header 'Content-Type: application/json' \
--data-raw '{
    "firstName": "Test",
    "lastName": "User",
    "email": "[email protected]",
    "password": "password1234"
}'

Response

{
    "accessToken": "eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ0dTJAZXhhbXBsZS5jb20iLCJpYXQiOjE3Mzc1MDEyNTAsImV4cCI6MTczODEwNjA1MH0.7Yj96BvdTv-4b05jPBhZ_QdpzWD8kosxyzlyoWsvqXk",
    "refreshToken": "eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ0dTJAZXhhbXBsZS5jb20iLCJpYXQiOjE3Mzc1MDEyNTAsImV4cCI6MTc0MDA5MzI1MH0.FAaKVZuRkJ4lUVdo8cnAd6kFfbn0JzQtT5roa4n8THs"
}

Authenticate User

Request

curl --location 'localhost:8080/api/v2/auth/authenticate-user' \
--header 'Content-Type: application/json' \
--data-raw '{
    "email": "[email protected]",
    "password": "password1234"
}'

Response

{
    "accessToken": "eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ0dUBleGFtcGxlLmNvbSIsImlhdCI6MTczNzUwMTAzOSwiZXhwIjoxNzM4MTA1ODM5fQ.Spi1W0gRCULRwLoU3Jz8sW4_zL0XnGi0xME3PTbEFK4",
    "refreshToken": "eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ0dUBleGFtcGxlLmNvbSIsImlhdCI6MTczNzUwMTAzOSwiZXhwIjoxNzQwMDkzMDM5fQ._WEcXnNyyCngS6gmJ4F3ho_Vn6Vo2DyzrmNFu-i6VjY"
}

Refresh Token

Request

curl --location 'localhost:8080/api/v2/auth/refresh-token' \
--header 'Content-Type: application/json' \
--data '{
    "refreshToken": "eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ0dUBleGFtcGxlLmNvbSIsImlhdCI6MTczNzUwNzM5OCwiZXhwIjoxNzM4MTEyMTk4fQ.JqkJxuaDbyem30MVd5Q5BQIfiLp7nu3210fmj2-rewc"
}'

Response

{
    "accessToken": "eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ0dUBleGFtcGxlLmNvbSIsImlhdCI6MTczNzUwNzQ2NiwiZXhwIjoxNzM4MTEyMjY2fQ.Et3XavwPZThsmbrC_jcTVbJn01ly4G9jEe28HZaOs2s"
}