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