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 return new NodeOAuthClient({
10 clientMetadata: {
11 client_name: 'AT Protocol Express App',
12 client_id: publicUrl
13 ? `${url}/client-metadata.json`
14 : `http://localhost?redirect_uri=${encodeURIComponent(`${url}/oauth/callback`)}`,
15 client_uri: url,
16 redirect_uris: [`${url}/oauth/callback`],
17 scope: 'profile offline_access',
18 grant_types: ['authorization_code', 'refresh_token'],
19 response_types: ['code'],
20 application_type: 'web',
21 token_endpoint_auth_method: 'none',
22 dpop_bound_access_tokens: true,
23 },
24 stateStore: new StateStore(db),
25 sessionStore: new SessionStore(db),
26 })
27}