Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

oauth-1.0a

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

oauth-1.0a

OAuth 1.0a Request Authorization for Node and Browser.

  • 2.2.6
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created

What is oauth-1.0a?

The oauth-1.0a npm package is a lightweight library for implementing OAuth 1.0a authentication in Node.js applications. It provides utilities for generating OAuth signatures, creating authorization headers, and handling the OAuth flow.

What are oauth-1.0a's main functionalities?

Generate OAuth Signature

This feature allows you to generate an OAuth signature for a given request. The code sample demonstrates how to create an OAuth instance, define the request data, and generate the signature using the consumer and token credentials.

const OAuth = require('oauth-1.0a');
const crypto = require('crypto');

const oauth = OAuth({
  consumer: { key: 'your-consumer-key', secret: 'your-consumer-secret' },
  signature_method: 'HMAC-SHA1',
  hash_function(base_string, key) {
    return crypto.createHmac('sha1', key).update(base_string).digest('base64');
  }
});

const request_data = {
  url: 'https://api.example.com/resource',
  method: 'GET'
};

const token = {
  key: 'your-access-token',
  secret: 'your-token-secret'
};

const signature = oauth.authorize(request_data, token);
console.log(signature);

Create Authorization Header

This feature allows you to create an OAuth authorization header for a given request. The code sample demonstrates how to generate the authorization header using the OAuth instance and the request data.

const OAuth = require('oauth-1.0a');
const crypto = require('crypto');

const oauth = OAuth({
  consumer: { key: 'your-consumer-key', secret: 'your-consumer-secret' },
  signature_method: 'HMAC-SHA1',
  hash_function(base_string, key) {
    return crypto.createHmac('sha1', key).update(base_string).digest('base64');
  }
});

const request_data = {
  url: 'https://api.example.com/resource',
  method: 'GET'
};

const token = {
  key: 'your-access-token',
  secret: 'your-token-secret'
};

const authorizationHeader = oauth.toHeader(oauth.authorize(request_data, token));
console.log(authorizationHeader);

Handle OAuth Flow

This feature demonstrates how to handle the OAuth flow to access a protected resource. The code sample shows how to generate the authorization header and make an authenticated request using the axios library.

const OAuth = require('oauth-1.0a');
const crypto = require('crypto');
const axios = require('axios');

const oauth = OAuth({
  consumer: { key: 'your-consumer-key', secret: 'your-consumer-secret' },
  signature_method: 'HMAC-SHA1',
  hash_function(base_string, key) {
    return crypto.createHmac('sha1', key).update(base_string).digest('base64');
  }
});

async function getProtectedResource() {
  const request_data = {
    url: 'https://api.example.com/resource',
    method: 'GET'
  };

  const token = {
    key: 'your-access-token',
    secret: 'your-token-secret'
  };

  const authorizationHeader = oauth.toHeader(oauth.authorize(request_data, token));

  try {
    const response = await axios.get(request_data.url, { headers: authorizationHeader });
    console.log(response.data);
  } catch (error) {
    console.error(error);
  }
}

getProtectedResource();

Other packages similar to oauth-1.0a

Keywords

FAQs

Package last updated on 05 Jun 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc