SuperTokens S3 Example

A reference implementation of passwordless authentication using SuperTokens, Go, and Docker on AWS EC2.

https://github.com/davidbmar/supertokens-s3-example  ·  public  ·  shipped

What it is

This project demonstrates how to integrate SuperTokens passwordless authentication into a Go backend service. It includes infrastructure scripts to deploy SuperTokens Core and PostgreSQL via Docker on an AWS EC2 instance, along with a Go server that handles magic link generation and session verification. The architecture is designed for cloud deployment with security considerations for internal service communication.

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[Client Browser/App] -->|HTTP Requests| GoBackend[Go Backend Server]
    GoBackend -->|Auth API Calls| STCore[SuperTokens Core]
    STCore -->|Read/Write Session Data| Postgres[(PostgreSQL Database)]
    GoBackend -->|Future Integration| S3[AWS S3 Storage]
    subgraph AWS EC2 Instance
        GoBackend
        STCore
        Postgres
    end

How it's built

The system uses a Shell script to orchestrate Docker containers for the database and auth core. The application logic is written in Go, utilizing the `supertokens-golang` SDK for auth flows and `gorilla/mux` for HTTP routing. Configuration is managed via environment variables loaded from a `.env` file.

How it runs

sequenceDiagram
    participant C as Client
    participant G as Go Backend
    participant S as SuperTokens Core
    participant D as PostgreSQL

    C->>G: POST /auth/login (email)
    G->>S: Create Magic Link Request
    S->>D: Store Pre-auth Session
    S-->>G: Return Magic Link URL
    G-->>C: Return Magic Link JSON
    
    C->>G: GET /auth/verify (link params)
    G->>S: Verify Session/Consume Link
    S->>D: Update Session Status
    S-->>G: Session Tokens
    G-->>C: Set Cookies/Return Tokens

How to apply & reuse

Use this repository as a template for setting up secure, passwordless login for Go-based microservices. It provides a ready-to-use Docker setup for the authentication backend and example code for integrating session handling into your API endpoints.

At a glance

CapabilitiesPasswordless LoginSession ManagementDocker OrchestrationAWS Deployment
ComponentsGo BackendSuperTokens CorePostgreSQLShell Setup ScriptStatic Frontend
TechGoSuperTokensDockerPostgreSQLAWS EC2Shell
Depends onDocker EngineGo RuntimeAWS Account
Integrates withAWS S3Nginx (Reverse Proxy)Let's Encrypt (SSL)
PatternsPasswordless AuthenticationMicroservices InfrastructureContainerized Deployment
Reuse tagsauthenticationgodockerawssupertokens

Repo hygiene

✓ all on main — nothing unmerged.