From 5772bedb88189dd67a138397a73da8acbf8bd1e8 Mon Sep 17 00:00:00 2001 From: nandi <78769380+codegod100@users.noreply.github.com> Date: Wed, 18 Nov 2026 06:53:47 +0000 Subject: [PATCH] feat: host atproto client metadata from this repo via Gitea raw Default client_id now points at oauth/atproto-client-metadata.json in this repository, served at https://git.site.latha.org/experiments/latha-auth/raw/branch/main/oauth/atproto-client-metadata.json so no separate deploy is needed before first login. --- README.md | 2 +- internal/atproto/atproto_test.go | 4 ++-- internal/atproto/oauth.go | 12 +++++++----- oauth/atproto-client-metadata.json | 17 +++++++++++++++++ 4 files changed, 27 insertions(+), 8 deletions(-) create mode 100644 oauth/atproto-client-metadata.json diff --git a/README.md b/README.md index e5e77c0..c52122e 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ Zero-localhost OAuth CLI for remote VMs authenticating against Gitea (`git.site. - `latha-auth gitea`: Authenticates with Gitea via PKCE + the `https://deploy.site.latha.org/oauth/callback` relay, configures `tea login` (`latha`), and sets up git credentials. - `latha-auth k3s`: Runs Zitadel OAuth 2.0 Device Code flow for K3s Headlamp (`dash.latha.org`, `client_id=400047321930268787`) and saves the token to `~/.config/latha-auth/k3s-token.json` (`0600`). - `latha-auth oidc --client-id [--scope "..."] [--out ]`: Generic Zitadel Device Code flow for any `auth.site.latha.org` service. -- `latha-auth atproto --identifier [--scope "..."] [--out ]`: AT Protocol OAuth (PAR + PKCE + DPoP) as a public client, collecting the code via the same deploy relay. Saves the session — tokens plus the DPoP private key they are bound to — to `~/.config/latha-auth/atproto-session.json` (`0600`). One-time setup: host the output of `latha-auth atproto --print-client-metadata` at the client_id URL (default `https://deploy.site.latha.org/oauth/atproto-client-metadata.json`, override with `--client-id` or `LATHA_ATPROTO_CLIENT_ID`). +- `latha-auth atproto --identifier [--scope "..."] [--out ]`: AT Protocol OAuth (PAR + PKCE + DPoP) as a public client, collecting the code via the same deploy relay. Saves the session — tokens plus the DPoP private key they are bound to — to `~/.config/latha-auth/atproto-session.json` (`0600`). The client_id defaults to the metadata JSON versioned in this repo at `oauth/atproto-client-metadata.json` (served via Gitea raw; regenerate with `latha-auth atproto --print-client-metadata` after scope/redirect changes, or override with `--client-id` / `LATHA_ATPROTO_CLIENT_ID`). - `latha-auth atproto-token [--refresh] [--json]`: Prints a valid access token from the saved session, refreshing in place when expired. Note tokens are DPoP-bound: consumers must sign per-request DPoP proofs with the session key, so this is for DPoP-aware tooling. ## Install diff --git a/internal/atproto/atproto_test.go b/internal/atproto/atproto_test.go index 97bc551..e6eba63 100644 --- a/internal/atproto/atproto_test.go +++ b/internal/atproto/atproto_test.go @@ -174,7 +174,7 @@ func TestOAuthFlowResolvePARExchangeSaveRefresh(t *testing.T) { client := &OAuthClient{ HTTP: pds.Client(), Metadata: resolved.AuthServer, - ClientID: "https://deploy.site.latha.org/oauth/atproto-client-metadata.json", + ClientID: DefaultClientID, Key: key, } @@ -198,7 +198,7 @@ func TestOAuthFlowResolvePARExchangeSaveRefresh(t *testing.T) { authURL := BuildAuthorizeURL(resolved.AuthServer, client.ClientID, par.RequestURI) if !strings.HasPrefix(authURL, pds.URL+"/oauth/authorize?") || !strings.Contains(authURL, "request_uri=urn%3Aietf%3Aparams%3Aoauth%3Arequest_uri%3Areq-1") || - !strings.Contains(authURL, "client_id=https%3A%2F%2Fdeploy.site.latha.org") { + !strings.Contains(authURL, "client_id=https%3A%2F%2Fgit.site.latha.org") { t.Fatalf("authorize URL = %s", authURL) } diff --git a/internal/atproto/oauth.go b/internal/atproto/oauth.go index 4dea613..1262ae4 100644 --- a/internal/atproto/oauth.go +++ b/internal/atproto/oauth.go @@ -12,11 +12,13 @@ import ( ) const ( - // DefaultClientID is where the latha-auth client metadata JSON is - // expected to be hosted. Host the output of - // `latha-auth atproto --print-client-metadata` at this URL (or pass - // --client-id / LATHA_ATPROTO_CLIENT_ID). - DefaultClientID = "https://deploy.site.latha.org/oauth/atproto-client-metadata.json" + // DefaultClientID serves the client metadata JSON from this repo + // (oauth/atproto-client-metadata.json) via Gitea raw, so it is + // versioned with the client. Regenerate with + // `latha-auth atproto --print-client-metadata` after changing + // scope or redirect URIs, or pass --client-id / + // LATHA_ATPROTO_CLIENT_ID to use a different hosted copy. + DefaultClientID = "https://git.site.latha.org/experiments/latha-auth/raw/branch/main/oauth/atproto-client-metadata.json" // DefaultScope covers full repo writes and blob uploads (the old // app-password capability level), which publishing tiles needs. DefaultScope = "atproto transition:generic" diff --git a/oauth/atproto-client-metadata.json b/oauth/atproto-client-metadata.json new file mode 100644 index 0000000..f7aebaa --- /dev/null +++ b/oauth/atproto-client-metadata.json @@ -0,0 +1,17 @@ +{ + "client_id": "https://git.site.latha.org/experiments/latha-auth/raw/branch/main/oauth/atproto-client-metadata.json", + "client_name": "latha-auth", + "grant_types": [ + "authorization_code", + "refresh_token" + ], + "response_types": [ + "code" + ], + "redirect_uris": [ + "https://deploy.site.latha.org/oauth/callback" + ], + "scope": "atproto transition:generic", + "token_endpoint_auth_method": "none", + "dpop_bound_access_tokens": true +}