@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 46 lines 1.63 KB
Raw
1 import { makeOAuthClient, type OAuthCredentials } from "alchemy/Auth/OAuthFlow";
2
3 /**
4 * The `cf` CLI's public Cloudflare OAuth client (no secret), shared with
5 * workers-sdk's `cf` login. New authorizations use the device flow
6 * (RFC 8628) against it.
7 */
8 export const OAUTH_CLIENT_ID = "cbca97e7-c331-4cdd-8fd8-e25a451b98bf";
9 /**
10 * Alchemy's previous Cloudflare OAuth client. Grants issued to it keep
11 * refreshing; a manual `profile refresh` re-authorizes them against
12 * {@link OAUTH_CLIENT_ID}.
13 */
14 export const LEGACY_OAUTH_CLIENT_ID = "e7e25ec474419def6ba38d2d2638b122";
15 export const OAUTH_ENDPOINTS = {
16 deviceAuthorization: "https://dash.cloudflare.com/oauth2/device/auth",
17 token: "https://dash.cloudflare.com/oauth2/token",
18 revoke: "https://dash.cloudflare.com/oauth2/revoke",
19 };
20
21 export { OAuthCredentials, OAuthError, type DeviceAuthorization } from "alchemy/Auth/OAuthFlow";
22
23 const client = makeOAuthClient({
24 clientId: OAUTH_CLIENT_ID,
25 endpoints: OAUTH_ENDPOINTS,
26 auth: { kind: "pkce" },
27 });
28
29 const legacyClient = makeOAuthClient({
30 clientId: LEGACY_OAUTH_CLIENT_ID,
31 endpoints: { token: OAUTH_ENDPOINTS.token, revoke: OAUTH_ENDPOINTS.revoke },
32 auth: { kind: "pkce" },
33 });
34
35 /**
36 * The client that can refresh and revoke `credentials`, or `undefined` when
37 * they were issued to a client Alchemy no longer knows.
38 */
39 export const clientFor = (credentials: Pick<OAuthCredentials, "clientId">) =>
40 credentials.clientId === OAUTH_CLIENT_ID
41 ? client
42 : credentials.clientId === LEGACY_OAUTH_CLIENT_ID
43 ? legacyClient
44 : undefined;
45
46 export const { deviceAuthorize, deviceToken, refresh, revoke, usesCurrentClient } = client;