This project is a Go-based LDAP Authentication Service that provides user authentication via an LDAP server. It is designed with modular components for better maintainability and scalability.
- LDAP Integration: Authenticate users with LDAP.
- Configuration Management: Easily configure the service using
config.yaml
. - Modular Design: Separate layers for services, controllers, and repositories.
- RESTful API: Exposes endpoints for authentication operations.
ldap-auth-service/
├── cmd/
│ └── main.go # Application entry point
├── config/
│ ├── config.yaml # Configuration file
│ └── config.go # Configuration loader
├── controllers/
│ └── auth_controller.go # Handles HTTP requests
├── models/
│ └── user.go # User data model
├── repositories/
│ └── ldap_repository.go # LDAP interaction logic
├── routes/
│ └── routes.go # API route definitions
├── services/
│ └── auth_service.go # Business logic for authentication
- Go: Version 1.18 or higher.
- LDAP Server: An operational LDAP server.
- Configuration: Update
config.yaml
with your LDAP server details.
-
Clone the repository:
git clone <repository-url> cd ldap-auth-service
-
Install dependencies:
go mod tidy
-
Update the configuration in
config/config.yaml
to match your environment.
The config/config.yaml
file contains all necessary configurations:
ldap:
host: "ldap.example.com"
port: 389
base_dn: "dc=example,dc=com"
bind_dn: "cn=admin,dc=example,dc=com"
bind_password: "password"
server:
port: 8080
Start the service with:
go run cmd/main.go
The application will be accessible at http://localhost:8080
.
Description: Authenticates a user with LDAP.
Request Body:
{
"username": "user1",
"password": "password123"
}
Response:
- 200 OK: Authentication successful.
- 401 Unauthorized: Authentication failed.
Sample Response:
{
"message": "Authentication successful",
"user": {
"username": "user1",
"email": "user1@example.com"
}
}
- Create new models in
models/
. - Add the required business logic in
services/
. - Integrate logic into a controller in
controllers/
. - Define new routes in
routes/routes.go
.
To run tests for the service:
go test ./...
Feel free to open issues or submit pull requests for improvements and bug fixes. Follow these guidelines:
- Fork the repository.
- Create a feature branch:
git checkout -b feature-name
- Commit your changes:
git commit -m "Add new feature"
- Push and open a pull request.
For inquiries or support, contact Your Name.