Skip to content
Zero dependency library for generating a Mastercard® API compliant OAuth signature in Swift
Branch: development
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

Mastercard OAuth 1.0 Signature Client


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



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


MastercardOAuth is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'MastercardOAuth'

You can then import the framework from Swift:

import MastercardOAuth

Note: Use of this library as a pod requires Xcode 10 or later.

Creating a valid OAuth Authorization header string

The method that does all the heavy lifting is OAuth.authorizationHeader(). 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 HTTP request's Authorization header.


To run the example project, first clone the repo and then pod install from the Example directory.

Example usage:

  let uri = URL(string: "")!
  let method = "GET"
  let examplePayload: [String: String] = ["languageId": 1,
                                          "geographicId": 0]
  let payloadJSON = (try? examplePayload, options: [])) ?? Data()
  let payloadString = String(data: payloadJSON, encoding: .utf8)
  let consumerKey = "<insert consumer key from developer portal>"
  let signingKey = "<initialize private key matching the consumer key>"

  let header = try? OAuth.authorizationHeader(forUri: uri, method: method, payload: payloadString, consumerKey: consumerKey, signingPrivateKey: myPrivateKey)

You can use the utility KeyProvider.swift to create a SecKey object representing your developer private key. Simply pass in the bundle path containing your Certificate.p12 to:

KeyProvider.loadPrivateKey(fromPath certificatePath: String, keyPassword: String) -> SecKey?


Luke Reichold,


MastercardOAuth is available under the MIT license. See the LICENSE file for more info.

You can’t perform that action at this time.