Something went wrong. Try again.
A live media wall for your Bluesky follows
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102import { BrowserOAuthClient, buildAtprotoLoopbackClientMetadata} from '@atproto/oauth-client-browser';
export const oauthReadEndpoints = [ 'app.bsky.actor.getPreferences', 'app.bsky.actor.getProfile', 'app.bsky.feed.getTimeline', 'app.bsky.feed.getAuthorFeed', 'app.bsky.feed.getPosts', 'app.bsky.feed.getPostThread', 'app.bsky.graph.getFollows', 'app.bsky.graph.getBlocks', 'app.bsky.labeler.getServices'] as const;
export const oauthInteractionScopes = [ 'repo:app.bsky.feed.like?action=create&action=delete', 'repo:app.bsky.feed.repost?action=create&action=delete', 'repo:app.bsky.graph.block?action=create&action=delete', 'repo:app.bsky.graph.follow?action=create&action=delete', ...[ 'app.bsky.bookmark.createBookmark', 'app.bsky.bookmark.deleteBookmark', 'app.bsky.graph.muteActor', 'app.bsky.graph.unmuteActor' ].map((endpoint) => `rpc:${endpoint}?aud=did:web:api.bsky.app%23bsky_appview`)] as const;
export const oauthScope = [ 'atproto', ...oauthReadEndpoints.map( (endpoint) => `rpc:${endpoint}?aud=did:web:api.bsky.app%23bsky_appview` ), ...oauthInteractionScopes].join(' ');
export function loopbackMetadata(url: URL) { if (url.hostname === 'localhost') url.hostname = '127.0.0.1'; return buildAtprotoLoopbackClientMetadata({ scope: oauthScope, redirect_uris: [`${url.origin}/`] });}
export function clientMetadata( origin: string): NonNullable<ConstructorParameters<typeof BrowserOAuthClient>[0]['clientMetadata']> { return { client_id: `${origin}/oauth-client-metadata.json`, client_name: 'Mural', client_uri: origin, redirect_uris: [`${origin}/`], scope: oauthScope, grant_types: ['authorization_code', 'refresh_token'], response_types: ['code'], token_endpoint_auth_method: 'none', application_type: 'web', dpop_bound_access_tokens: true };}
let initialization: | Promise<{ client: BrowserOAuthClient; result: Awaited<ReturnType<BrowserOAuthClient['init']>>; error?: string; }> | undefined;
export function initializeAuth() { initialization ??= (async () => { const local = ['localhost', '127.0.0.1', '[::1]'].includes(location.hostname); const origin = import.meta.env.VITE_APP_ORIGIN?.replace(/\/$/, ''); if (!local && origin !== location.origin) { throw new Error( 'Build with VITE_APP_ORIGIN set to this site’s HTTPS origin before logging in.' ); } const client = new BrowserOAuthClient({ handleResolver: 'https://bsky.social', clientMetadata: local ? loopbackMetadata(new URL(location.href)) : clientMetadata(location.origin) }); try { return { client, result: await client.init() }; } catch (cause) { return { client, result: undefined, error: cause instanceof Error ? cause.message : 'Session restoration failed. Please sign in again.' }; } })(); return initialization;}