Scratch space for learning atproto app development
1import { NodeOAuthClient } from '@atproto/oauth-client-node'
2import type { Database } from '#/db'
3import { env } from '#/lib/env'
4import { SessionStore, StateStore } from './storage'
5
6export const createClient = async (db: Database) => {
7 const publicUrl = env.PUBLIC_URL
8 const url = publicUrl || `http://127.0.0.1:${env.PORT}`
9 const enc = encodeURIComponent
10 return new NodeOAuthClient({
11 clientMetadata: {
12 client_name: 'AT Protocol Express App',
13 client_id: publicUrl
14 ? `${url}/client-metadata.json`
15 : `http://localhost?redirect_uri=${enc(`${url}/oauth/callback`)}&scope=${enc('atproto transition:generic')}`,
16 client_uri: url,
17 redirect_uris: [`${url}/oauth/callback`],
18 scope: 'atproto transition:generic',
19 grant_types: ['authorization_code', 'refresh_token'],
20 response_types: ['code'],
21 application_type: 'web',
22 token_endpoint_auth_method: 'none',
23 dpop_bound_access_tokens: true,
24 },
25 stateStore: new StateStore(db),
26 sessionStore: new SessionStore(db),
27 })
28}