Skip to content

**AuthJS version** 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.

Notifications You must be signed in to change notification settings

ozdemirrulass/nextjs-keycloak-authjs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

Enterprise-Level Authentication in a Containerized Environment for Next.js 13 - AUTHJS PATCH

This repository is a patch for people who wants to use Authjs instead of Next-Auth. Original repository of the tutorial is HERE and the tutorial link.

Here I explain this repository in dept: AuthJS Patch Article

Table of Contents

  1. Introduction
  2. Features
  3. Architecture
  4. Prerequisites
  5. Installation
  6. Configuration
  7. Usage
  8. Contributing
  9. License

Introduction

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.

Features

  • 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.

Architecture

Architecture Diagram

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.

Prerequisites

  • Docker and Docker Compose
  • Git

Installation

  1. Clone the repository

    git clone https://github.com/ozdemirrulass/nextjs-keycloak-authjs.git
     cd nextjs-keycloak-authjs
  2. Build Docker images

    docker compose -f docker-compose.dev.yml build

Configuration

  1. Environment Variables Create a .env.local file in the root directory of next-app and add the necessary environment variables:

    AUTH_SECRET=secret
    
    NEXT_PUBLIC_KEYCLOAK_REALM=<realm-name>
    NEXT_PUBLIC_KEYCLOAK_CLIENT_ID=<client-name>
    KEYCLOAK_CLIENT_SECRET=<client-secret-from-keycloak>
    NEXT_LOCAL_KEYCLOAK_URL="http://localhost:8080"
    NEXT_CONTAINER_KEYCLOAK_ENDPOINT="http://keycloak:8080"
  2. Update Configurations Modify next.config.mjs and docker-compose.dev.yml according to your setup requirements.

Usage

  1. Running the application

    docker compose -f docker-compose.dev.yml up
  2. Access the application Open your browser and navigate to http://localhost:3000

Contributing

Contributions are welcome! Please fork this repository and submit pull requests.

  1. Fork the repository
  2. Create a new branch (git checkout -b feature-branch)
  3. Make your changes
  4. Commit your changes (git commit -m 'Add some feature')
  5. Push to the branch (git push origin feature-branch)
  6. Create a new Pull Request

License

This project is licensed under the MIT License. See the LICENSE file for details.

About

**AuthJS version** 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.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published