this repo has no description
at main 53 lines 1.5 kB view raw
1/** 2 * AT Protocol OAuth client configuration 3 */ 4 5import { BrowserOAuthClient } from '@atproto/oauth-client-browser'; 6 7let oauthClient: BrowserOAuthClient | null = null; 8 9export function getOAuthClient(): BrowserOAuthClient { 10 if (oauthClient) return oauthClient; 11 12 oauthClient = new BrowserOAuthClient({ 13 clientMetadata: { 14 client_id: typeof window !== 'undefined' 15 ? `${window.location.origin}/client-metadata.json` 16 : 'https://attoshi.com/client-metadata.json', 17 client_name: '@toshi Wallet', 18 client_uri: 'https://attoshi.com', 19 redirect_uris: ['https://attoshi.com/wallet'], 20 scope: 'atproto', 21 grant_types: ['authorization_code', 'refresh_token'], 22 response_types: ['code'], 23 token_endpoint_auth_method: 'none', 24 application_type: 'web', 25 dpop_bound_access_tokens: true, 26 }, 27 handleResolver: 'https://bsky.social', 28 }); 29 30 return oauthClient; 31} 32 33export async function login(handle: string): Promise<void> { 34 const client = getOAuthClient(); 35 await client.signIn(handle, { 36 scope: 'atproto', 37 }); 38} 39 40export async function getSession() { 41 const client = getOAuthClient(); 42 const result = await client.init(); 43 return result?.session ?? null; 44} 45 46export async function logout(): Promise<void> { 47 const client = getOAuthClient(); 48 const result = await client.init(); 49 if (result?.session) { 50 // Clear the session 51 // The OAuth client handles cleanup internally 52 } 53}