fetch-mw-oauth2 is a JavaScript library designed to simplify OAuth2 integration with the standard `fetch` API, handling automatic token acquisition and refreshing. Currently at v3.3.1, it supports `authorization_code`, `password`, and `client_credentials` grant types, offers robust error handling, OpenID Connect `id_token` exposure, and includes support for token revocation (RFC 7009) and the `resource` parameter (RFC 8707). Since its v3.0.0 release, the library is ESM-only and has ceased support for Node.js 14 and 16. It primarily functions as a `fetch` wrapper or middleware. This package is in maintenance mode, as development has shifted to its successor, `@badgateway/oauth2-client`, which offers enhanced features and similar functionality.
npm install fetch-mw-oauth2Verified import paths — ran on the pinned version, not inferred.
This example demonstrates how to set up `fetch-mw-oauth2` using the client_credentials grant to automatically handle OAuth2 authentication and fetch a protected resource. It utilizes environment variables for sensitive data.
Migrate your project to use ES Modules `import` syntax and ensure you are running Node.js 18 or newer. Update your `package.json` to include `"type": "module"`.
If experiencing issues, update to v3.1.0 or newer and consider setting `authorizationMethod` or switching to `client_secret_post` if your server has compatibility problems with strict Basic auth encoding.
Review `README.md` for `authorizationMethod` options if your server requires strict Basic encoding. Otherwise, consider `client_secret_post` for better compatibility.
Migrate your application to use `@badgateway/oauth2-client` for continued feature development and support.
Ensure you are using `fetch-mw-oauth2` v3.2.0 or newer for better browser compatibility with modern bundlers.
Upgrade to v3.3.1 or newer to avoid potential issues with concurrent endpoint discovery requests.
Change `const { OAuth2 } = require('fetch-mw-oauth2');` to `import { OAuth2 } from 'fetch-mw-oauth2';` and ensure your `package.json` specifies `"type": "module"` if running in Node.js.If on v3.0.0, your server might not handle strict encoding; upgrade to v3.1.0+. If on v3.1.0+, your server might require strict encoding; explicitly set the `authorizationMethod` option, or prefer the `client_secret_post` method if your server supports it.
Update your `fetch-mw-oauth2` dependency to version 3.2.0 or newer to resolve browser build issues with modern bundlers.
No dependency data recorded yet.