php - Yii 2 Oauth authentication without browser for Magento -


i'm trying oauth call magento 1.9 authclient extension. (see https://github.com/yiisoft/yii2-authclient)

this script redirects magento page have authenticate myself. possible automatically, script can run cronjob?

        try {             $callbackurl = "*********************/web/cronjob/syncmage";             $temporarycredentialsrequesturl = "*************/oauth/initiate?oauth_callback=" . urlencode($callbackurl);             $adminauthorizationurl = '**************/beheer/oauth_authorize';             $accesstokenrequesturl = '**************/oauth/token';             $apiurl = '*********/api/rest';             $consumerkey = '**************';             $consumersecret = '*****************';             $session = yii::$app->session;             if (!$session->isactive) {                 $session->open();             }              if (!isset($_get['oauth_token']) && isset($_session['state']) && $_session['state'] == 1) {                 $_session['state'] = 0;             }              if (!isset($session['state'])) {                 $session['state'] = false;             }             sleep(3);             $authtype = ($_session['state'] == 2) ? oauth_auth_type_authorization : oauth_auth_type_uri;             $oauthclient = new \oauth($consumerkey, $consumersecret, oauth_sig_method_hmacsha1, $authtype);             $oauthclient->enabledebug();             $oauthclient->disablesslchecks();              if (!isset($_get['oauth_token']) && !$_session['state']) {                 $requesttoken = $oauthclient->getrequesttoken($temporarycredentialsrequesturl);                 $_session['secret'] = $requesttoken['oauth_token_secret'];                 $_session['state'] = 1;                 header('location: ' . $adminauthorizationurl . '?oauth_token=' . $requesttoken['oauth_token']);                 exit;             } else if ($_session['state'] == 1) {                 $oauthclient->settoken($_get['oauth_token'], $_session['secret']);                 $accesstoken = $oauthclient->getaccesstoken($accesstokenrequesturl);                 $_session['state'] = 2;                 $_session['token'] = $accesstoken['oauth_token'];                 $_session['secret'] = $accesstoken['oauth_token_secret'];                 header('location: ' . $callbackurl);                 exit;             } else {                  $oauthclient->settoken($_session['token'], $_session['secret']);                 $resourceurl = "$apiurl/customers?page=".$page."&limit=".$limit;                 $activecontacts = [];                 $activecompanies = [];                  $userslist = $this->call($oauthclient, $resourceurl);                 if($userslist) {                     foreach($userslist $user) {                          $userid = $user->entity_id;                         array_push($activecontacts, $userid);                          $resourceurl = "$apiurl/customers/$userid/addresses";                         $addresslist = $this->call($oauthclient, $resourceurl);                          // contacts                         $dbcontact = magcontact::find()->where(['mag_id' => $userid])->one();                         //code....                      }                  }             }         } catch (\oauthexception $e) {             $this->dump($e->lastresponse);             $this->dump($e->getmessage());         }     


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -