public function GetAuthResponse($params) { if (isset($params[self::CODE]) && $params[self::CODE] != 400) { // echo __METHOD__ . __LINE__ . " user id {$usr_id} / CODE {$params['code']} user brands <br>"; $STATE = isset($params[self::STATE]) ? $params[self::STATE] : null; /* * Get Application credentials: client id / client secret */ $oMediaClients = new \Av\ClientCredentialsModel(); $params_credentials = array(\Av\ClientCredentialsModel::MEDIA_ID => \Av\MediaModel::MEDIA_FACEBOOK); $credential = $oMediaClients->GetCredentials($params_credentials); $APP_ID = isset($credential[\Av\ClientCredentialsModel::CLIENT_ID]) ? $credential[\Av\ClientCredentialsModel::CLIENT_ID] : null; $APP_SECRET = isset($credential[\Av\ClientCredentialsModel::CLIENT_SECRET]) ? $credential[\Av\ClientCredentialsModel::CLIENT_SECRET] : null; if (!isset($APP_ID) || !isset($APP_SECRET)) { throw new FacebookSDKException('You must fill out the CLIENT credentials'); } FacebookSession::setDefaultApplication($APP_ID, $APP_SECRET); require_once 'Facebook/FacebookRedirectLoginHelper.php'; /* * Get callback end point */ $oCallBackUrl = new \Av\MediaAuthCallbackUrlModel(); $params_callback_url = array(\Av\MediaAuthCallbackUrlModel::MEDIA_ID => \Av\MediaModel::MEDIA_FACEBOOK, \Av\MediaAuthCallbackUrlModel::AUTH_TYPE_ID => \Av\MediaAuthTypeModel::AUTH_TYPE_SIGNUP); $callback_url = $oCallBackUrl->GetMediaAuthCallbackUrl($params_callback_url); if ($callback_url === false) { throw new FacebookSDKException("Callback Url for media FACEBOOK and Authorization type Signup is not set"); } $helper = new FacebookRedirectLoginHelper($callback_url); try { $session = $helper->getSessionFromRedirect(); $ACCESS_TOKEN = $session->getToken(); $this->service_auth->SetToken($ACCESS_TOKEN); if (isset($params[self::STATE])) { $arrState = \Av\UrlControllerHelper::unpackParamFromUrl($params[self::STATE]); $this->service_auth->SetState($arrState); } } catch (FacebookRequestException $ex) { echo __METHOD__ . __LINE__ . " Facebook Authentication error <br><pre>"; var_dump($ex); echo "</pre>"; return; } catch (\Exception $ex) { echo __METHOD__ . __LINE__ . " Facebook error during authentication <br><pre>"; var_dump($ex); echo "</pre>"; return; } $params_access_token = array(self::AUTH_TOKEN => $ACCESS_TOKEN); try { $this->service_person->MeAction($params_access_token); } catch (FacebookRequestException $e) { echo __METHOD__ . __LINE__ . " Facebook error during getting person info <br><pre>"; var_dump($e); echo "</pre>"; return; } // get granted permissions try { $this->service_person->PermissionsAction($params_access_token); } catch (FacebookRequestException $e) { echo __METHOD__ . __LINE__ . " Facebook error during getting permissions <br><pre>"; var_dump($e); echo "</pre>"; return; } } else { echo __METHOD__ . __LINE__ . " Facebook CODE is not set or set to 400<br>"; } }
public function GetAuthResponse($params) { if (isset($params[self::CODE]) && $params[self::CODE] != 400) { $this->AddDebug(__METHOD__ . " #" . __LINE__ . " response :" . print_r($params, true)); // echo __METHOD__ . __LINE__ . self " user id {$usr_id} / CODE {$params['code']} user brands <br> are: <br><pre>"; var_dump($oauth); echo "</pre>"; $CODE = $params[self::CODE]; $STATE = isset($params[self::STATE]) ? \Av\UrlControllerHelper::unpackParamFromUrl($params[self::STATE]) : null; $GOOGLE_MEDIA_ID = isset($STATE[self::MEDIA_ID]) ? $STATE[self::MEDIA_ID] : null; if (!isset($GOOGLE_MEDIA_ID)) { throw new \Google_Exception("Got invalid Google Media Id from 'state'"); } // 1. Get Google media id ( youtube,calendar,G+...) from state /* * Get Application credentials: client id / client secret */ $oMediaClients = new \Av\ClientCredentialsModel(); $params_credentials = array(\Av\ClientCredentialsModel::MEDIA_ID => $GOOGLE_MEDIA_ID); $credential = $oMediaClients->GetCredentials($params_credentials); $CLIENT_ID = isset($credential[\Av\ClientCredentialsModel::CLIENT_ID]) ? $credential[\Av\ClientCredentialsModel::CLIENT_ID] : null; $CLIENT_SECRET = isset($credential[\Av\ClientCredentialsModel::CLIENT_SECRET]) ? $credential[\Av\ClientCredentialsModel::CLIENT_SECRET] : null; if (!isset($CLIENT_ID) || !isset($CLIENT_SECRET)) { throw new \Google_Exception('You must fill out the CLIENT credentials'); } /* * Get callback end point */ $oCallBackUrl = new \Av\MediaAuthCallbackUrlModel(); $params_callback_url = array(\Av\MediaAuthCallbackUrlModel::MEDIA_ID => $GOOGLE_MEDIA_ID, \Av\MediaAuthCallbackUrlModel::AUTH_TYPE_ID => \Av\MediaAuthTypeModel::AUTH_TYPE_SIGNUP); $CALBACK_URL = $oCallBackUrl->GetMediaAuthCallbackUrl($params_callback_url); if ($CALBACK_URL === false) { throw new \Google_Exception("Callback Url for media FACEBOOK and Authorization type Signup is not set"); } $client = new \Google_Client(); $client->setClientId($CLIENT_ID); $client->setClientSecret($CLIENT_SECRET); $client->setRedirectUri($CALBACK_URL); // $client->setScopes(self::getScope()); // $client->setAccessType(self::getAccessTypeOffline()); $client->authenticate($CODE); $access_token = $client->getAccessToken(); $token = json_decode($access_token); $this->service_auth->SetToken($access_token); if (isset($token->{\Av\MediaUserModel::REFRESH_TOKEN})) { $this->service_auth->SetRefreshToken($token->{\Av\MediaUserModel::REFRESH_TOKEN}); } if (isset($STATE)) { $this->service_auth->SetState($STATE); } if (!isset($GOOGLE_MEDIA_ID)) { throw new \Google_Exception("Got invalid GOOGLE MEDIA ID from 'state'"); } // Only G+ provides peron's information if ($GOOGLE_MEDIA_ID == \Av\MediaModel::MEDIA_GOOGLE_PLUS) { $params_access_token = array(self::AUTH_TOKEN => $access_token); $this->service_person->MeAction($params_access_token); } $this->AddDebug(__METHOD__ . " #" . __LINE__ . " access token :" . print_r($access_token, true)); // echo __METHOD__ . __LINE__ . " access token saved with status {$ok} <br><pre>"; var_dump($access_token); echo "</pre>"; // $access_token = $oAuthObj->authorizeToken($cDB, $code, $cAuth->szURL); // $oAuthObj->saveAuthorization($cDB, $access_token, $cAuth->szURL); } else { if (isset($params['error'])) { $statusMessage = "Authorization Error. "; $statusMessage .= $EEEOR_DELIMITER . $_GET['error']; $statusMessage .= $EEEOR_DELIMITER . $_GET['error_reason']; $statusMessage .= $EEEOR_DELIMITER . $_GET['error_description']; $this->AddDebug(__METHOD__ . " #" . __LINE__ . " error:" . print_r($statusMessage, true)); // echo __METHOD__ . " #" .__LINE__ . " heartsoul brand authorization error <br><pre>"; var_dump($statusMessage); echo "</pre>"; } else { if ($params['code'] == 400) { $statusMessage = "Authorization Error 400. "; $statusMessage = $EEEOR_DELIMITER . $_GET['code']; $statusMessage = $EEEOR_DELIMITER . $_GET['error_type']; $statusMessage = $EEEOR_DELIMITER . $_GET['error_message']; $this->AddDebug(__METHOD__ . " #" . __LINE__ . " bad code :" . print_r($statusMessage, true)); // echo __METHOD__ . " #" . __LINE__ . " heartsoul brand authorization error <br><pre>"; var_dump($statusMessage); echo "</pre>"; } } } }
public function GetLink($params = null) { /* * Good chance to read some extra parameners from $params */ if (isset($params)) { } /* * Get main parameters set in constractor */ $MEDIA_ID = $this->GetMediaID(); $AUTH_TYPE_ID = $this->GetAuthTypeID(); $STATE = $this->GetState(); if (empty($MEDIA_ID) || empty($AUTH_TYPE_ID)) { return false; } /* * Get Application credentials: client id / client secret */ $oMediaClients = new \Av\ClientCredentialsModel(); $params_credentials = array(\Av\ClientCredentialsModel::MEDIA_ID => $MEDIA_ID); $credential = $oMediaClients->GetCredentials($params_credentials); if (isset($credential[\Av\ClientCredentialsModel::CLIENT_ID])) { $this->SetClientId($credential[\Av\ClientCredentialsModel::CLIENT_ID]); } if (isset($credential[\Av\ClientCredentialsModel::CLIENT_SECRET])) { $this->SetClientSecret($credential[\Av\ClientCredentialsModel::CLIENT_SECRET]); } /* * Get authorization scope */ $oScope = new \Av\MediaAuthScopeModel(); $params_scope = array(\Av\MediaAuthScopeModel::MEDIA_ID => $MEDIA_ID, \Av\MediaAuthScopeModel::AUTH_TYPE_ID => $AUTH_TYPE_ID); $scope = $oScope->GetMediaAuthScope($params_scope); if ($scope !== false) { $this->SetScope($scope); } /* * Get callback end point */ $oCallBackUrl = new \Av\MediaAuthCallbackUrlModel(); $params_callback_url = array(\Av\MediaAuthCallbackUrlModel::MEDIA_ID => $MEDIA_ID, \Av\MediaAuthCallbackUrlModel::AUTH_TYPE_ID => $AUTH_TYPE_ID); $callback_url = $oCallBackUrl->GetMediaAuthCallbackUrl($params_callback_url); if ($callback_url !== false) { $this->SetCallbackUrl($callback_url); } return $this->BuildLink($params); }