OAuth2/OIDC provider for Nostr NIP-07 authentication with Gitea
git clone https://git.smesh.lol/gitea-nostr-auth.git
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.
go build ./cmd/nostr-oauth2-server
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"
./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
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 build -t nostr-oauth2-server .
docker run -p 8080:8080 -v $(pwd)/config.yaml:/app/config.yaml nostr-oauth2-server
/authorize endpointwindow.nostr (NIP-07) to get pubkey and sign a challengeWhen Gitea requests user info, the server:
This ensures profiles are found even if only stored on the user's preferred relays.
Default relays used for initial queries (configurable):
wss://relay.nostr.band/wss://nostr.wine/wss://nos.lol/wss://relay.primal.net/wss://purplepag.es/| Endpoint | Description |
|---|---|
/.well-known/openid-configuration | OIDC discovery document |
/authorize | OAuth2 authorization (shows login page) |
/verify | Verify signed Nostr event |
/token | Exchange auth code for access token |
/userinfo | Get user profile (npub, username, email) |
This is free and unencumbered software released into the public domain (Unlicense).