README.md raw

gitea-nostr-auth

An OAuth2/OIDC provider that enables Nostr NIP-07 browser extension authentication for Gitea. Allows users to sign in to Gitea using their Nostr identity.

Features

Quick Start

1. Build

go build ./cmd/nostr-oauth2-server

2. Configure

Copy config.example.yaml to config.yaml and update:

server:
  port: 8080
  base_url: "https://nostr-auth.example.com"

oauth2:
  clients:
    - client_id: "gitea"
      client_secret: "your-secure-secret"  # Generate with: openssl rand -hex 32
      redirect_uris:
        - "https://gitea.example.com/user/oauth2/nostr/callback"

3. Run

./nostr-oauth2-server -config config.yaml

Or with environment variables:

PORT=8080 \
BASE_URL=https://nostr-auth.example.com \
OAUTH2_CLIENT_ID=gitea \
OAUTH2_CLIENT_SECRET=your-secure-secret \
OAUTH2_REDIRECT_URIS=https://gitea.example.com/user/oauth2/nostr/callback \
./nostr-oauth2-server

4. Configure Gitea

Add the OAuth2 authentication source:

gitea admin auth add-oauth \
  --name "Nostr" \
  --provider openidConnect \
  --key "gitea" \
  --secret "your-secure-secret" \
  --auto-discover-url "https://nostr-auth.example.com/.well-known/openid-configuration"

Enable auto-registration in Gitea's app.ini:

[service]
DISABLE_REGISTRATION = false
ALLOW_ONLY_EXTERNAL_REGISTRATION = true

Docker

docker build -t nostr-oauth2-server .
docker run -p 8080:8080 -v $(pwd)/config.yaml:/app/config.yaml nostr-oauth2-server

How It Works

Authentication Flow

  1. User clicks "Login with Nostr" on Gitea
  2. Gitea redirects to nostr-oauth2-server's /authorize endpoint
  3. Login page uses window.nostr (NIP-07) to get pubkey and sign a challenge
  4. Server verifies signature and issues an OAuth2 authorization code
  5. Gitea exchanges code for access token and fetches user info
  6. User is logged in (or account is created if new)

Profile Fetching

When Gitea requests user info, the server:

  1. Fetches NIP-65 relay list (kind 10002) from fallback relays to find user's preferred relays
  2. Queries user's read relays + fallbacks for their profile (kind 0)
  3. Extracts profile data: name, display_name, picture, NIP-05, website, etc.
  4. Caches results for 24 hours to minimize relay queries

This ensures profiles are found even if only stored on the user's preferred relays.

Fallback Relays

Default relays used for initial queries (configurable):

API Endpoints

EndpointDescription
/.well-known/openid-configurationOIDC discovery document
/authorizeOAuth2 authorization (shows login page)
/verifyVerify signed Nostr event
/tokenExchange auth code for access token
/userinfoGet user profile (npub, username, email)

Security

License

This is free and unencumbered software released into the public domain (Unlicense).