コード例 #1
0
ファイル: OauthTest.php プロジェクト: nosto/php-sdk
 /**
  * Test the OAuth client authenticate without a authorize code.
  */
 public function testOauthAuthenticateWithoutCode()
 {
     $meta = new NostoOAuthClientMetaData();
     $client = new NostoOAuthClient($meta);
     $this->specify('failed oauth authenticate', function () use($client) {
         $this->setExpectedException('NostoException');
         $client->authenticate('');
     });
 }
コード例 #2
0
ファイル: NostoAccount.php プロジェクト: buttasg/cowgirlk
 /**
  * @inheritdoc
  */
 public static function syncFromNosto(NostoOAuthClientMetaDataInterface $meta, $code)
 {
     $oauthClient = new NostoOAuthClient($meta);
     $token = $oauthClient->authenticate($code);
     if (empty($token->accessToken)) {
         throw new NostoException('No access token found when trying to sync account from Nosto');
     }
     if (empty($token->merchantName)) {
         throw new NostoException('No merchant name found when trying to sync account from Nosto');
     }
     $request = new NostoHttpRequest();
     // The request is currently not made according the the OAuth2 spec with the access token in the
     // Authorization header. This is due to the authentication server not implementing the full OAuth2 spec yet.
     $request->setUrl(NostoOAuthClient::$baseUrl . '/exchange');
     $request->setQueryParams(array('access_token' => $token->accessToken));
     $response = $request->get();
     $result = $response->getJsonResult(true);
     if ($response->getCode() !== 200) {
         Nosto::throwHttpException('Failed to sync account from Nosto.', $request, $response);
     }
     if (empty($result)) {
         throw new NostoException('Received invalid data from Nosto when trying to sync account');
     }
     $account = new self($token->merchantName);
     $account->tokens = NostoApiToken::parseTokens($result, 'api_');
     if (!$account->isConnectedToNosto()) {
         throw new NostoException('Failed to sync all account details from Nosto');
     }
     return $account;
 }
コード例 #3
0
ファイル: Account.php プロジェクト: ysilvela/php-sdk
 /**
  * Syncs an existing Nosto account via OAuth.
  *
  * Requires that the OAuth cycle has already completed the first step in getting the authorization code.
  *
  * @param NostoOauthClientMetaInterface $meta the OAuth client meta data to use for connection to Nosto.
  * @param string $authCode the authorization code that grants access to transfer data from Nosto.
  * @return NostoAccount the synced account.
  *
  * @throws NostoException on failure.
  */
 public function sync(NostoOauthClientMetaInterface $meta, $authCode)
 {
     $oauthClient = new NostoOAuthClient($meta);
     $token = $oauthClient->authenticate($authCode);
     $request = new NostoHttpRequest();
     // The request is currently not made according the the OAuth2 spec with the access token in the
     // Authorization header. This is due to the authentication server not implementing the full OAuth2 spec yet.
     $request->setUrl(NostoOAuthClient::$baseUrl . '/exchange');
     $request->setQueryParams(array('access_token' => $token->getAccessToken()));
     $response = $request->get();
     if ($response->getCode() !== 200) {
         throw Nosto::createHttpException('Failed to send account sync to Nosto.', $request, $response);
     }
     $result = $response->getJsonResult(true);
     $account = new NostoAccount($token->getMerchantName());
     $tokens = NostoApiToken::parseTokens($result, 'api_');
     foreach ($tokens as $token) {
         $account->addApiToken($token);
     }
     if (!$account->isConnectedToNosto()) {
         throw new NostoException('Failed to sync all account details from Nosto. Unknown error.');
     }
     return $account;
 }