A secure authentication microservice (Spring Boot) and modern frontend (Vue 3) for user registration, login, JWT-based authentication, password change, and token refresh. Built with Spring Boot, PostgreSQL, Flyway, Swagger, Vue 3, Pinia, and Tailwind CSS.
- User registration with role assignment
- Username/password login
- JWT access & refresh tokens
- Token refresh endpoint
- Password change endpoint
- PostgreSQL with Flyway migrations
- Swagger API documentation
- Security best practices (password validation, JWT key size, endpoint protection)
- Modern Vue 3 frontend with component-based architecture
- Java 17+
- Maven 3.8+
- Docker & Docker Compose
- Node.js 18+ and npm (for frontend)
git clone <your-repo-url>
cd auth-service- Edit
src/main/resources/application.ymlif needed (DB credentials, JWT secret, etc). - Ensure
jwt.secretis at least 32 characters. - Provide secrets via environment variables or a secrets file (see below).
docker-compose up -dThis will start a PostgreSQL instance on port 5432 with the database shopdb.
Flyway will automatically run migrations on application startup.
export JWT_SECRET="<your-jwt-secret>"
./mvnw spring-boot:run./mvnw spring-boot:run -Dspring.config.additional-location=classpath:application-secrets.ymlThe service will start on port 9090 by default.
Open http://localhost:9090/swagger-ui.html or http://localhost:9090/swagger-ui/index.html
The frontend is located in the auth-fe/ directory and is built with Vue 3, Vite, Pinia, and Tailwind CSS.
cd auth-fe
npm install
npm run dev- The frontend expects the backend API to be running and accessible at the URL specified in
VITE_API_BASE_URLinauth-fe/.env. - All authentication and token management is handled securely using session storage and Axios interceptors.
- See the frontend
auth-fe/README.mdfor more details.
POST /api/auth/register— Register a new userPOST /api/auth/login— Login and receive access/refresh tokensPOST /api/auth/refresh-token— Get new tokens using a refresh tokenPOST /api/auth/change-password— Change password (JWT required)
See Swagger UI for full details and request/response schemas.
- Go to Google Cloud Console
- Create a new project (or select an existing one)
- Navigate to APIs & Services > Credentials
- Click Create Credentials > OAuth client ID
- Set Application type to
Web application - Add the following redirect URI:
http://localhost:9090/login/oauth2/code/google
- After creation, note the Client ID and Client Secret
- Copy
src/main/resources/application-secrets.yml.exampletosrc/main/resources/application-secrets.yml - Fill in your secrets:
spring: security: oauth2: client: registration: google: client-id: <your-client-id> client-secret: <your-client-secret> scope: profile, email jwt: secret: <your-jwt-secret> expiration: 86400000 refreshExpiration: 604800000
- Make sure
src/main/resources/application-secrets.ymlis in.gitignore(already configured)
- The main
application.ymluses environment variable placeholders:client-id: ${GOOGLE_CLIENT_ID} client-secret: ${GOOGLE_CLIENT_SECRET} ... jwt: secret: ${JWT_SECRET}
- You can set these as environment variables or use the secrets file locally.
- To run locally with the secrets file:
./mvnw spring-boot:run -Dspring.config.additional-location=classpath:application-secrets.yml
- Or set the environment variables in your shell/session.
- Start the app and visit:
http://localhost:9090/oauth2/authorization/google
- Complete Google login. You will be redirected and receive JWT tokens in the response.
- Default roles seeded:
ADMIN,MAKER,CHECKER - Passwords must be at least 8 chars, with upper/lowercase, digit, and special character
- All sensitive endpoints are JWT-protected
- Update
jwt.secretinapplication.ymlfor production
- If you see DB connection errors, ensure Docker PostgreSQL is running and credentials match
- If you see JWT errors, check your
jwt.secretand token format - For Flyway errors, check migration scripts in
src/main/resources/db/migration/ - If you see errors about missing secrets, ensure you have set the required environment variables or are using the secrets file as described above.
MIT
