game-library-auth
Introduction
game-library-auth is an authentication service for the game-library web application. It is responsible for user authentication and authorization.
game-library consists of:
- game-library - main service for fetching, storing, and providing games data
- current service handles authentication and authorization
- game-library-ui - UI service
- game-library-infra - infrastructure and deployment configurations
Table of Contents
Installation
Prerequisites: go, Docker, Make.
To set up the service, follow these steps:
-
Clone the repository:
git clone https://github.com/OutOfStack/game-library-auth.git
cd game-library-auth
-
Set up the database:
make drunpg # runs postgres server with 'auth' db in docker container
make migrate # applies all migrations to database
-
Generate key pair for local JWT signing:
make keygen # creates private/public key pair files
-
Create the app.env file based on app.example.env and update it with your local configuration settings.
-
Get Google API Client ID for Google OAuth and set it in app.env:
https://developers.google.com/identity/gsi/web/guides/get-google-api-clientid
-
Get GitHub OAuth App Client ID and Secret for GitHub OAuth and set them in app.env:
https://docs.github.com/en/apps/oauth-apps/building-oauth-apps/creating-an-oauth-app
-
Get Resend API key and set it along with the sender details in app.env:
https://resend.com/api-keys
-
Build and run the service:
make build
make run
Refer to the List of Make Commands for a complete list of commands.
Usage
After installation, you can use the following Make commands to develop the service:
make test: Runs tests for the whole project.
make generate: Generates proto files, documentation for Swagger UI and mocks for testing.
make lint: Runs golangci-lint for code analysis.
Refer to the List of Make Commands for a complete list of commands.
Tech Stack and Integrations
- Data storage with PostgreSQL.
- Transactional email delivery through Resend API.
- gRPC for internal service-to-service communication.
- Tracing with OTLP exporter (Jaeger).
- Log management with Graylog.
- Metrics collection with Prometheus.
- Code analysis with golangci-lint.
- CI/CD with GitHub Actions and deploy to Kubernetes (microk8s) cluster.
Configuration
Documentation
API documentation is available via Swagger UI. To generate the documentation, run:
make generate
gRPC
The service exposes a gRPC endpoint for internal service-to-service communication.
Endpoint: localhost:9001 (APP_GRPC_ADDRESS environment variable in app.example.env)
Protobuf Definition: api/proto/authapi/v1/authapi.proto
Testing with grpcurl:
# list services
grpcurl -plaintext localhost:9001 list
# describe service
grpcurl -plaintext localhost:9001 describe authapi.v1.AuthApiService
# call VerifyToken method
grpcurl -plaintext -d '{"token": "your-jwt-token-here"}' -emit-defaults localhost:9001 authapi.v1.AuthApiService/VerifyToken
List of Make Commands
Main Commands
build builds app
build-mng builds manage app
run runs app
test runs tests for the whole project
generate generates docs for Swagger UI
lint runs golangci-lint
cover outputs tests coverage
Database Commands
drunpg runs postgres server with 'auth' db in docker container
migrate applies all migrations to database (reads from config file)
rollback roll backs one last migration of database (reads from config file)
Key Management
keygen creates private/public key pair files
secretgen generates a cryptographically secure random secret for HMAC
Docker Commands
dbuildauth builds auth app docker image
dbuildmng builds manage app docker image
drunauth runs auth app in docker container
License
MIT License