A simple authentication service built with Go and Gin, providing JWT-based authentication for demo purposes.
- JWT-based authentication
- Swagger documentation
- Hardcoded test users with different access levels
- Docker support
- Comprehensive test suite
The service includes two hardcoded test users:
-
Beta User
{ "username": "betauser", "password": "betauser", "company": "acme global", "beta_access": true }
-
Normal User
{ "username": "normaluser", "password": "normaluser", "company": "generic co", "beta_access": false }
The API documentation is available via Swagger UI at:
http://localhost:8080/swagger/index.html
Authenticates a user and returns a JWT token along with user details.
Request body:
{
"username": "string",
"password": "string"
}
Success Response (200):
{
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"user": {
"username": "string",
"company": "string",
"beta_access": boolean
}
}
Returns a list of all available users with their credentials. This endpoint is provided for demo purposes to easily populate the login form.
Success Response (200):
[
{
"username": "betauser",
"password": "betauser"
},
{
"username": "normaluser",
"password": "normaluser"
}
]
- Go 1.23 or higher
- Docker (optional)
- Clone the repository
- Install dependencies:
go mod download
- Generate Swagger documentation:
swag init
- Run the application:
go run main.go
- Build the image:
docker build -t hackers-auth .
- Run the container:
docker run -p 8080:8080 hackers-auth
- Kubernetes cluster
- Helm 3.x
- cert-manager installed (for TLS)
-
Create a custom values file (e.g.,
my-values.yaml
):# Image configuration image: repository: your-registry/hackers-auth # Change to your image repository tag: your-tag # Change to your image tag pullPolicy: IfNotPresent # Domain configuration hostname: auth.your-domain.com # Change to your domain # Resource limits resources: requests: cpu: 100m memory: 128Mi limits: cpu: 200m memory: 256Mi
-
Install the chart:
helm install hackers-auth ./chart -f my-values.yaml
Or upgrade an existing release:
helm upgrade hackers-auth ./chart -f my-values.yaml
Parameter | Description | Default |
---|---|---|
image.repository |
Image repository | cloudbees-days/hackers-auth |
image.tag |
Image tag | latest |
image.pullPolicy |
Image pull policy | IfNotPresent |
hostname |
Service hostname | hackers-auth.example.com |
resources.requests.cpu |
CPU request | 100m |
resources.requests.memory |
Memory request | 128Mi |
resources.limits.cpu |
CPU limit | 200m |
resources.limits.memory |
Memory limit | 256Mi |
Run the test suite:
go test -v
The test suite includes:
- Login endpoint tests
- User authentication tests
- JWT token validation
- Error handling tests
.
├── main.go # Main application file
├── main_test.go # Test suite
├── Dockerfile # Docker configuration
├── .dockerignore # Docker ignore file
├── .gitignore # Git ignore file
├── chart/ # Helm chart directory
└── docs/ # Generated Swagger documentation (gitignored)
- The JWT token expires after 24 hours
- Swagger documentation is generated during Docker build
- The service runs in release mode when deployed via Docker