informeren/oauth2-mobilepay

MobilePay OAuth 2.0 Client Provider for The PHP League OAuth2-Client

1.4.1 2020-08-19 17:13 UTC

This package is auto-updated.

Last update: 2024-04-20 01:43:37 UTC


README

Build Status

This package provides MobilePay OAuth 2.0 support for the PHP League's OAuth 2.0 Client.

This package is compliant with PSR-1, PSR-4 and PSR-12. If you notice compliance oversights, please send a patch via pull request.

Requirements

The following versions of PHP are supported.

  • PHP 7.3
  • PHP 7.4

Install

Use composer to install the package:

$ composer require informeren/oauth2-mobilepay

Usage

$provider = new MobilePay([
    'clientId' => 'examplecompany',
    'clientSecret' => 'yxWIQHKjeEXW1ayL7kV77mh9YInAZNmSjJGuOrG69GE',
    'discoveryUri' => 'https://www.example.com/discovery',
    'redirectUri' => 'https://www.example.com/redirect',
]);

The clientId and clientSecret values are provided by MobilePay. The rest of the values are provided by you.

Create authorization URL

$url = $provider->getAuthorizationUrl([
    'scope' => ['openid', 'subscriptions', 'offline_access'],
    'response_type' => 'code id_token',
    'response_mode' => 'fragment',
    'code_verifier' => 'MVLkNAsW0uy5PnH3L3YwUzXqcPzMfNeKPIfD4K32MN4',
    'merchant_vat' => 'DK12345678',
]);

After the first request, you must use the same code_verifier value for all subsequent authorization requests, so store it in a safe place.

Open the resulting URL in a browser and accept the request. You will be redirected to the redirectUri and the authorization code will be available in the code URL parameter.

Use authorization code to get access token

$token = $provider->getAccessToken('authorization_code', [
    'code' => 'gDnCpS1n2tUB4D428D2v4Daw77mKm66N2xekzEBSmKzeDspdUfrNnCTFWuZ2Ly9F',
    'code_verifier' => 'MVLkNAsW0uy5PnH3L3YwUzXqcPzMfNeKPIfD4K32MN4',
]);

Refresh access token

$token = $provider->getAccessToken('refresh_token', [
    'refresh_token' => 'NDAwxVTnsE5KlHf4ganujXfG3EAAJkj0DquVuxXxZk6c4G1G0tIX8vQ40Jzxaq0j',
]);

Command-line interface

The package includes a simple command-line interface to the most common operations. Run it without arguments for usage instructions.

Use the following command to generate an authorization URL and open it in your default browser.

$ ./vendor/bin/mobilepay-auth authorize | xargs open

Testing

Tests can be run with:

$ composer test

Static analysis can be run with:

$ composer analyze

Style checks can be run with:

$ composer check

Documentation

License

The MIT License (MIT). Please see License File for more information.