axios-oauth-client is a utility library designed to simplify the implementation of various OAuth 2.0 grant types when using the Axios HTTP client. Currently at version 2.2.0, it provides dedicated functions for common flows such as Authorization Code, Owner Credentials (Resource Owner Password Credentials), Client Credentials, and Refresh Token grants. The library integrates directly with Axios, allowing developers to instantiate OAuth client functions with an Axios instance, a token endpoint URL, and client credentials. It streamlines the process of obtaining access tokens by handling the underlying HTTP requests and OAuth 2.0 specific parameter encoding. A key differentiator is its straightforward, function-based API specifically tailored for Axios users, focusing on providing the primitives for token acquisition rather than a comprehensive OAuth client state management system. This means users are responsible for token storage, renewal logic, and attaching tokens to subsequent requests. It's built for Node.js environments (engines >= 14) and ships with TypeScript types, ensuring type safety for its users.
npm install axios-oauth-clientVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to obtain an access token using the Client Credentials grant and then refresh it.
Ensure 'axios' is installed: `npm install axios` or `yarn add axios`.
Implement an Axios interceptor or manual logic to store tokens, check expiry, refresh tokens, and attach the current access token to outbound requests.
Developers must explicitly call the appropriate grant function (e.g., `clientCredentials`, `refreshToken`) based on their application's current authentication state.
Install axios: `npm install axios` or `yarn add axios`.
Ensure you have a compatible version of Axios (e.g., `^1.2.1`) and that you are importing `axios` as a default import: `import axios from 'axios'`.
Verify all OAuth client credentials, endpoint URLs, and grant-specific parameters (like the authorization code or refresh token) are correct and match the configuration on your OAuth provider. Check the response body for specific error details from the OAuth server.