@@ -375,15 +375,23 @@ public function validateIDToken($idToken){
375
375
* @param String $scope The scope of the key
376
376
* @return OAuth2AccessToken
377
377
*/
378
- public function OAuth1ToOAuth2Migration ($ consumerKey , $ consumerSecret , $ accessToken , $ accessTokenSecret , $ scope ){
378
+ public function OAuth1ToOAuth2Migration ($ consumerKey , $ consumerSecret , $ accessToken , $ accessTokenSecret , $ scope, $ redirectUri = null , $ environment = " Sandbox " ){
379
379
$ 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
+ }
380
389
$ parameters = array (
381
390
'scope ' => $ scope ,
382
- 'redirect_uri ' => " https://developer.intuit.com/v2/OAuth2Playground/RedirectUrl " ,
391
+ 'redirect_uri ' => $ redirectUri ,
383
392
'client_id ' => $ this ->getClientID (),
384
393
'client_secret ' => $ this ->getClientSecret ()
385
394
);
386
- $ baseURL = "https://developer.api.intuit.com/v2/oauth2/tokens/migrate " ;
387
395
$ authorizationHeaderInfo = $ oauth1Encrypter ->getOAuthHeader ($ baseURL , array (), "POST " );
388
396
$ http_header = array (
389
397
'Accept ' => 'application/json ' ,
@@ -425,7 +433,7 @@ private function parseNewAccessTokenFromResponse($body, $realmID = null){
425
433
$ refreshToken = $ json_body [CoreConstants::OAUTH2_REFRESH_GRANTYPE ];
426
434
$ refreshTokenExpiresTime = $ json_body [CoreConstants::X_REFRESH_TOKEN_EXPIRES_IN ];
427
435
$ 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 " ]) ){
429
437
$ idToken = $ json_body ["id_token " ];
430
438
$ result = $ this ->validateIDToken ($ idToken );
431
439
if (!$ result ){
0 commit comments