Skip to content

Commit c0871f3

Browse files
committed
fix #244
1 parent fa1436c commit c0871f3

File tree

2 files changed

+34
-4
lines changed

2 files changed

+34
-4
lines changed

src/Core/OAuth/OAuth2/OAuth2LoginHelper.php

+12-4
Original file line numberDiff line numberDiff line change
@@ -375,15 +375,23 @@ public function validateIDToken($idToken){
375375
* @param String $scope The scope of the key
376376
* @return OAuth2AccessToken
377377
*/
378-
public function OAuth1ToOAuth2Migration($consumerKey, $consumerSecret, $accessToken, $accessTokenSecret, $scope){
378+
public function OAuth1ToOAuth2Migration($consumerKey, $consumerSecret, $accessToken, $accessTokenSecret, $scope, $redirectUri = null, $environment = "Sandbox"){
379379
$oauth1Encrypter = new OAuth1($consumerKey, $consumerSecret, $accessToken, $accessTokenSecret);
380+
if(!isset($redirectUri)){
381+
$redirectUri = "https://developer.intuit.com/v2/OAuth2Playground/RedirectUrl";
382+
}
383+
384+
if(strcasecmp($environment, "Sandbox") == 0){
385+
$baseURL = "https://developer-sandbox.api.intuit.com/v2/oauth2/tokens/migrate";
386+
}else{
387+
$baseURL = "https://developer.api.intuit.com/v2/oauth2/tokens/migrate";
388+
}
380389
$parameters = array(
381390
'scope' => $scope,
382-
'redirect_uri' => "https://developer.intuit.com/v2/OAuth2Playground/RedirectUrl",
391+
'redirect_uri' => $redirectUri,
383392
'client_id' => $this->getClientID(),
384393
'client_secret' => $this->getClientSecret()
385394
);
386-
$baseURL = "https://developer.api.intuit.com/v2/oauth2/tokens/migrate";
387395
$authorizationHeaderInfo = $oauth1Encrypter->getOAuthHeader($baseURL, array(), "POST");
388396
$http_header = array(
389397
'Accept' => 'application/json',
@@ -425,7 +433,7 @@ private function parseNewAccessTokenFromResponse($body, $realmID = null){
425433
$refreshToken = $json_body[CoreConstants::OAUTH2_REFRESH_GRANTYPE];
426434
$refreshTokenExpiresTime = $json_body[CoreConstants::X_REFRESH_TOKEN_EXPIRES_IN];
427435
$accessToken = $json_body[CoreConstants::ACCESS_TOKEN];
428-
if(array_key_exists("id_token", $json_body)){
436+
if(array_key_exists("id_token", $json_body) && isset($json_body["id_token"]) && !empty($json_body["id_token"])){
429437
$idToken = $json_body["id_token"];
430438
$result = $this->validateIDToken($idToken);
431439
if(!$result){
+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
//Replace the line with require "vendor/autoload.php" if you are using the Samples from outside of _Samples folder
3+
include('../config.php');
4+
5+
use QuickBooksOnline\API\Core\ServiceContext;
6+
use QuickBooksOnline\API\DataService\DataService;
7+
use QuickBooksOnline\API\PlatformService\PlatformService;
8+
use QuickBooksOnline\API\Core\Http\Serialization\XmlObjectSerializer;
9+
10+
11+
$dataService = DataService::Configure(array(
12+
'auth_mode' => 'oauth2',
13+
'ClientID' => "L0I9uqpOVAXN0MKrK15dCHLWqqfvWzvFS5S0VnKezX0cDbsLlI",
14+
'ClientSecret' => "qJEjqG3wyzOFvl9WhwSnskJYHWoFlvID7k1iF1as",
15+
'RedirectURI' => "https://b200efd8.ngrok.io/OAuth2_c/OAuth_2/OAuth2PHPExample.php",
16+
'scope' => "com.intuit.quickbooks.accounting",
17+
'baseUrl' => "production"
18+
));
19+
20+
$OAuth2LoginHelper = $dataService->getOAuth2LoginHelper();
21+
$result = $OAuth2LoginHelper->OAuth1ToOAuth2Migration("qyprdfv4WnI3X47vpYJAkbvDKKT33J", "0mWGSoIWq2q8tDHEvmKjG34rBO8pqyhiJZdS1n4U", "qyprdEUxdMv94gvvJhQtZaCxJcU19RiEE9BLbVYBeicbWWis", "tKUFEl7fJTuzKrzgnouJYmqJaTSE31lgbGfY8hDb", "com.intuit.quickbooks.accounting", null, "Production");
22+
var_dump($result);

0 commit comments

Comments
 (0)