A small Go service that handles Sign in with Apple, session issuance/refresh, and user persistence in Postgres. It uses pgx
for DB access, a tiny in-memory cache for JWKS, and Goose for SQL migrations.
- Prerequisites
- Configuration
- Running with Docker Compose
- Running locally
- Migrations
- API Endpoints
- Troubleshooting
- Go 1.22+
- Docker & Docker Compose (for containerized runs)
- An Apple Sign In private key (
.p8
) associated with your Team and Key ID
.env keys (dummy example):
# App JWT
APP_JWT_SECRET=dev-supersecret-change-me
APP_JWT_ISSUER=auth-service
APP_JWT_AUDIENCE=auth-service-clients
APP_JWT_ACCESS_LIFETIME=15m
APP_JWT_REFRESH_LIFETIME=720h
APP_JWT_CLOCK_SKEW_LEEWAY=60s
# Apple Sign In
APPLE_TEAM_ID=AAAAAAA111
APPLE_CLIENT_ID=com.example.app
APPLE_KEY_ID=KID123ABC
APPLE_PRIVATE_KEY_PATH=./secrets/AuthKey_DEV.p8
APPLE_HTTP_TIMEOUT=5s
APPLE_JWK_CACHE_TTL=24h
# Database (choose one)
DATABASE_URL=postgres://auth_user:auth_pass@localhost:5432/auth_db?sslmode=disable
# DATABASE_URL=postgres://auth_user:auth_pass@db:5432/auth_db?sslmode=disable # for Docker
# HTTP
PORT=3000
- Place your Apple private key at
./secrets/AppleKey_DEV.p8
(or adjust the path in.env
). - Ensure your
.env
hasDATABASE_URL
pointing to the Compose host (db
):
postgres://auth_user:auth_pass@db:5432/auth_db?sslmode=disable
- Start services:
docker compose up --build
- Service will listen on
http://localhost:${PORT}
(default3000
).
If Adminer is included, it will be athttp://localhost:8081
(serverdb
, userauth_user
, passauth_pass
, dbauth_db
).
Example docker-compose.yml
snippet:
services:
server:
env_file: .env
volumes:
- ./secrets/AppleKey_DEV.p8:/run/keys/apple.p8:ro
environment:
APPLE_PRIVATE_KEY_PATH: /run/keys/apple.p8
- Start Postgres on your machine (or via Docker) and ensure:
DATABASE_URL=postgres://auth_user:auth_pass@localhost:5432/auth_db?sslmode=disable
- Ensure the
.p8
atAPPLE_PRIVATE_KEY_PATH
exists. - Run the server:
go run ./...
-
POST /token/apple
Exchange Apple authorization code, verify ID token, upsert user/identity, issue app tokens.
Response:{ "access_token": "...", "refresh_token": "..." }
-
POST /token/refresh
Exchange a valid refresh token for a new pair. -
POST /token/revoke
(auth required)
Revoke a single refresh token. -
POST /token/revoke/all
(auth required)
Revoke all refresh tokens for the current user.
Add auth support for:
- Microsoft
- Others?
Add logging****
Add saving username