Link bookmarking tool built on aproto (early alpha)
1import { config, isDev } from "@/lib/config"
2import { SessionStore, StateStore } from "./storage"
3import { AtprotoOAuthClient } from "@bigmoves/atproto-oauth-client"
4
5console.log("isDev:", isDev)
6
7export const createClient = () => {
8 const publicUrl = config.PUBLIC_URL
9 const url = publicUrl || `http://127.0.0.1:${config.PORT}`
10 const enc = encodeURIComponent
11
12 return new AtprotoOAuthClient({
13 clientMetadata: {
14 client_name: "Pinboarding",
15 client_id: !isDev
16 ? new URL(`/client-metadata.json`, publicUrl).toString()
17 : `http://localhost?redirect_uri=${
18 enc(`${url}/oauth/callback`)
19 }&scope=${enc("atproto transition:generic")}`,
20 client_uri: url,
21 redirect_uris: [`${url}/oauth/callback`],
22 scope: "atproto transition:generic",
23 grant_types: ["authorization_code", "refresh_token"],
24 response_types: ["code"],
25 application_type: "web",
26 token_endpoint_auth_method: "none",
27 dpop_bound_access_tokens: true,
28 },
29 stateStore: StateStore,
30 sessionStore: SessionStore,
31 })
32}
33
34export const oauthClient = createClient()