Zero dependency library for generating a Mastercard API compliant OAuth signature.
Node 6.12.3+
Body hash extension for non application/x-www-form-urlencoded payloads
Before using this library, you will need to set up a project and key in the Mastercard Developers Portal.
The two key pieces of information you will need are:
- Consumer key
- Private key matching the public key uploaded to Mastercard Developer Portal
The method that does all the heavy lifting is OAuth.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 from developer portal>";
const signingKey = "<initialize private key matching the consumer key>";
const uri = "https://sandbox.api.mastercard.com/service";
const method = "GET";
const payload = "Hello world!";
const authHeader = OAuth.getAuthorizationHeader(uri, method, payload, consumerKey, signingKey);