Something went wrong. Try again.
A lexicon-driven AppView for ATProto.
Something went wrong. Try again.
README.md
@happyview/oauth-client-browser #
Browser OAuth client for authenticating with a HappyView instance using AT Protocol.
Built on top of @happyview/oauth-client with Web Crypto and localStorage adapters included.
Installation #
npm install @happyview/oauth-client-browser
Usage #
Setup #
import { HappyViewBrowserClient } from "@happyview/oauth-client-browser";
const client = new HappyViewBrowserClient({
instanceUrl: "https://happyview.example.com",
clientKey: "hvc_your_client_key",
});
Login #
Redirects the user to their PDS authorization server:
await client.login("alice.bsky.social");
// User is redirected to their PDS for authorization
If you need the authorization URL without an immediate redirect (e.g., to open in a popup), use prepareLogin:
const { authorizationUrl, did, state } =
await client.prepareLogin("alice.bsky.social");
OAuth Callback #
On the /oauth/callback route, call callback() to complete the token exchange:
const session = await client.callback();
// Session is now stored in localStorage
Restore Session #
On subsequent page loads, restore the session from localStorage:
const session = await client.restore();
if (session) {
// User is still logged in
}
Authenticated Requests #
The session's fetchHandler attaches DPoP proof headers automatically. Pass it a path (relative to the HappyView instance) or a full URL:
const response = await session.fetchHandler(
"/xrpc/com.example.getStuff?limit=10",
{ method: "GET" },
);
Logout #
await client.logout("did:plc:abc123");
Exports #
This package re-exports everything from @happyview/oauth-client, plus:
HappyViewBrowserClient-- the main browser clientLocalStorageAdapter--StorageAdapterbacked bywindow.localStorageWebCryptoAdapter--CryptoAdapterbacked by the Web Crypto APIresolveHandleToDid-- resolve an AT Protocol handle to a DIDresolveDidDocument-- fetch a DID documentresolvePdsUrl-- extract the PDS URL from a DID documentresolveAuthServerMetadata-- fetch OAuth authorization server metadata from a PDS