Esempio n. 1
0
 /**
  * @covers OAuth\OAuth1\Service\OpenBankProject::__construct
  * @covers OAuth\OAuth1\Service\OpenBankProject::getRequestTokenEndpoint
  * @covers OAuth\OAuth1\Service\OpenBankProject::parseAccessTokenResponse
  */
 public function testParseAccessTokenResponseValid()
 {
     $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface');
     $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue('oauth_token=foo&oauth_token_secret=bar'));
     $token = $this->getMock('\\OAuth\\OAuth1\\Token\\TokenInterface');
     $storage = $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface');
     $storage->expects($this->any())->method('retrieveAccessToken')->will($this->returnValue($token));
     $service = new OpenBankProject($this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), $client, $storage, $this->getMock('\\OAuth\\OAuth1\\Signature\\SignatureInterface'));
     $this->assertInstanceOf('\\OAuth\\OAuth1\\Token\\StdOAuth1Token', $service->requestAccessToken('foo', 'bar', $token));
 }
Esempio n. 2
0
 * @author      Amir Duran <*****@*****.**>
 * @license     http://www.opensource.org/licenses/mit-license.html  MIT License
 */
use OAuth\OAuth1\Service\OpenBankProject;
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;