All Projects → Mastercard → oauth1-signer-ruby

Mastercard / oauth1-signer-ruby

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

Programming Languages

ruby
36898 projects - #4 most used programming language

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

oauth1-signer-nodejs
Zero dependency library for generating a Mastercard API compliant OAuth signature.
Stars: ✭ 26 (+73.33%)
Mutual labels:  openapi, oauth1, mastercard, oauth1a
mastercard-api-client-tutorial
Generating and Configuring a Mastercard API Client
Stars: ✭ 25 (+66.67%)
Mutual labels:  openapi, mastercard
client-encryption-java
Library for Mastercard API compliant payload encryption/decryption.
Stars: ✭ 55 (+266.67%)
Mutual labels:  openapi, mastercard
client-encryption-nodejs
Library for Mastercard API compliant payload encryption/decryption.
Stars: ✭ 20 (+33.33%)
Mutual labels:  openapi, mastercard
apitte-openapi
👪 OpenAPI specification for Apitte stack
Stars: ✭ 15 (+0%)
Mutual labels:  openapi
swagger-spec
Spec for Swagger 2.0 definition
Stars: ✭ 17 (+13.33%)
Mutual labels:  openapi
openapicmd
The CLI for all things OpenAPI and Swagger
Stars: ✭ 24 (+60%)
Mutual labels:  openapi
intellij-openapi-generator
Intellij Plugin for openapi-generator
Stars: ✭ 73 (+386.67%)
Mutual labels:  openapi
abap-openapi-client
ABAP OpenAPI Client and Server generator in ABAP
Stars: ✭ 44 (+193.33%)
Mutual labels:  openapi
sanic-ext
Extended Sanic functionality
Stars: ✭ 26 (+73.33%)
Mutual labels:  openapi
cakephp-swagger-bake
Automatically generate OpenAPI, Swagger, and Redoc documentation from your existing CakePHP code.
Stars: ✭ 48 (+220%)
Mutual labels:  openapi
openapi-generator
An OpenAPI document generator. ⚙️
Stars: ✭ 22 (+46.67%)
Mutual labels:  openapi
openapi4j
OpenAPI 3 parser, JSON schema and request validator.
Stars: ✭ 92 (+513.33%)
Mutual labels:  openapi
mrapi
A framework for rapid development of API or DAL applications.
Stars: ✭ 20 (+33.33%)
Mutual labels:  openapi
openapi-types.ts
Generated TypeScript definitions based on GitHub's OpenAPI spec
Stars: ✭ 30 (+100%)
Mutual labels:  openapi
starlite
Light, Flexible and Extensible ASGI API framework
Stars: ✭ 1,525 (+10066.67%)
Mutual labels:  openapi
cookbook
VueJS + NodeJS Evergreen Cookbook
Stars: ✭ 440 (+2833.33%)
Mutual labels:  openapi
openapi-python-client
Generate modern Python clients from OpenAPI
Stars: ✭ 543 (+3520%)
Mutual labels:  openapi
oag
Idiomatic Go (Golang) client package generation from OpenAPI documents
Stars: ✭ 51 (+240%)
Mutual labels:  openapi
swagger-editor-validate
This GitHub Actions validates OpenAPI (OAS) definition file using Swagger Editor.
Stars: ✭ 30 (+100%)
Mutual labels:  openapi

oauth1-signer-ruby

Table of Contents

Overview

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

Compatibility

  • Ruby 2.4.4+
  • Truffle Ruby 1.0.0+

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

gem install mastercard_oauth1_signer

Loading the Signing Key

The following code shows how to load the private key using OpenSSL:

require 'openssl'

is = File.binread("<insert PKCS#12 key file path>");
signing_key = OpenSSL::PKCS12.new(is, "<insert key password>").key;

Creating the OAuth Authorization Header

The method that does all the heavy lifting is OAuth.get_authorization_header. 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.

require 'oauth'

consumer_key = "<insert consumer key>";
uri = "https://sandbox.api.mastercard.com/service";
method = "POST";
payload = "Hello world!";
authHeader = OAuth.get_authorization_header(uri, method, payload, consumer_key, signing_key);

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:

ruby

OpenAPI Generator

Client libraries can be generated using the following command:

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

See also:

Callback method Typhoeus.before

The Authorization header can be hooked into before a request run:

config = OpenapiClient::Configuration.default
api_client = OpenapiClient::ApiClient.new
config.basePath = "https://sandbox.api.mastercard.com"
api_client.config = config

Typhoeus.before { |request|
  authHeader =
      OAuth.get_authorization_header request.base_url, request.options[:method],
                                     request.options[:body], consumer_key, signing_key.key
  request.options[:headers] = request.options[:headers].merge({'Authorization' => authHeader})
}
    
serviceApi = service.ServiceApi.new api_client

opts = {}
serviceApi.call opts
// 

See also: https://rubydoc.info/github/typhoeus/typhoeus/frames/Typhoeus#before-class_method

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].