mastercard/oauth1-signer
最新稳定版本:v1.1.4
Composer 安装命令:
composer require mastercard/oauth1-signer
包简介
Zero dependency library for generating a Mastercard API compliant OAuth signature.
README 文档
README
Table of Contents
Overview
Zero dependency library for generating a Mastercard API compliant OAuth signature.
Compatibility
PHP 5.6+
References
Versioning and Deprecation Policy
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
composer require mastercard/oauth1-signer
Loading the Signing Key
A private key object can be created by calling the AuthenticationUtils::loadSigningKey function:
use Mastercard\Developer\OAuth\Utils\AuthenticationUtils; // … $signingKey = AuthenticationUtils::loadSigningKey( '<insert PKCS#12 key file path>', '<insert key alias>', '<insert key password>');
Creating the OAuth Authorization Header
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.
use Mastercard\Developer\OAuth\OAuth; // … $consumerKey = '<insert consumer key>'; $uri = 'https://sandbox.api.mastercard.com/service'; $method = 'POST'; $payload = 'Hello world!'; $authHeader = OAuth::getAuthorizationHeader($uri, $method, $payload, $consumerKey, $signingKey);
Signing HTTP Client Request Objects
Alternatively, you can use helper classes for some of the commonly used HTTP clients.
These classes, provided in the Mastercard\Developer\Signers\ namespace, will modify the provided request object in-place and will add the correct Authorization header. Once instantiated with a consumer key and private key, these objects can be reused.
Usage briefly described below, but you can also refer to the test namespace for examples.
cURL
POST example
use Mastercard\Developer\Signers\CurlRequestSigner; // … $method = 'POST'; $uri = 'https://sandbox.api.mastercard.com/service'; $payload = json_encode(['foo' => 'bår']); $headers = array( 'Content-Type: application/json', 'Content-Length: ' . strlen($payload) ); $handle = curl_init($uri); curl_setopt_array($handle, array(CURLOPT_RETURNTRANSFER => 1, CURLOPT_CUSTOMREQUEST => $method, CURLOPT_POSTFIELDS => $payload)); $signer = new CurlRequestSigner($consumerKey, $signingKey); $signer->sign($handle, $method, $headers, $payload); $result = curl_exec($handle); curl_close($handle);
GET example
use Mastercard\Developer\Signers\CurlRequestSigner; // … $method = 'GET'; $baseUri = 'https://sandbox.api.mastercard.com/service'; $queryParams = array('param1' => 'with spaces', 'param2' => 'encoded#symbol'); $uri = $baseUri . '?' . http_build_query($queryParams); $handle = curl_init($uri); curl_setopt_array($handle, array(CURLOPT_RETURNTRANSFER => 1)); $signer = new CurlRequestSigner($consumerKey, $signingKey); $signer->sign($handle, $method); $result = curl_exec($handle); curl_close($handle);
GuzzleHttp
use GuzzleHttp\Psr7\Request; use Mastercard\Developer\Signers\PsrHttpMessageSigner; // … $payload = '{"foo":"bår"}'; $headers = ['Content-Type' => 'application/json']; $request = new Request('POST', 'https://sandbox.api.mastercard.com/service', $headers, $payload); $signer = new PsrHttpMessageSigner($consumerKey, $signingKey); $signer.sign($request);
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.
This project provides you with classes you can use when configuring your API client. These classes will take care of adding the correct Authorization header before sending the request.
Generators currently supported:
php
OpenAPI Generator
Client libraries can be generated using the following command:
openapi-generator-cli generate -i openapi-spec.yaml -g php -o out
See also:
Usage of the PsrHttpMessageSigner
use GuzzleHttp; use OpenAPI\Client\Api\ServiceApi; use OpenAPI\Client\Configuration use Mastercard\Developer\Signers\PsrHttpMessageSigner; // … $stack = new GuzzleHttp\HandlerStack(); $stack->setHandler(new GuzzleHttp\Handler\CurlHandler()); $stack->push(GuzzleHttp\Middleware::mapRequest([new PsrHttpMessageSigner($consumerKey, $signingKey), 'sign'])); $options = ['handler' => $stack]; $client = new GuzzleHttp\Client($options); $config = new Configuration(); $config->setHost('https://sandbox.api.mastercard.com'); $serviceApi = new ServiceApi($client, $config); // …
mastercard/oauth1-signer 适用场景与选型建议
mastercard/oauth1-signer 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 653.2k 次下载、GitHub Stars 达 4, 最近一次更新时间为 2026 年 01 月 04 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「oauth1」 「oauth1a」 「mastercard」 「openapi」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 mastercard/oauth1-signer 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 mastercard/oauth1-signer 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 mastercard/oauth1-signer 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Etsy API OAuth 1.0 Client Provider for The PHP League OAuth1-Client
OAuth 1.0 Client Library for Goodreads
This project enables OAuth v1.0 and v2.0 in a simple yet effective way.
Laravel package for the simplification and integration of many of your users most wanted login providers. Installation is a breeze. Never worry about OAuth again.
AWeber OAuth 1 Client Provider for The PHP League OAuth1-Client package
Alfabank REST API integration
统计信息
- 总下载量: 653.2k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 5
- 点击次数: 35
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-01-04