Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
bunq_psd2_oauth.php
<?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
You can’t perform that action at this time.