Reference implementation of a Go backend with SuperTokens passwordless authentication and Dockerized infrastructure on AWS EC2.
https://github.com/davidbmar/supertokens-s3-example · public · shipped
A demonstration project that integrates the SuperTokens Golang SDK for passwordless (magic link) authentication with a Go HTTP server. It includes infrastructure scripts to deploy PostgreSQL and the SuperTokens core via Docker on an Ubuntu EC2 instance, providing a complete stack for testing session-based auth flows.
scp -i "your-key.pem" sample_docker_container_setup.sh ubuntu@<your-ec2-ip>:/home/ubuntu/ ssh -i "your-key.pem" ubuntu@<your-ec2-ip> chmod +x sample_docker_container_setup.sh ./sample_docker_container_setup.sh cd /home/ubuntu/go/src/transcription-service go run cmd/server/main.go
flowchart TD
Client[Web Browser or Curl]
GoBackend[Go Backend Server]
SuperTokensCore[SuperTokens Core Container]
PostgresDB[PostgreSQL Container]
Client -->|HTTP Request| GoBackend
GoBackend -->|Auth API Calls| SuperTokensCore
SuperTokensCore -->|Read Write Data| PostgresDB
The system uses a Shell script to orchestrate Docker containers for PostgreSQL and the SuperTokens core. The application logic is written in Go, using the gorilla/mux router and the official supertokens-golang library. Configuration is managed via environment variables loaded through godotenv.
sequenceDiagram
participant Client
participant GoBackend
participant SuperTokensCore
participant PostgresDB
Client->>GoBackend: POST auth login with email
GoBackend->>SuperTokensCore: Create magic link request
SuperTokensCore->>PostgresDB: Store pre auth session
SuperTokensCore-->>GoBackend: Return magic link URL
GoBackend-->>Client: Return JSON with link
Client->>GoBackend: GET auth verify with token
GoBackend->>SuperTokensCore: Validate session
SuperTokensCore->>PostgresDB: Check session validity
SuperTokensCore-->>GoBackend: Session valid
GoBackend-->>Client: Return success or redirect
Use this repository as a template for setting up secure, session-based authentication in Go microservices. It demonstrates how to isolate identity management in Docker containers while keeping the application stateless and connected via internal networks.