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.
The following versions of PHP are supported.
- PHP 7.3
- PHP 7.4
Use composer to install the package:
$ composer require informeren/oauth2-mobilepay
$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.
$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.
$token = $provider->getAccessToken('authorization_code', [
'code' => 'gDnCpS1n2tUB4D428D2v4Daw77mKm66N2xekzEBSmKzeDspdUfrNnCTFWuZ2Ly9F',
'code_verifier' => 'MVLkNAsW0uy5PnH3L3YwUzXqcPzMfNeKPIfD4K32MN4',
]);
$token = $provider->getAccessToken('refresh_token', [
'refresh_token' => 'NDAwxVTnsE5KlHf4ganujXfG3EAAJkj0DquVuxXxZk6c4G1G0tIX8vQ40Jzxaq0j',
]);
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
Tests can be run with:
$ composer test
Static analysis can be run with:
$ composer analyze
Style checks can be run with:
$ composer check
The MIT License (MIT). Please see License File for more information.