Created
November 6, 2019 08:43
-
-
Save basst85/2d5304df8b63c0afecfaa72c41faf21c to your computer and use it in GitHub Desktop.
bunq_psd2_oauth.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use bunq\Context\ApiContext; | |
use bunq\Context\BunqContext; | |
use bunq\Model\Core\BunqEnumOauthResponseType; | |
use bunq\Model\Core\OauthAuthorizationUri; | |
use bunq\Model\Generated\Endpoint\OauthCallbackUrl; | |
use bunq\Model\Generated\Endpoint\OauthClient; | |
use bunq\Util\BunqEnumApiEnvironmentType; | |
use bunq\Util\FileUtil; | |
use bunq\Util\SecurityUtil; | |
require_once(__DIR__ . '/vendor/autoload.php'); | |
const PSD2_CONTEXT_CONF = 'conf_psd2.conf'; | |
const FILE_OAUTH_CONFIGURATION = 'oauth.conf'; | |
const CLIENT_DESCRIPTION = 'Psd2Test'; | |
const OAUTH_REDIRECT_URI = 'https://your_oauth_callback_url'; | |
/* | |
// Create new API context for PSD2 and save to conf file | |
$apiContext = ApiContext::createForPsd2( | |
BunqEnumApiEnvironmentType::SANDBOX(), | |
SecurityUtil::getCertificateFromFile('cert.pem'), | |
SecurityUtil::getPrivateKeyFromFile('key.pem'), | |
[ | |
SecurityUtil::getCertificateFromFile('cert.pem') | |
], | |
CLIENT_DESCRIPTION | |
); | |
$apiContext->save(PSD2_CONTEXT_CONF); | |
BunqContext::loadApiContext($apiContext); | |
*/ | |
$apiContext = ApiContext::restore(PSD2_CONTEXT_CONF); | |
BunqContext::loadApiContext($apiContext); | |
/* | |
// Create oAuth-client and save config to oauth.conf | |
$oauthClientIdResponse = OauthClient::create(); | |
$oauthClient = OauthClient::get($oauthClientIdResponse->getValue())->getValue(); | |
FileUtil::saveObjectAsJson(FILE_OAUTH_CONFIGURATION, $oauthClient); | |
*/ | |
// Read oAuth-client config | |
$oauthClient = FileUtil::readObjectFromJsonFile(FILE_OAUTH_CONFIGURATION, OauthClient::class); | |
/* | |
// Create the callback | |
OauthCallbackUrl::create( | |
$oauthClient->getId(), | |
OAUTH_REDIRECT_URI | |
); | |
*/ | |
// Create oAuth authorization URL | |
$oauthAuthorizationUri = OauthAuthorizationUri::create( | |
BunqEnumOauthResponseType::CODE(), | |
OAUTH_REDIRECT_URI, | |
$oauthClient | |
); | |
echo $oauthAuthorizationUri->getAuthorizationUriString(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment