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.

Clean up a bit

+22 -6
+11 -3
atsw.js
··· 118 118 headers: { "content-type": "application/x-www-form-urlencoded", DPoP: dpop }, 119 119 body, 120 120 }); 121 - dpopNonce = res.headers.get("dpop-nonce") ?? dpopNonce; 122 - if (res.ok || !res.headers.get("dpop-nonce")) return { json: await res.json(), dpopNonce }; 121 + 122 + const newNonce = res.headers.get("dpop-nonce"); 123 + const nonceChanged = newNonce && newNonce !== dpopNonce; 124 + dpopNonce = newNonce ?? dpopNonce; 125 + 126 + if (nonceChanged && 400 <= res.status && res.status <= 499) continue; 127 + 128 + return { json: await res.json(), dpopNonce }; 123 129 } 124 130 125 131 throw new Error("DPoP nonce retry failed"); ··· 407 413 408 414 let res = new Response(); 409 415 for (let attempt = 0; attempt < MAX_DPOP_RETRIES; attempt++) { 416 + if (attempt > 0) session = (await getSession(session.did)) ?? session; 417 + 410 418 const dpop = await createDPoP(session.dpopKey, htm, htu, session.dpopNonce, ath); 411 419 412 420 const headers = new Headers(req.headers); ··· 421 429 await putSession(session); 422 430 } 423 431 424 - if (res.status !== 401 || !session.dpopNonce) break; 432 + if (res.status !== 401) break; 425 433 } 426 434 427 435 return res;
+11 -3
example/atsw.js
··· 118 118 headers: { "content-type": "application/x-www-form-urlencoded", DPoP: dpop }, 119 119 body, 120 120 }); 121 - dpopNonce = res.headers.get("dpop-nonce") ?? dpopNonce; 122 - if (res.ok || !res.headers.get("dpop-nonce")) return { json: await res.json(), dpopNonce }; 121 + 122 + const newNonce = res.headers.get("dpop-nonce"); 123 + const nonceChanged = newNonce && newNonce !== dpopNonce; 124 + dpopNonce = newNonce ?? dpopNonce; 125 + 126 + if (nonceChanged && 400 <= res.status && res.status <= 499) continue; 127 + 128 + return { json: await res.json(), dpopNonce }; 123 129 } 124 130 125 131 throw new Error("DPoP nonce retry failed"); ··· 407 413 408 414 let res = new Response(); 409 415 for (let attempt = 0; attempt < MAX_DPOP_RETRIES; attempt++) { 416 + if (attempt > 0) session = (await getSession(session.did)) ?? session; 417 + 410 418 const dpop = await createDPoP(session.dpopKey, htm, htu, session.dpopNonce, ath); 411 419 412 420 const headers = new Headers(req.headers); ··· 421 429 await putSession(session); 422 430 } 423 431 424 - if (res.status !== 401 || !session.dpopNonce) break; 432 + if (res.status !== 401) break; 425 433 } 426 434 427 435 return res;