https://github.com/ndimensional/atproto-oauth-client-cloudflare-workers
https://github.com/ndimensional/atproto-oauth-client-cloudflare-workers
Last synced: 10 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/ndimensional/atproto-oauth-client-cloudflare-workers
- Owner: nDimensional
- License: mit
- Created: 2025-08-19T01:53:19.000Z (11 months ago)
- Default Branch: main
- Last Pushed: 2025-08-20T00:06:26.000Z (11 months ago)
- Last Synced: 2025-08-20T02:24:46.844Z (11 months ago)
- Language: TypeScript
- Size: 66.4 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# atproto-oauth-client-cloudflare-workers
This library contains local patched copies of
- [`@atproto/oauth-client-node`](https://github.com/bluesky-social/atproto/tree/main/packages/oauth/oauth-client-node)
- [`@atproto/oauth-client`](https://github.com/bluesky-social/atproto/tree/main/packages/oauth/oauth-client)
- [`@atproto-labs/handle-resolver-node`](https://github.com/bluesky-social/atproto/tree/main/packages/internal/handle-resolver-node)
- [`@atproto-labs/handle-resolver`](https://github.com/bluesky-social/atproto/tree/main/packages/internal/handle-resolver)
- [`@atproto-labs/identity-resolver`](https://github.com/bluesky-social/atproto/tree/main/packages/internal/identity-resolver)
- [`@atproto-labs/did-resolver`](https://github.com/bluesky-social/atproto/tree/main/packages/internal/did-resolver)
that are compatible with the Cloudflare Workers edge runtime.
The only changes applied throughout are:
1. replacing `request.cache: "no-cache"` with `request.headers["cache-control"]: "no-cache"`
2. replacing `request.redirect: "error"` with `request.redirect: "follow"`
DNS handle resolution requires the [`nodejs_compat` compatibility flag](https://developers.cloudflare.com/workers/runtime-apis/nodejs/).
## Usage
`WorkersOAuthClient` works mostly as a drop-in replacement for `NodeOAuthClient`.
```ts
import { WorkersOAuthClient } from "atproto-oauth-client-cloudflare-workers"
export const client = new WorkersOAuthClient({
clientMetadata: {
// ...
}
}
```
By default, like `NodeOAuthClient`, this will use an in-memory store for the handle cache and DID cache. This doesn't make much sense for the workers environment, since memory is reset after each invocation. To use Cloudflare KV namespaces for your handle and DID caches, create `DidCacheKV` and `HandleCacheKV` instances and pass them to the `WorkersOAuthClient` constructor.
Similarly, to use KV namespaces for the oauth state store and oauth session store, (which are required), import and provide `StateStoreKV` and `SessionStoreKV` instances.
```ts
import { env } from "cloudflare:workers"
import {
WorkersOAuthClient,
DidCacheKV,
HandleCacheKV,
StateStoreKV,
SessionStoreKV,
} from "atproto-oauth-client-cloudflare-workers";
export const client = new WorkersOAuthClient({
// did -> didDocument cache
didCache: new DidCacheKV(env.DID_CACHE),
// handle -> did cache
handleCache: new HandleCacheKV(env.HANDLE_CACHE),
clientMetadata: {
// Interface to store authorization state data (during authorization flows)
stateStore: new StateStoreKV(env.OAUTH_STATE_STORE),
// Interface to store authenticated session data
sessionStore: new SessionStoreKV(env.OAUTH_SESSION_STORE),
// ...
}
}
```