OAuth 2.1 Provider Framework for Cloudflare Workers This is a TypeScript library that implements the provider side of the OAuth 2.1 protocol with PKCE support. The library is intended to be used on Cloudflare Workers. Beta As of March, 2025, this library is very new, prerelease software. The API is still subject to change. Benefits of this library The library acts as a wrapper around your Worker code, which adds authorization for your API endpoints. All token management is handled automatically. Your API handler is written like a regular fetch handler, but receives the already-authenticated user details as a parameter. No need to perform any checks of your own. The library is agnostic to how you manage and authenticate users. The library is agnostic to how you build your UI. Your authorization flow can be implemented using whatever UI framework you use for everything else. The library's storage does not store any secrets, only hashes of them. Usage A Worker that uses the library might look like this: import { OAuthProvider } from "my-oauth" ; import { WorkerEntrypoint } from "cloudflare:workers" ; // We export the OAuthProvider instance as the entrypoint to our Worker. This means it // implements the `fetch()` handler, receiving all HTTP requests. export default new OAuthProvider ( { // Configure API routes. Any requests whose URL starts with any of these prefixes will be // considered API requests. The OAuth provider will check the access token on these requests, // and then, if the token is valid, send the request to the API handler. // You can provide: // - A single route (string) or multiple routes (array) // - Full URLs (which will match the hostname) or just paths (which will match any hostname) apiRoute : [ "/api/" , // Path only - will match any hostname "https://api.example.com/" // Full URL - will check hostname ] , // When the OAuth system receives an API request with a valid access token, it passes the request // to this handler object's fetch method. //...
First seen: 2025-06-03 04:38
Last seen: 2025-06-03 19:42