All Projects → Mastercard → oauth1-signer-nodejs

Mastercard / oauth1-signer-nodejs

Licence: MIT license
Zero dependency library for generating a Mastercard API compliant OAuth signature.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to oauth1-signer-nodejs

oauth1-signer-ruby
Zero dependency library for generating a Mastercard API compliant OAuth signature.
Stars: ✭ 15 (-42.31%)
Mutual labels:  openapi, oauth1, mastercard, oauth1a
mastercard-api-client-tutorial
Generating and Configuring a Mastercard API Client
Stars: ✭ 25 (-3.85%)
Mutual labels:  openapi, mastercard
client-encryption-java
Library for Mastercard API compliant payload encryption/decryption.
Stars: ✭ 55 (+111.54%)
Mutual labels:  openapi, mastercard
client-encryption-nodejs
Library for Mastercard API compliant payload encryption/decryption.
Stars: ✭ 20 (-23.08%)
Mutual labels:  openapi, mastercard
apispots-extension
Chrome extensions for discovering and interacting with Open APIs
Stars: ✭ 41 (+57.69%)
Mutual labels:  openapi
openapi-definitions
OpenAPI Definitions
Stars: ✭ 30 (+15.38%)
Mutual labels:  openapi
cube
Common LISP Kubernetes Client
Stars: ✭ 33 (+26.92%)
Mutual labels:  openapi
awesome-integration
A curated list of awesome system integration software and resources.
Stars: ✭ 117 (+350%)
Mutual labels:  openapi
openapicmd
The CLI for all things OpenAPI and Swagger
Stars: ✭ 24 (-7.69%)
Mutual labels:  openapi
minos
Tool to test OpenAPI spec files VS real implementations
Stars: ✭ 17 (-34.62%)
Mutual labels:  openapi
sbt-lagom-descriptor-generator
Lagom API code generator
Stars: ✭ 23 (-11.54%)
Mutual labels:  openapi
loopback-next
LoopBack makes it easy to build modern API applications that require complex integrations.
Stars: ✭ 4,412 (+16869.23%)
Mutual labels:  openapi
nestjs-asyncapi
NestJS AsyncAPI module - generate the documentation of your event-based services using decorators
Stars: ✭ 88 (+238.46%)
Mutual labels:  openapi
symmetric
A powerful tool to enable super fast module-to-API transformations. Learn in minutes, implement in seconds. Batteries included.
Stars: ✭ 65 (+150%)
Mutual labels:  openapi
intellij-openapi-generator
Intellij Plugin for openapi-generator
Stars: ✭ 73 (+180.77%)
Mutual labels:  openapi
reedelk-runtime
Reedelk Runtime Platform Community Edition
Stars: ✭ 25 (-3.85%)
Mutual labels:  openapi
yaml-include
Valid, modular YAML documents with js-yaml. Seriously.
Stars: ✭ 39 (+50%)
Mutual labels:  openapi
openapi-filter
Filter internal paths, operations, parameters, schemas etc from OpenAPI/Swagger/AsyncAPI definitions
Stars: ✭ 112 (+330.77%)
Mutual labels:  openapi
php-pesa
Open payment integration toolkit for PHP
Stars: ✭ 26 (+0%)
Mutual labels:  openapi
openapi-viewer
Browse and test a REST API described with the OpenAPI 3.0 Specification
Stars: ✭ 85 (+226.92%)
Mutual labels:  openapi

oauth1-signer-nodejs

Table of Contents

Overview

Zero dependency library for generating a Mastercard API compliant OAuth signature.

Compatibility

Node 6.12.3+

There shouldn't be any Node compatibility issues with this package, but it's a good idea to keep your Node versions up-to-date. It is recommended that you use one of the LTS Node.js releases, or one of the more general recent releases. A Node version manager such as nvm (Mac and Linux) or nvm-windows is a good way to stay on top of this.

References

Usage

Prerequisites

Before using this library, you will need to set up a project in the Mastercard Developers Portal.

As part of this set up, you'll receive credentials for your app:

  • A consumer key (displayed on the Mastercard Developer Portal)
  • A private request signing key (matching the public certificate displayed on the Mastercard Developer Portal)

Adding the Library to Your Project

npm i mastercard-oauth1-signer

Loading the Signing Key

The following code shows how to load the private key using node-forge:

const forge = require("node-forge");
const fs = require("fs");
const p12Content = fs.readFileSync("<insert PKCS#12 key file path>", 'binary');
const p12Asn1 = forge.asn1.fromDer(p12Content, false);
const p12 = forge.pkcs12.pkcs12FromAsn1(p12Asn1, false, "<insert key password>");
const keyObj = p12.getBags({
    friendlyName: "<insert key alias>",
    bagType: forge.pki.oids.pkcs8ShroudedKeyBag
}).friendlyName[0];
const signingKey = forge.pki.privateKeyToPem(keyObj.key);

Creating the OAuth Authorization Header

The method that does all the heavy lifting is getAuthorizationHeader. You can call into it directly and as long as you provide the correct parameters, it will return a string that you can add into your request's Authorization header.

const consumerKey = "<insert consumer key>";
const uri = "https://sandbox.api.mastercard.com/service";
const method = "POST";
const payload = "Hello world!";

const oauth = require('mastercard-oauth1-signer');
const authHeader = oauth.getAuthorizationHeader(uri, method, payload, consumerKey, signingKey);

Integrating with OpenAPI Generator API Client Libraries

OpenAPI Generator generates API client libraries from OpenAPI Specs. It provides generators and library templates for supporting multiple languages and frameworks.

Generators currently supported:

javascript

OpenAPI Generator

Client libraries can be generated using the following command:

openapi-generator-cli generate -i openapi-spec.yaml -g javascript -o out

See also:

Overriding applyAuthToRequest

The Authorization header can be added before sending the requests by overriding the applyAuthToRequest function:

const service = require('../service/index.js');
const apiClient = require('../service/ApiClient.js');
const client = apiClient.instance;
client.basePath = "https://sandbox.api.mastercard.com";
client.applyAuthToRequest = function(request) {
    const _end = request._end;
    request._end = function() {
        const authHeader = oauth.getAuthorizationHeader(request.url, request.method, request._data, consumerKey, signingKey);
        request.req.setHeader('Authorization', authHeader);
        _end.call(request);
    }
    return request;
};
const serviceApi = new service.ServiceApi();
const opts = {}
const callback = function(error, data, response) {
    // …
};
serviceApi.call(opts, callback);
// …
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].