SuperTokens S3 Example

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

What it is

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.

Features

Quickstart

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

Architecture

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

How it's built

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.

How it runs

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

How to apply & reuse

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.

At a glance

CapabilitiesPasswordless LoginSession ManagementDocker OrchestrationAPI Routing
ComponentsGo Backend ServerSuperTokens CorePostgreSQL DatabaseSetup Shell ScriptStatic HTML Frontend
TechGoShellDockerPostgreSQLSuperTokensAWS EC2
Depends onDocker EngineGolang ToolchainUbuntu LinuxAWS Security Groups
Integrates withAWS S3Nginx Reverse ProxyLet's Encrypt SSL
PatternsPasswordless AuthenticationContainerized InfrastructureEnvironment Based ConfigurationMicroservice Architecture
Reuse tagsauthenticationgolangsupertokensdockerawsinfrastructure-as-code

⚠ Needs attention