Registry / security / axios-oauth-1.0a

axios-oauth-1.0a

JSON →
library0.4.1jsnpmunverified

Add OAuth 1.0a signing to axios requests via interceptors. Current stable version is 0.4.1, updated occasionally. Supports HMAC-SHA1 and HMAC-SHA256 algorithms, auto body hash for POST/PUT, optional realm, callback, verifier, and token secret. Ships TypeScript types, but requires polyfills for buffer and crypto in browsers. Alternative to oauth-1.0a with tighter axios integration, but depends on axios >=0.21.0.

npm install axios-oauth-1.0a
INSTALL
IMPORT
SIG · AXIOS-OAUTH-1.0A
A
axios-oauth-1.0a
securityjavascriptv0.4.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
✓ import addOAuthInterceptor from 'axios-oauth-1.0a';
✗ const addOAuthInterceptor = require('axios-oauth-1.0a');
Package exports a default function (ESM default export). CommonJS require also works in Node.js. TypeScript: import type is not provided.
addOAuthInterceptor
✓ import addOAuthInterceptor from 'axios-oauth-1.0a';
✗ import { addOAuthInterceptor } from 'axios-oauth-1.0a';
It is a default export, not named.
OAuthOptions
✓ import type { OAuthOptions } from 'axios-oauth-1.0a';
✗ import { OAuthOptions } from 'axios-oauth-1.0a';
OAuthOptions is a TypeScript type (interface), not a runtime value.

Creates an axios client with OAuth 1.0a interceptor using environment variables for credentials.

import axios from 'axios'; import addOAuthInterceptor from 'axios-oauth-1.0a'; const client = axios.create(); addOAuthInterceptor(client, { algorithm: 'HMAC-SHA256', key: process.env.OAUTH_KEY ?? '', secret: process.env.OAUTH_SECRET ?? '', token: process.env.OAUTH_TOKEN ?? '', tokenSecret: process.env.OAUTH_TOKEN_SECRET ?? '', includeBodyHash: 'auto', }); client.get('https://api.example.com/endpoint') .then(response => console.log(response.data)) .catch(error => console.error(error));
Debug
Known issues
gotchaRequires buffer and crypto polyfills in browser environments (Webpack 5 defaults no polyfills).
fix
Configure resolve.fallback in webpack.config.js: { buffer: require.resolve('buffer/'), crypto: require.resolve('crypto-browserify') } and install packages: npm install buffer crypto-browserify
affects: >=0.0.0
gotchaincludeBodyHash: 'auto' only hashes body on PUT/POST requests. Other methods will not include body hash regardless of setting.
fix
Set includeBodyHash: true if you need body hash on all methods (e.g., PATCH).
affects: >=0.0.0
deprecatedAlgorithm 'HMAC-SHA1' is deprecated and considered less secure. Prefer 'HMAC-SHA256'.
fix
Use algorithm: 'HMAC-SHA256'.
affects: >=0.0.0
gotchaPackage version 0.x may have breaking changes between minor versions. No major release yet.
fix
Pin to exact version or use lockfile. Check releases for breaking changes.
affects: >=0.0.0
Errors
Common errors & fixes
Error: Can't resolve 'buffer' in '/node_modules/axios-oauth-1.0a/dist'
Webpack 5 no longer includes Node.js polyfills by default.
fix
Add resolve.fallback for buffer and crypto in webpack config and install buffer and crypto-browserify packages.
TypeError: client.interceptors.request.use is not a function
Passed a regular axios instance or something that is not an axios client with interceptors.
fix
Ensure you pass an axios instance created via axios.create() or axios for interceptors to be added.
Upgrade
Version history
0.4.1latest on npm
Audit
Dependencies
axiosrequiredpeer dependency; package intercepts axios requests to sign them
Agent activity
21 hits · last 30 days
node
20
Resources
axios-oauth-1.0a — npm install axios-oauth-1.0a · libregistry