feat: serve latha-auth atproto OAuth client metadata
Build and Push Image / build (push) Successful in 40s

Add GET /oauth/atproto-client-metadata.json next to the existing OAuth
relay routes so AT Protocol authorization servers can resolve the
latha-auth public client (client_id is this URL).
This commit is contained in:
nandi committed 2026-11-18 06:20:41 +00:00
1 parent 4a9ec8b2ad
commit 6f3cb6777b
3 files changed
+70

No files matched your search

+28
View File
@@ -64,6 +64,34 @@ func (o *oauthRelayStore) pruneLocked(now time.Time) {
} }
} }
// atprotoClientMetadata is the OAuth Client ID Metadata Document for
// the latha-auth AT Protocol public client. It must stay available at
// exactly the client_id URL for the life of any session issued against
// it. Source of truth: `latha-auth atproto --print-client-metadata`.
var atprotoClientMetadata = struct {
ClientID string `json:"client_id"`
ClientName string `json:"client_name"`
GrantTypes []string `json:"grant_types"`
ResponseTypes []string `json:"response_types"`
RedirectURIs []string `json:"redirect_uris"`
Scope string `json:"scope"`
TokenEndpointAuthMethod string `json:"token_endpoint_auth_method"`
DPoPBoundAccessTokens bool `json:"dpop_bound_access_tokens"`
}{
ClientID: "https://deploy.site.latha.org/oauth/atproto-client-metadata.json",
ClientName: "latha-auth",
GrantTypes: []string{"authorization_code", "refresh_token"},
ResponseTypes: []string{"code"},
RedirectURIs: []string{"https://deploy.site.latha.org/oauth/callback"},
Scope: "atproto transition:generic",
TokenEndpointAuthMethod: "none",
DPoPBoundAccessTokens: true,
}
func (s *Server) handleAtprotoClientMetadata(w http.ResponseWriter, r *http.Request) {
writeJSON(w, http.StatusOK, atprotoClientMetadata)
}
func (s *Server) handleOAuthCallback(w http.ResponseWriter, r *http.Request) { func (s *Server) handleOAuthCallback(w http.ResponseWriter, r *http.Request) {
q := r.URL.Query() q := r.URL.Query()
if errParam := q.Get("error"); errParam != "" { if errParam := q.Get("error"); errParam != "" {
+41
View File
@@ -128,3 +128,44 @@ func TestOAuthRelayTTLExpiration(t *testing.T) {
t.Fatalf("expected expired entry to be rejected, got (%q, %v)", code, ok) t.Fatalf("expected expired entry to be rejected, got (%q, %v)", code, ok)
} }
} }
func TestAtprotoClientMetadata(t *testing.T) {
srv := newTestServer(t)
ts := httptest.NewServer(srv.Handler())
defer ts.Close()
resp, err := http.Get(ts.URL + "/oauth/atproto-client-metadata.json")
if err != nil {
t.Fatalf("get client metadata: %v", err)
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
t.Fatalf("expected 200, got %d", resp.StatusCode)
}
if ct := resp.Header.Get("Content-Type"); !strings.HasPrefix(ct, "application/json") {
t.Fatalf("expected application/json content type, got %q", ct)
}
body, err := io.ReadAll(resp.Body)
if err != nil {
t.Fatalf("read body: %v", err)
}
var out struct {
ClientID string `json:"client_id"`
RedirectURIs []string `json:"redirect_uris"`
Scope string `json:"scope"`
DPoPBoundAccessTokens bool `json:"dpop_bound_access_tokens"`
}
if err := json.Unmarshal(body, &out); err != nil {
t.Fatalf("unmarshal client metadata: %v", err)
}
// client_id must exactly match the public URL this is served from.
if out.ClientID != "https://deploy.site.latha.org/oauth/atproto-client-metadata.json" {
t.Fatalf("client_id = %q", out.ClientID)
}
if len(out.RedirectURIs) != 1 || out.RedirectURIs[0] != "https://deploy.site.latha.org/oauth/callback" {
t.Fatalf("redirect_uris = %v", out.RedirectURIs)
}
if !out.DPoPBoundAccessTokens {
t.Fatal("dpop_bound_access_tokens must be true")
}
}
+1
View File
@@ -55,6 +55,7 @@ func (s *Server) routes() {
s.mux.HandleFunc("GET /metrics", s.handleMetrics) s.mux.HandleFunc("GET /metrics", s.handleMetrics)
s.mux.HandleFunc("GET /oauth/callback", s.handleOAuthCallback) s.mux.HandleFunc("GET /oauth/callback", s.handleOAuthCallback)
s.mux.HandleFunc("GET /oauth/atproto-client-metadata.json", s.handleAtprotoClientMetadata)
s.mux.HandleFunc("GET /api/oauth/poll", s.handleOAuthPoll) s.mux.HandleFunc("GET /api/oauth/poll", s.handleOAuthPoll)
s.mux.HandleFunc("POST /webhook/gitea", s.handleGiteaWebhook) s.mux.HandleFunc("POST /webhook/gitea", s.handleGiteaWebhook)