Graphical PDS migrator for AT Protocol
1import { AtprotoOAuthClient } from "@bigmoves/atproto-oauth-client"; 2import { SessionStore, StateStore } from "../storage.ts"; 3 4/** 5 * Create the OAuth client. 6 * @param db - The Deno KV instance for the database 7 * @returns The OAuth client 8 */ 9export const createClient = (db: Deno.Kv) => { 10 if (Deno.env.get("NODE_ENV") == "production" && !Deno.env.get("PUBLIC_URL")) { 11 throw new Error("PUBLIC_URL is not set"); 12 } 13 14 const publicUrl = Deno.env.get("PUBLIC_URL"); 15 const url = publicUrl || `http://127.0.0.1:8000`; 16 const enc = encodeURIComponent; 17 18 return new AtprotoOAuthClient({ 19 clientMetadata: { 20 client_name: "Statusphere React App", 21 client_id: publicUrl 22 ? `${url}/oauth-client-metadata.json` 23 : `http://localhost?redirect_uri=${ 24 enc(`${url}/api/oauth/callback`) 25 }&scope=${enc("atproto transition:generic transition:chat.bsky")}`, 26 client_uri: url, 27 redirect_uris: [`${url}/api/oauth/callback`], 28 scope: "atproto transition:generic transition:chat.bsky", 29 grant_types: ["authorization_code", "refresh_token"], 30 response_types: ["code"], 31 application_type: "web", 32 token_endpoint_auth_method: "none", 33 dpop_bound_access_tokens: true, 34 }, 35 stateStore: new StateStore(db), 36 sessionStore: new SessionStore(db), 37 }); 38}; 39 40const kv = await Deno.openKv(); 41export const oauthClient = createClient(kv);