Scratch space for learning atproto app development
1import { JoseKey } from '@atproto/jwk-jose'
2import { NodeOAuthClient } from '@atproto/oauth-client-node'
3import type { Database } from '#/db'
4import { env } from '#/env'
5import { SessionStore, StateStore } from './storage'
6
7export const createClient = async (db: Database) => {
8 const publicUrl = env.PUBLIC_URL
9 const url = publicUrl || `http://127.0.0.1:${env.PORT}`
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=${encodeURIComponent(`${url}/oauth/callback`)}`,
16 client_uri: url,
17 logo_uri: `${url}/logo.png`,
18 tos_uri: `${url}/tos`,
19 policy_uri: `${url}/policy`,
20 redirect_uris: [`${url}/oauth/callback`],
21 scope: 'profile offline_access',
22 grant_types: ['authorization_code', 'refresh_token'],
23 response_types: ['code'],
24 application_type: 'web',
25 token_endpoint_auth_method: 'none',
26 dpop_bound_access_tokens: true,
27 },
28 stateStore: new StateStore(db),
29 sessionStore: new SessionStore(db),
30 })
31}