simple atproto oauth for static svelte apps flo-bit.dev/svelte-atproto-client-oauth/
6
fork

Configure Feed

Select the types of activity you want to include in your feed.

test

+29 -9
+7 -9
src/lib/auth.svelte.ts
··· 1 1 import type { BrowserOAuthClient, OAuthSession } from '@atproto/oauth-client-browser'; 2 2 import type { Agent } from '@atproto/api'; 3 + import { metadata } from './client-metadata'; 3 4 4 5 const { MODE } = import.meta.env; 5 6 ··· 22 23 const { BrowserOAuthClient } = await import('@atproto/oauth-client-browser'); 23 24 const { Agent } = await import('@atproto/api'); 24 25 25 - const clientId = `http://localhost?${new URLSearchParams({ 26 - scope: 'atproto transition:generic', 27 - redirect_uri: Object.assign(new URL(window.location.origin), { 28 - hostname: '[::1]' 29 - }).href 30 - })}`; 26 + const clientId = `${window.location.origin}/svelte-atproto-client-oauth/client-metadata.json`; 27 + 28 + console.log(clientId); 31 29 32 - oauthClient = await BrowserOAuthClient.load({ 33 - clientId, 30 + oauthClient = new BrowserOAuthClient({ 31 + clientMetadata: metadata, 34 32 handleResolver: HANDLE_RESOLVER_URL, 35 - plcDirectoryUrl: PLC_DIRECTORY_URL, 36 33 allowHttp: MODE === 'development' || MODE === 'test' 37 34 }); 38 35 ··· 40 37 41 38 try { 42 39 const initResult = await oauthClient.init(); 40 + console.log(initResult); 43 41 if (initResult) { 44 42 data.session = initResult.session; 45 43 data.agent = new Agent(initResult.session);
+16
src/lib/client-metadata.ts
··· 1 + const url = 'https://flo-bit.dev/svelte-atproto-client-oauth'; 2 + 3 + export const metadata = { 4 + client_id: `${url}/client-metadata.json`, 5 + 6 + client_name: 'Svelte Atproto Client OAuth', 7 + 8 + redirect_uris: [url], 9 + 10 + scope: 'atproto', 11 + grant_types: ['authorization_code', 'refresh_token'], 12 + response_types: ['code'], 13 + token_endpoint_auth_method: 'none', 14 + application_type: 'web', 15 + dpop_bound_access_tokens: true 16 + };
+6
src/routes/client-metadata.json/+server.ts
··· 1 + import { metadata } from '$lib/client-metadata'; 2 + import { json } from '@sveltejs/kit'; 3 + 4 + export async function GET() { 5 + return json(metadata); 6 + }