mollie/oauth2-mollie-php 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

mollie/oauth2-mollie-php

Composer 安装命令:

composer require mollie/oauth2-mollie-php

包简介

Mollie Provider for OAuth 2.0 Client

README 文档

README

Mollie-Logo-Style-Small

Mollie Connect in PHP

This package provides Mollie OAuth 2.0 support for the PHP League's OAuth 2.0 Client. Visit our API documentation for more information about the Mollie implementation of OAuth2.

Use Mollie Connect (OAuth) to easily connect Mollie Merchant accounts to your application. Mollie Connect also makes it possible to charge additional fees to your costumers with Application Fee.

Installation

By far the easiest way to install the Mollie API client is to require it with Composer.

$ composer require mollie/oauth2-mollie-php ^2.0

    {
        "require": {
            "mollie/oauth2-mollie-php": "^2.0"
        }
    }

You may also git checkout or download all the files, and include the OAuth 2.0 provider manually.

Usage

Usage is the same as The League's OAuth client, using \Mollie\OAuth2\Client\Provider\Mollie as the provider.

Authorization Code Flow

$provider = new \Mollie\OAuth2\Client\Provider\Mollie([
    'clientId'     => 'YOUR_CLIENT_ID',
    'clientSecret' => 'YOUR_CLIENT_SECRET',
    'redirectUri'  => 'https://your-redirect-uri',
]);

// If we don't have an authorization code then get one
if (!isset($_GET['code']))
{
    // Fetch the authorization URL from the provider; this returns the
    // urlAuthorize option and generates and applies any necessary parameters
    // (e.g. state).
    $authorizationUrl = $provider->getAuthorizationUrl([
        // Optional, only use this if you want to ask for scopes the user previously denied.
        'approval_prompt' => 'force',

        // Optional, a list of scopes. Defaults to only 'organizations.read'.
        'scope' => [
	    \Mollie\OAuth2\Client\Provider\Mollie::SCOPE_ORGANIZATIONS_READ,
	    \Mollie\OAuth2\Client\Provider\Mollie::SCOPE_PAYMENTS_READ,
	],
    ]);

    // Get the state generated for you and store it to the session.
    $_SESSION['oauth2state'] = $provider->getState();

    // Redirect the user to the authorization URL.
    header('Location: ' . $authorizationUrl);
    exit;
}

// Check given state against previously stored one to mitigate CSRF attack
elseif (empty($_GET['state']) || ($_GET['state'] !== $_SESSION['oauth2state']))
{
    unset($_SESSION['oauth2state']);
    exit('Invalid state');
}

else
{
    try
    {
        // Try to get an access token using the authorization code grant.
        $accessToken = $provider->getAccessToken('authorization_code', [
            'code' => $_GET['code']
        ]);

        // Using the access token, we may look up details about the resource owner.
        $resourceOwner = $provider->getResourceOwner($accessToken);

        print_r($resourceOwner->toArray());
    }
    catch (\League\OAuth2\Client\Provider\Exception\IdentityProviderException $e)
    {
        // Failed to get the access token or user details.
        exit($e->getMessage());
    }
}

Refreshing A Token

$provider = new \Mollie\OAuth2\Client\Provider\Mollie([
    'clientId'     => 'YOUR_CLIENT_ID',
    'clientSecret' => 'YOUR_CLIENT_SECRET',
    'redirectUri'  => 'https://your-redirect-uri',
]);

$grant = new \League\OAuth2\Client\Grant\RefreshToken();
$token = $provider->getAccessToken($grant, ['refresh_token' => $refreshToken]);

Authenticating using the AccessToken (mollie-api-php example)

After refreshing an AccessToken, here's how to use it with the mollie-api-php package. Note that the getToken() method is used to obtain the access token string.

$mollie = new \Mollie\Api\MollieApiClient;
$mollie->setAccessToken($token->getToken());

// With the correct scopes, you can now interact with Mollie's API on behalf of the Merchant
$payments = $mollie->payments->page();

Note

In order to access the mollie api via \Molie\Api\MollieApiClient, the mollie/mollie-api-php library is required!

Revoking a token

Both AccessTokens and RefreshTokens are revokable. Here's how to revoke an AccessToken:

$provider = new \Mollie\OAuth2\Client\Provider\Mollie([
    'clientId'     => 'YOUR_CLIENT_ID',
    'clientSecret' => 'YOUR_CLIENT_SECRET',
    'redirectUri'  => 'https://your-redirect-uri',
]);

$provider->revokeAccessToken($accessToken->getToken());

Similarly, here's how to revoke a RefreshToken:

Note: When you revoke a refresh token, all access tokens based on the same authorization grant will be revoked as well.

$provider = new \Mollie\OAuth2\Client\Provider\Mollie([
    'clientId'     => 'YOUR_CLIENT_ID',
    'clientSecret' => 'YOUR_CLIENT_SECRET',
    'redirectUri'  => 'https://your-redirect-uri',****
]);

$provider->revokeRefreshToken($refreshToken->getToken());

API documentation

If you wish to learn more about our APIs, please visit the Mollie Developer Portal.

Want to help us make our API client even better?

Want to help us make our API client even better? We take pull requests, sure. But how would you like to contribute to a technology oriented organization? Mollie is hiring developers and system engineers. Check out our vacancies or get in touch.

License

BSD (Berkeley Software Distribution) License. Copyright (c) 2015-2018, Mollie B.V.

Support

Contact: www.mollie.cominfo@mollie.com — +31 20-612 88 55

mollie/oauth2-mollie-php 适用场景与选型建议

mollie/oauth2-mollie-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.83M 次下载、GitHub Stars 达 26, 最近一次更新时间为 2015 年 11 月 13 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「authorization」 「api」 「client」 「oauth」 「oauth2」 「payment」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 mollie/oauth2-mollie-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 mollie/oauth2-mollie-php 我们能提供哪些服务?
定制开发 / 二次开发

基于 mollie/oauth2-mollie-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 1.83M
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 26
  • 点击次数: 40
  • 依赖项目数: 1
  • 推荐数: 5

GitHub 信息

  • Stars: 26
  • Watchers: 36
  • Forks: 15
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-2-Clause
  • 更新时间: 2015-11-13