/** * @covers OAuth\OAuth1\Service\OpenBankProject::__construct * @covers OAuth\OAuth1\Service\OpenBankProject::getRequestTokenEndpoint * @covers OAuth\OAuth1\Service\OpenBankProject::parseRequestTokenResponse * @covers OAuth\OAuth1\Service\OpenBankProject::parseAccessTokenResponse */ public function testParseRequestTokenResponseValid() { $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue('oauth_callback_confirmed=true&oauth_token=foo&oauth_token_secret=bar')); $service = new OpenBankProject($this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), $client, $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface'), $this->getMock('\\OAuth\\OAuth1\\Signature\\SignatureInterface')); $this->assertInstanceOf('\\OAuth\\OAuth1\\Token\\StdOAuth1Token', $service->requestRequestToken()); }
use OAuth\Common\Storage\Session; use OAuth\Common\Consumer\Credentials; use OAuth\OAuth1\Signature\Signature; /** * Bootstrap the example */ require_once __DIR__ . '/bootstrap.php'; // Session storage, for testing purposes I choose Session. You can extend TokenStorageInterface and make connection with DB $storage = new Session(); // Setup the credentials for the requests $credentials = new Credentials($servicesCredentials['openBankProject']['key'], $servicesCredentials['openBankProject']['secret'], $currentUri->getAbsoluteUri()); $openBankProjectService = new OpenBankProject($credentials, new \OAuth\Common\Http\Client\CurlClient(), $storage, new Signature($credentials)); if (!empty($_GET['oauth_token'])) { var_dump($_SESSION); $token = $storage->retrieveAccessToken('OpenBankProject'); // Get access token $openBankProjectService->requestAccessToken($_GET['oauth_token'], $_GET['oauth_verifier'], $token->getRequestTokenSecret()); var_dump(json_decode($openBankProjectService->request('https://apisandbox.openbankproject.com/obp/v1.2.1/banks'), true)); //Call some standard API exit; } elseif (!empty($_GET['go']) && $_GET['go'] === 'go') { // Obtain request token $token = $openBankProjectService->requestRequestToken(); $url = $openBankProjectService->getAuthorizationUri(array('oauth_token' => $token->getRequestToken())); header('Location: ' . $url); //Redirect to the Authentification server exit; } else { $url = $currentUri->getRelativeUri() . '?go=go'; echo "<a href='{$url}'>Login with Open Project API!</a>"; }