axios-oauth-1.0a
axios-oauth-1.0a copied to clipboard
Add per-request oauth and improve CJS support
This PR adds improved CJS support:
// rather than having to do this:
const { default: addOAuthInterceptor } = require('axios-oauth-1.0a');
// you can now do this:
const addOAuthInterceptor = require('axios-oauth-1.0a');
It also adds the ability to add/override oauth options per individual request:
// Create a client
const client = axios.create();
// Add interceptor
addOAuthInterceptor(client);
// send a signed request
client.get('https://example.com/example', {
algorithm: 'HMAC-SHA1',
key: 'someKey1',
secret: 'someSecret1',
}).then(...);
// send another signed request with a different key/secret
client.get('https://example.com/example', {
algorithm: 'HMAC-SHA1',
key: 'someKey2',
secret: 'someSecret2',
}).then(...);
OR:
// Create a client
const client = axios.create();
// Add interceptor
addOAuthInterceptor(client, {
algorithm: 'HMAC-SHA1',
key: 'xxx',
secret: 'yyy',
});
// send a signed request with the algorithm/key/secret set above, and token set below
client.get('https://example.com/example', {
token: 'someToken1'
}).then(...);
// send another signed request with a different token and added tokenSecret
client.get('https://example.com/example', {
token: 'someToken2',
tokenSecret: 'someTokenSecret'
}).then(...);
- Can you do this without checking in the generated resources? I am opposed to checking in built/generated files.
- Maybe there's a way to improve the CJS compatibility while avoiding the
module.exports =hack? Maybe have seperate exports for ESM and CJS clients? like in https://antfu.me/posts/publish-esm-and-cjs