a tiny oauth browser client for atproto using a service worker
11
fork

Configure Feed

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

Remove configure function

+7 -28
+7 -8
README.md
··· 38 38 await navigator.serviceWorker.ready; 39 39 ``` 40 40 41 - Load your configuration from `client-metadata.json`: 42 - 43 - ```js 44 - import { configure } from "./atsw.js"; 45 - 46 - const config = await configure("./client-metadata.json"); 47 - ``` 48 - 49 41 ### Logging in 50 42 51 43 Pass the configuration and handle to `‌logIn`. It'll automatically redirect the user to their PDS: ··· 53 45 ```js 54 46 import { logIn } from "./atsw.js"; 55 47 48 + const config = { 49 + clientId: "https://example.com/client-metadata.json", 50 + redirectUri: "https://example.com", 51 + scope: "atproto repo?collection=com.atproto.server.getSession" 52 + }; 56 53 await logIn(config, "you.bsky.social"); 57 54 ``` 55 + 56 + The configuration must match the corresponding fields from `client-metadata.json`. 58 57 59 58 ### Resuming sessions 60 59
-10
atsw.js
··· 231 231 } 232 232 233 233 /** 234 - * Fetch client metadata and return an OAuth config. 235 - * @param {string} metadataUrl 236 - * @returns {Promise<OAuthConfig>} 237 - */ 238 - export async function configure(metadataUrl) { 239 - const m = await (await fetch(metadataUrl)).json(); 240 - return { clientId: m.client_id, redirectUri: m.redirect_uris[0], scope: m.scope }; 241 - } 242 - 243 - /** 244 234 * Start the OAuth login flow. Stores an authing session in IndexedDB and 245 235 * redirects the browser to the authorization server. When the auth server 246 236 * redirects back, the service worker will intercept the callback and complete
-10
example/atsw.js
··· 231 231 } 232 232 233 233 /** 234 - * Fetch client metadata and return an OAuth config. 235 - * @param {string} metadataUrl 236 - * @returns {Promise<OAuthConfig>} 237 - */ 238 - export async function configure(metadataUrl) { 239 - const m = await (await fetch(metadataUrl)).json(); 240 - return { clientId: m.client_id, redirectUri: m.redirect_uris[0], scope: m.scope }; 241 - } 242 - 243 - /** 244 234 * Start the OAuth login flow. Stores an authing session in IndexedDB and 245 235 * redirects the browser to the authorization server. When the auth server 246 236 * redirects back, the service worker will intercept the callback and complete