Giter Club home page Giter Club logo

oauth1-signer-python's Introduction

oauth1-signer-python

Table of Contents

Overview

This is an alpha version of the Pyhon library for generating a Mastercard API compliant OAuth signature. As such it is a work-in-progress, not for commercial use, and unsupported. This warning will be removed when the bundle is finalised.

Compatibility

Python 3.7.x

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

PIP

pip3 install git+https://github.com/Mastercard/oauth1-signer-python.git

or Clone

git clone https://github.com/Mastercard/oauth1-signer-python.git

Change to the repo folder, and enter :

python3 setup.py install

Sample Code

The following code snippets show how to use this signing library to send messages to a Mastercard service.

Imports needed for the code snippets.
import sys
import requests
from oauth1.oauth import OAuth
import oauth1.authenticationutils as authenticationutils
import json
from urllib.parse import urlencode
Get a signing key from the .p12 file (replace place-holder strings with values from your project in developer zone).
signing_key = authenticationutils.load_signing_key('your-keyFile.p12', 'the-keystore-password')
consumer_key = 'your-consumer-key-from-devzone'

baseUrl = 'https://sandbox.api.mastercard.com' # remove 'sandbox.' if calling production
To send a GET with query parameters:
queryMap = {
        "Format": "XML",    # change this to toggle between and XML or JSON response
        "Details": "offers.easysavings",
        "PageOffset": "0",
        "PageLength": "5",
        "Latitude": "38.53463",
        "Longitude": "-90.286781"
        }
uri = baseUrl + "/merchants/v1/merchant?" + urlencode(queryMap)
header = OAuth().get_authorization_header(uri, 'GET', None, consumer_key, signing_key)
headers = {'Authorization': header, 'Content-Type': 'application/json'}

r = requests.get(uri, headers=headers)
print(r.text)
To send a POST to :
uri = baseUrl + "/eop/offer/v1/search?Format=XML" # change this to toggle between and XML or JSON response
reqBodyMap = {
        'OfferSearchCriteria': {
                'ItemsPerPage': 300,
                'Program': 'easysavings'
        }
}
reqJson = json.dumps(reqBodyMap)
header = OAuth().get_authorization_header(uri, 'POST', reqJson, consumer_key, signing_key)
headers = {'Authorization': header, 'Content-Type': 'application/json'}
r = requests.post(uri, headers=headers, data=reqJson)
print(r.text)

oauth1-signer-python's People

Contributors

jaaufauvre avatar karlingrammc avatar mickfgit avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.