@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 04:45 UTC

main
ts 59 lines 2.92 KB
Raw
1 import { makeOAuthClient } from "alchemy/Auth/OAuthFlow";
2 import * as Redacted from "effect/Redacted";
3
4 export { OAuthCredentials, OAuthError, type Authorization } from "alchemy/Auth/OAuthFlow";
5
6 /**
7 * Registered PlanetScale OAuth application credentials.
8 *
9 * Unlike Cloudflare, PlanetScale OAuth has **no public-client flow** — the
10 * token endpoint requires client authentication for every grant (PKCE is
11 * advertised in their discovery doc but does not lift that requirement), so
12 * exchanging the authorization code (and refreshing the token) requires the
13 * application's `client_secret`. There is no way to keep that secret out of
14 * a distributed CLI, so it ships here: the exposure is the same posture as a
15 * public `client_id` (a stolen refresh token is usable, exactly like
16 * Cloudflare's secret-less refresh), and it can be rotated by cutting a new
17 * release. PlanetScale's own CLI ships its OAuth `client_secret` in source
18 * the same way:
19 * https://github.com/planetscale/cli/blob/main/internal/auth/authenticator.go
20 *
21 * Registered at https://app.planetscale.com with redirect URI
22 * {@link OAUTH_REDIRECT_URI}. Scopes are configured on the application
23 * itself, not requested per-authorization (so `authorize()` is called with
24 * no scopes). Rotate by registering a new secret and cutting a release.
25 */
26 export const OAUTH_CLIENT_ID = "pscale_app_aa12e3938baebb788aac443f66e422da";
27 export const OAUTH_CLIENT_SECRET = Redacted.make(
28 "pscale_app_secret_yyZ3Q8oe99GP9_yA5wrA5er6RuN6Lz9dC66Bj1OJzpg",
29 );
30
31 export const OAUTH_REDIRECT_URI = "https://alchemy.run/auth/callback";
32 export const OAUTH_LOCAL_CALLBACK_URI = "http://localhost:9976/auth/callback";
33 export const OAUTH_ENDPOINTS = {
34 // PlanetScale's own .well-known OAuth discovery doc declares this as
35 // the authorization_endpoint — NOT auth.planetscale.com/oauth/authorize
36 // (which their public docs cite). The auth.planetscale.com alias does
37 // render a consent screen but emits codes whose resulting tokens lack
38 // a `sub` claim, so the resource API at api.planetscale.com rejects
39 // them as invalid. Use the canonical endpoint.
40 authorize: "https://app.planetscale.com/oauth/authorize",
41 token: "https://auth.planetscale.com/oauth/token",
42 };
43
44 const client = makeOAuthClient({
45 clientId: OAUTH_CLIENT_ID,
46 endpoints: OAUTH_ENDPOINTS,
47 redirectUri: OAUTH_REDIRECT_URI,
48 localCallbackUri: OAUTH_LOCAL_CALLBACK_URI,
49 auth: { kind: "clientSecret", clientSecret: OAUTH_CLIENT_SECRET },
50 // PlanetScale's docs show the token endpoint with all parameters in the
51 // query string (https://planetscale.com/docs/api/reference/oauth). Their
52 // .well-known discovery doc advertises client_secret_basic /
53 // client_secret_post instead, but both behave identically to the
54 // query-string form in practice, so we follow the public docs literally.
55 tokenTransport: "query",
56 });
57
58 export const { authorize, callback, exchange, exchangeCallbackInput, refresh, usesCurrentClient } =
59 client;