UNPKG

@atproto/oauth-client-browser

Version:

ATPROTO OAuth client for the browser (relies on WebCrypto & Indexed DB)

15 lines 737 B
import { isLoopbackHost } from '@atproto/oauth-types'; /** * @example * ```ts * const clientId = buildLoopbackClientId(window.location) * ``` */ export function buildLoopbackClientId(location, localhost = '127.0.0.1') { if (!isLoopbackHost(location.hostname)) { throw new TypeError(`Expected a loopback host, got ${location.hostname}`); } const redirectUri = `http://${location.hostname === 'localhost' ? localhost : location.hostname}${location.port && !location.port.startsWith(':') ? `:${location.port}` : location.port}${location.pathname}`; return `http://localhost${location.pathname === '/' ? '' : location.pathname}?redirect_uri=${encodeURIComponent(redirectUri)}`; } //# sourceMappingURL=util.js.map