AT Protocol OAuth2 Go Example
This is a example project showing how to implement an Golang web service which uses atproto OAuth for authentication.
python-oauth-web-app is used as a reference for the implementation.
Docs
ATProto OAuth Docs
OAuth for AT Protocol
Prerequisites
- Go 1.22 or later
- A domain with HTTPS support (for production use)
- A Bluesky(or AT Protocol) account
Setup
- Clone the repository:
git clone https://github.com/potproject/atproto-oauth2-go-example.git
cd atproto-oauth2-go-example
- Install dependencies:
go mod download
- Generate a Secret JWK:
go run genKey/main.go
- Create a
.env
file based on .env.example
:
HOST=your-domain.com # Your domain
PORT=3000 # Port to run the server on
SECRET_JWK='...' # The Secret JWK generated in step 3
Running the Server
Start the server:
go run main.go
# However, you need a site that is actually published with https
The server will start on the specified port with the following endpoints:
/
: Login page
/login
: Handle login requests
/callback
: OAuth callback endpoint
/jwks.json
: JWKS endpoint
/client_metadata.json
: Client metadata endpoint
Flow
- User enters their Bluesky handle on the login page
- Server resolves the handle to a DID
- Server resolves the DID to a PDS (Personal Data Server)
- Server performs PAR with the PDS
- User is redirected to the Bluesky authorization page
- After authorization, user is redirected back to the callback endpoint
License
MIT