This repository provides a setup for authentication in a modern web application environment. For more detailed explanation and step by step guide of this repository please visit my blog post.
- Introduction
- Features
- Architecture
- Prerequisites
- Installation
- Configuration
- Usage
- Contributing
- License
This project demonstrates how to integrate enterprise-level authentication in a containerized Next.js 13 environment. It covers key aspects such as OAuth, JWT, and secure handling of user credentials in a scalable and maintainable way.
- Secure Authentication: Implement OAuth 2.0, JWT, and session management.
- Containerization: Use Docker to containerize the application for consistent development and deployment environments.
- Scalability: Designed to scale with microservices architecture.
- Extensibility: Easily extendable with additional authentication providers and services.
The architecture consists of the following components:
- Next.js 13: Frontend framework.
- Authentication Service: Keycloak
- MySQL: Keycloak inteagrated database service.
- Docker: Containerization of the application.
- Docker and Docker Compose
- Git
-
Clone the repository
git clone https://github.com/ozdemirrulass/keycloak-nextjs-mysql-docker.git
cd keycloak-nextjs-mysql-docker
-
Build Docker images
docker compose -f docker-compose.dev.yml build
-
Environment Variables Create a
.env.local
file in the root directory ofnext-app
and add the necessary environment variables:NEXT_PUBLIC_KEYCLOAK_REALM=<realm-name> NEXT_PUBLIC_KEYCLOAK_CLIENT_ID=<client-name> KEYCLOAK_CLIENT_SECRET=<secret-from-keycloak-client> NEXTAUTH_SECRET=<create-using-openssl> NEXT_LOCAL_KEYCLOAK_URL="http://localhost:8080" NEXT_CONTAINER_KEYCLOAK_ENDPOINT="http://keycloak:8080"
-
Update Configurations Modify
next.config.mjs
anddocker-compose.dev.yml
according to your setup requirements.
-
Running the application
docker compose -f docker-compose.dev.yml up
-
Access the application Open your browser and navigate to
http://localhost:3000
Contributions are welcome! Please fork this repository and submit pull requests.
- Fork the repository
- Create a new branch (
git checkout -b feature-branch
) - Make your changes
- Commit your changes (
git commit -m 'Add some feature'
) - Push to the branch (
git push origin feature-branch
) - Create a new Pull Request
This project is licensed under the MIT License. See the LICENSE file for details.