getAccessToken() публичный Метод

public getAccessToken ( $accessTokenURL, $requestToken, $httpMethod = 'POST', array $parameters = [] )
$parameters array
Пример #1
0
 /**
  * returns an access token
  *
  * @param ApiClient $pApiClient
  * @return OAuthToken
  */
 public static function getAccess($pApiClient, $pUser = null)
 {
     if ($pUser) {
         $lUser = $pUser;
     } else {
         $lUser = sfContext::getInstance()->getUser()->getUser();
     }
     $lAccessToken = OAuthServiceTokenPeer::getAccessToken($lUser->getId(), $pApiClient->getId());
     if ($lAccessToken) {
         $lAccessToken = $lAccessToken->convert();
     } else {
         $lServiceRegistry = $pApiClient->getOAuthServiceRegistry();
         $lRequest = sfContext::getInstance()->getRequest();
         $lOAuthKey = $lRequest->getParameter('oauth_token');
         $lRequestToken = OAuthServiceTokenPeer::getRequestToken($lUser->getId(), $lOAuthKey);
         // check if a request token is available
         if ($lRequestToken) {
             // delete request token
             $lRequestToken->delete();
         } else {
             throw new OAuthException('no valid request token');
         }
         $lOAuthConsumer = new OAuthConsumer($lServiceRegistry->getConsumerKey(), $lServiceRegistry->getConsumerSecret(), null);
         // @todo better http error code handling
         try {
             $lAccessToken = OAuthClient::getAccessToken($lOAuthConsumer, $lServiceRegistry->getAccessUri(), $lRequestToken->convert(), $lServiceRegistry->getHttpMethod(), $lServiceRegistry->getScope(), self::getSignature($lServiceRegistry->getSignatureMethods()));
         } catch (Exception $e) {
             throw new OAuthException('request token seems to be invalid');
         }
         OAuthServiceTokenPeer::saveAccessToken($lAccessToken, $lUser->getId(), $lServiceRegistry->getId());
     }
     return $lAccessToken;
 }
Пример #2
0
session_start();
require_once '../OAuthClient.class.php';
$CLIENT_ID = '995059916144-2odfvfoh0h18fhfsid1lh25d1vpunm5n.apps.googleusercontent.com';
$CLIENT_SECRET = 'A3G-GgF_2rsWXUuvmU1hPLOv';
$AUTH_URL = 'https://accounts.google.com/o/oauth2/auth';
$TOKEN_URL = 'https://accounts.google.com/o/oauth2/token';
$google = new OAuthClient();
$google->setClientId($CLIENT_ID)->setClientSecret($CLIENT_SECRET)->setScope('https://www.googleapis.com/auth/plus.me')->setAuthUrl($AUTH_URL)->setTokenUrl($TOKEN_URL);
if (isset($_GET['code']) == true) {
    if ($google->authenticate($_GET['code']) == true) {
        $redirectUrl = $google->getRedirectUrl();
        header('location:' . $redirectUrl);
    }
    exit;
} elseif ($google->getAccessToken() == null) {
    $authUrl = $google->getAuthenticationUrl();
    header('location:' . $authUrl);
    exit;
}
?>
<html lang="ko">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=1000">
<title>SimpleOAuth2Client Examples - Google</title>
</head>
<body>
	<pre>
<?php 
Пример #3
0
 /**
  * ask linkedin for an access token
  *
  * @author Matthias Pfefferle
  * @param string $pTokenKey
  */
 public function getAccessToken($pOAuthToken)
 {
     $lAccessToken = OAuthClient::getAccessToken($this->getConsumer(), "https://api.linkedin.com/uas/oauth/accessToken", $pOAuthToken, "GET", array("oauth_verifier" => $pOAuthToken->verifier));
     return $lAccessToken;
 }
Пример #4
0
 /**
  * Fetches an access token from Twitter
  *
  * @param string $verifier 1.0a verifier
  *
  * @return OAuthToken $token the access token
  */
 function getAccessToken($verifier = null)
 {
     return parent::getAccessToken(self::$accessTokenURL, $verifier);
 }
Пример #5
0
 function getWriteTypeContext($parent, $type)
 {
     ob_start();
     $type = Request('type');
     $parent = Request('parent');
     $subject = $this->getSubject($parent);
     $lms = $this->getLms($subject->lid);
     $templetPath = $lms->templetPath;
     $templetDir = $lms->templetDir;
     if ($type == 'video') {
         $token = $this->IM->getModule('member')->getSocialAuth('youtube');
         if ($token == null) {
             $_SESSION['SOCIAL_REDIRECT_URL'] = '/class/all/write?parent=' . $parent . '&type=video';
             $message = '우리는 유튜브를 사용합니다.<br>유튜브 계정연결이 필요합니다. <a href="/process/member/youtube">이곳을 눌러 유튜브 계정을 연동하여 주십시오.</a>';
             return $message;
         } else {
             $youtube = new OAuthClient();
             $youtube->setClientId($this->youtube->client_id)->setClientSecret($this->youtube->client_secret)->setScope('https://www.googleapis.com/auth/youtube https://www.googleapis.com/auth/youtube.upload https://www.googleapis.com/auth/youtubepartner https://www.googleapis.com/auth/youtube.force-ssl')->setRefreshToken($token->refresh_token)->setAuthUrl($this->youtube->auth_url)->setTokenUrl($this->youtube->token_url);
             //				echo $youtube->getAccessToken();
             echo '<input type="hidden" name="access_token" value="' . $youtube->getAccessToken() . '">' . PHP_EOL;
         }
     }
     if (file_exists($this->Module->getPath() . '/scripts/lms.' . $type . '.js') == true) {
         $this->IM->addSiteHeader('script', $this->Module->getDir() . '/scripts/lms.' . $type . '.js');
     }
     $default = new stdClass();
     $idx = Request('idx');
     if ($idx !== null) {
         $post = $this->getPost($idx);
         if ($post == null) {
             header("HTTP/1.1 404 Not Found");
             return $this->getError($this->getLangauge('error/notFound'));
         }
         if ($this->checkPermission('post_modify') == false && $post->midx != $this->IM->getModule('member')->getLogged()) {
             header("HTTP/1.1 403 Forfidden");
             return $this->getError($this->getLanguage('error/forbidden'));
         }
         if ($lms->use_label != 'NONE') {
             $post->labels = $this->db()->select($this->table->class_label)->where('idx', $post->idx)->get();
             for ($i = 0, $loop = count($post->labels); $i < $loop; $i++) {
                 $post->labels[$i] = $post->labels[$i]->label;
             }
         } else {
             $post->labels = array();
         }
         $post->content = $this->getArticleContent($post->content);
         $post->attachments = $this->db()->select($this->table->attachment)->where('parent', $idx)->where('type', 'POST')->get();
         for ($i = 0, $loop = count($post->attachments); $i < $loop; $i++) {
             $post->attachments[$i] = $post->attachments[$i]->idx;
         }
     } else {
         if (isset($config->label) == true) {
             $default->label = $config->label;
         }
         $post = null;
     }
     $IM = $this->IM;
     $Module = $this;
     if (file_exists($templetPath . '/write.' . $type . '.php') == true) {
         include $templetPath . '/write.' . $type . '.php';
     }
     $context = ob_get_contents();
     ob_end_clean();
     return $context;
 }
Пример #6
0
 function doProcess($action)
 {
     $results = new stdClass();
     $values = new stdClass();
     if ($action == 'check') {
         $name = Request('name');
         $value = Request('value');
         if ($name == 'email') {
             if (CheckEmail($value) == true) {
                 if ($this->db()->select($this->table->member)->where('email', $value)->has() == true) {
                     $results->success = false;
                     $results->message = $this->getLanguage('signup/help/email/duplicated');
                 } else {
                     $results->success = true;
                 }
             } else {
                 $results->success = false;
                 $results->message = $this->getLanguage('signup/help/email/error');
             }
         }
         if ($name == 'name') {
             if (strlen($value) > 0) {
                 $results->success = true;
             } else {
                 $results->success = false;
                 $results->message = $this->getLanguage('signup/help/name/error');
             }
         }
         if ($name == 'nickname') {
             if (CheckNickname($value) == true) {
                 if ($this->db()->select($this->table->member)->where('nickname', $value)->where('idx', $this->getLogged(), '!=')->has() == true) {
                     $results->success = false;
                     $results->message = $this->getLanguage('signup/help/nickname/duplicated');
                 } else {
                     $results->success = true;
                 }
             } else {
                 $results->success = false;
                 $results->message = $this->getLanguage('signup/help/nickname/error');
             }
         }
         if ($name == 'old_password') {
             if ($this->isLogged() == false) {
                 $results->success = false;
                 $results->message = $this->getLanguage('error/notLogged');
             } else {
                 $mHash = new Hash();
                 if ($mHash->password_validate($value, $this->getMember()->password) == true) {
                     $results->success = true;
                     $results->message = $this->getLanguage('password/help/old_password/success');
                 } else {
                     $results->success = false;
                     $results->message = $this->getLanguage('password/help/old_password/error');
                 }
             }
         }
     }
     if ($action == 'forceLogin') {
         $code = Decoder(Request('code'));
         if ($code === false) {
             $results->success = false;
             $results->message = $this->getLanguage('error/invalidCode');
         } else {
             $data = json_decode($code);
             if ($data != null && $data->ip == $_SERVER['REMOTE_ADDR']) {
                 $this->login($data->idx);
                 $results->success = true;
             } else {
                 $results->success = false;
                 $results->message = $this->getLanguage('error/invalidCode');
             }
         }
     }
     if ($action == 'login') {
         $mHash = new Hash();
         $email = Request('email');
         $password = Request('password');
         $results->errors = array();
         $loginFail = Request('loginFail', 'session') != null && is_array(Request('loginFail', 'session')) == true ? Request('loginFail', 'session') : array('count' => 0, 'time' => 0);
         if ($loginFail['time'] > time()) {
             $results->success = false;
             $results->message = $this->getLanguage('login/error/login');
         } else {
             $check = $this->db()->select($this->table->member)->where('email', $email)->getOne();
             if ($check == null) {
                 $results->success = false;
                 $results->errors['email'] = $this->getLanguage('login/error/email');
                 $loginFail['count']++;
                 if ($loginFail['count'] == 5) {
                     $loginFail['count'] = 0;
                     $loginFail['time'] = time() + 60 * 60 * 5;
                 }
                 $values->email = $email;
                 $values->password = $password;
             } elseif ($mHash->password_validate($password, $check->password) == false) {
                 $results->success = false;
                 $results->errors['password'] = $this->getLanguage('login/error/password');
                 $loginFail['count']++;
                 if ($loginFail['count'] == 5) {
                     $loginFail['count'] = 0;
                     $loginFail['time'] = time() + 60 * 60 * 5;
                 }
                 $values->email = $email;
                 $values->password = $password;
             } else {
                 if ($check->status == 'ACTIVE') {
                     $this->db()->update($this->table->member, array('last_login' => time()))->where('idx', $check->idx)->execute();
                     $this->login($check->idx);
                     $results->success = true;
                 } elseif ($check->status == 'VERIFYING') {
                     $_SESSION['MEMBER_REGISTER_IDX'] = Encoder($check->idx);
                     $page = $this->getMemberPage('signup');
                     $results->success = false;
                     $results->redirect = $this->IM->getUrl($page->menu, $page->page, 'verify');
                 } else {
                     $results->success = false;
                     $results->message = $this->getLanguage('error/' . $check->status);
                 }
             }
         }
         $_SESSION['loginFail'] = $loginFail;
     }
     if ($action == 'logout') {
         unset($_SESSION['MEMBER_LOGGED']);
         $results->success = true;
     }
     if ($action == 'cert') {
         $results->success = true;
     }
     if ($action == 'signup') {
         $errors = array();
         $email = CheckEmail(Request('email')) == true ? Request('email') : ($errors['email'] = $this->getLanguage('signup/help/email/error'));
         $password = strlen(Request('password')) >= 4 ? Request('password') : ($errors['password'] = $this->getLanguage('signup/help/password/error'));
         if (strlen(Request('password')) < 4 || Request('password') != Request('password_confirm')) {
             $errors['password_confirm'] = $this->getLanguage('signup/help/password_confirm/error');
         }
         $name = CheckNickname(Request('name')) == true ? Request('name') : ($errors['name'] = $this->getLanguage('signup/help/name/error'));
         $nickname = CheckNickname(Request('nickname')) == true ? Request('nickname') : ($errors['nickname'] = $this->getLanguage('signup/help/nickname/error'));
         if ($this->db()->select($this->table->member)->where('email', $email)->has() == true) {
             $errors['email'] = $this->getLanguage('signup/help/email/duplicated');
         }
         if ($this->db()->select($this->table->member)->where('nickname', $nickname)->has() == true) {
             $errors['nickname'] = $this->getLanguage('signup/help/nickname/duplicated');
         }
         if (empty($errors) == true) {
             $mHash = new Hash();
             $insert = array();
             $insert['gidx'] = Request('registerGIDX', 'session');
             $insert['email'] = $email;
             $insert['password'] = $mHash->password_hash($password);
             $insert['name'] = $name;
             $insert['nickname'] = $nickname;
             $insert['status'] = 'VERIFYING';
             $idx = $this->db()->insert($this->table->member, $insert)->execute();
             if ($idx !== false) {
                 $results->success = true;
                 $_SESSION['MEMBER_REGISTER_IDX'] = Encoder($idx);
                 $this->sendVerifyEmail($idx);
                 unset($_SESSION['registerGIDX']);
             } else {
                 $results->success = false;
             }
         } else {
             $results->success = false;
             $results->errors = $errors;
         }
     }
     if ($action == 'verifyEmail') {
         $registerIDX = Request('registerIDX');
         if ($registerIDX == null) {
             $results->success = false;
         } else {
             $email = Request('email');
             $email_verify_code = Request('email_verify_code');
             $check = $this->db()->select($this->table->email)->where('midx', $registerIDX)->where('email', $email)->getOne();
             if ($check == null) {
                 $results->success = false;
                 $results->errors = array('email' => $this->getLanguage('verifyEmail/help/email/notFound'));
             } elseif ($check->code == $email_verify_code) {
                 $this->db()->update($this->table->email, array('status' => 'VERIFIED'))->where('midx', $registerIDX)->where('email', $email)->execute();
                 $this->db()->update($this->table->member, array('status' => 'ACTIVE'))->where('idx', $registerIDX)->execute();
                 $results->success = true;
             } else {
                 $results->success = false;
                 $results->errors = array('email_verify_code' => $this->getLanguage('verifyEmail/help/email_verify_code/error'));
             }
         }
     }
     if ($action == 'sendVerifyEmail') {
         $registerIDX = Request('registerIDX');
         $email = Request('email');
         if ($this->isLogged() == true) {
             if (CheckEmail($email) == false) {
                 $results->success = false;
                 $results->errors = array('email' => $this->getLanguage('modifyEmail/help/email/error'));
             } elseif ($this->db()->select($this->table->member)->where('email', $email)->count() == 1) {
                 $results->success = false;
                 $results->errors = array('email' => $this->getLanguage('modifyEmail/help/email/duplicated'));
             } else {
                 $check = $this->db()->select($this->table->email)->where('midx', $this->getLogged())->where('email', $email)->getOne();
                 if ($check == null || $check->status != 'SENDING' || $check->status == 'SENDING' && $check->reg_date + 300 < time()) {
                     $this->db()->delete($this->table->email)->where('midx', $this->getLogged())->where('email', $email)->execute();
                     $status = $this->sendVerifyEmail($this->getLogged(), $email);
                     $results->success = true;
                     $results->message = $this->getLanguage('verifyEmail/sending');
                 } else {
                     $results->success = false;
                     $results->message = $this->getLanguage('verifyEmail/error/sending');
                 }
             }
         } elseif ($registerIDX != null) {
             $member = $this->db()->select($this->table->member)->where('idx', $registerIDX)->getOne();
             if ($member == null || $member->status != 'VERIFYING') {
                 $results->success = false;
                 $results->message = $this->getLanguage('verifyEmail/error/target');
             } else {
                 if (CheckEmail($email) == false) {
                     $results->success = false;
                     $results->message = $this->getLanguage('verifyEmail/error/email');
                 } else {
                     $check = $this->db()->select($this->table->email)->where('midx', $registerIDX)->where('email', $email)->getOne();
                     if ($check->status == 'VERIFIED') {
                         $signupPage = $this->getMemberPage('signup');
                         $results->success = true;
                         $this->db()->update($this->table->member, array('status' => 'ACTIVE'))->where('idx', $registerIDX)->execute();
                         $results->redirect = $this->IM->getUrl($signupPage->menu, $signupPage->page, 'complete');
                     } elseif ($check == null || $check->status == 'CANCELED' || $check->status == 'SENDING' && $check->reg_date + 300 < time()) {
                         $this->db()->delete($this->table->email)->where('midx', $registerIDX)->where('email', $email)->execute();
                         $status = $this->sendVerifyEmail($registerIDX, $email);
                         $results->success = true;
                         $results->message = $this->getLanguage('verifyEmail/sending');
                     } else {
                         $results->success = false;
                         $results->message = $this->getLanguage('verifyEmail/error/sending');
                     }
                 }
             }
         } else {
             $results->success = false;
             $results->message = $this->getLanguage('error/notLogged');
         }
     }
     if ($action == 'photoEdit') {
         $templet = Request('templet');
         if ($this->isLogged() == true) {
             $results->success = true;
             $results->modalHtml = $this->getPhotoEdit($templet);
             $results->photo = $this->getMember()->photo;
         } else {
             $results->success = false;
             $results->message = $this->getLanguage('error/notLogged');
         }
     }
     if ($action == 'photoUpload') {
         $photo = Request('photo');
         if ($this->isLogged() == false) {
             $results->success = false;
             $results->message = $this->getLanguage('error/notLogged');
         } else {
             if (preg_match('/^data:image\\/(.*?);base64,(.*?)$/', $photo, $match) == true) {
                 $bytes = base64_decode($match[2]);
                 file_put_contents($this->IM->getAttachmentPath() . '/member/' . $this->getLogged() . '.jpg', $bytes);
                 $this->IM->getModule('attachment')->createThumbnail($this->IM->getAttachmentPath() . '/member/' . $this->getLogged() . '.jpg', $this->IM->getAttachmentPath() . '/member/' . $this->getLogged() . '.jpg', 250, 250, false, 'jpg');
                 $results->success = true;
                 $results->message = $this->getLanguage('photoEdit/success');
             } else {
                 $results->success = false;
                 $results->message = $this->getLanguage('photoEdit/error');
             }
         }
     }
     if ($action == 'modifyEmail') {
         $confirm = Request('confirm');
         if ($confirm == 'TRUE') {
             $email = Request('email');
             $code = Request('code');
             $check = $this->db()->select($this->table->email)->where('midx', $this->getLogged())->where('email', $email)->getOne();
             if ($check == null || $check->code != $code) {
                 $results->success = false;
                 $results->errors = array('code' => $this->getLanguage('modifyEmail/help/code/error'));
             } else {
                 $this->db()->update($this->table->email, array('status' => 'VERIFIED'))->where('midx', $this->getLogged())->where('email', $email)->execute();
                 $this->db()->update($this->table->member, array('email' => $email))->where('idx', $this->getLogged())->execute();
                 $results->success = true;
                 $results->message = $this->getLanguage('modifyEmail/success');
             }
         } else {
             $templet = Request('templet');
             if ($this->isLogged() == true) {
                 $results->success = true;
                 $results->modalHtml = $this->getModifyEmail($templet);
             } else {
                 $results->success = false;
                 $results->message = $this->getLanguage('error/notLogged');
             }
         }
     }
     if ($action == 'modify') {
         $step = Request('step');
         if ($step == 'verify') {
             $member = $this->getMember();
             $password = Request('password');
             $mHash = new Hash();
             if ($mHash->password_validate($password, $member->password) == true) {
                 $results->success = true;
                 $results->password = Encoder($password);
             } else {
                 $results->success = false;
                 $results->errors = array('password' => $this->getLanguage('verify/help/password/error'));
             }
         }
         if ($step == 'modify') {
             $errors = array();
             $values->name = Request('name') ? Request('name') : ($errors['name'] = $this->getLanguage('signup/help/name/error'));
             $values->nickname = Request('nickname') ? Request('nickname') : ($errors['nickname'] = $this->getLanguage('signup/help/nickname/error'));
             if ($this->isLogged() == false) {
                 $results->success = false;
                 $results->message = $this->getLangauge('error/notLogged');
             } elseif (count($errors) == 0) {
                 $insert = array();
                 $insert['name'] = $values->name;
                 $insert['nickname'] = $values->nickname;
                 $this->db()->update($this->table->member, $insert)->where('idx', $this->getLogged())->execute();
                 $results->success = true;
                 $results->message = $this->getLanguage('modify/success');
             } else {
                 $results->success = false;
                 $results->errors = $errors;
             }
         }
     }
     if ($action == 'password') {
         $errors = array();
         $password = strlen(Request('password')) >= 4 ? Request('password') : ($errors['password'] = $this->getLanguage('signup/help/password/error'));
         if (strlen(Request('password')) < 4 || Request('password') != Request('password_confirm')) {
             $errors['password_confirm'] = $this->getLanguage('signup/help/password_confirm/error');
         }
         if ($this->isLogged() == false) {
             $results->success = false;
             $results->message = $this->getLangauge('error/notLogged');
         } else {
             $mHash = new Hash();
             if (strlen($this->getMember()->password) == 65) {
                 $old_password = Request('old_password');
                 if ($old_password == '' || $mHash->password_validate($old_password, $this->getMember()->password) == false) {
                     $errors['old_password'] = $this->getLanguage('password/help/old_password/error');
                 }
             }
             if (count($errors) == 0) {
                 $password = $mHash->password_hash($password);
                 $this->db()->update($this->table->member, array('password' => $password))->where('idx', $this->getLogged())->execute();
                 $results->success = true;
                 $results->message = $this->getLanguage('password/success');
             } else {
                 $results->success = false;
                 $results->errors = $errors;
             }
         }
     }
     if ($action == 'facebook') {
         if (Request('SOCIAL_REDIRECT_URL', 'session') == null) {
             $_SESSION['SOCIAL_REDIRECT_URL'] = $_SERVER['HTTP_REFERER'];
         }
         if ($this->IM->domain == 'www.arzz.com') {
             $CLIENT_ID = '985851538105124';
             $CLIENT_SECRET = 'c6b74ae32d4786b440bb878c46ee2998';
         } elseif ($this->IM->domain == 'www.minitalk.kr') {
             $CLIENT_ID = '418845248317025';
             $CLIENT_SECRET = '5850c198f8f4b0b254a53ae7f9049600';
         } else {
             $CLIENT_ID = '985851538105124';
             $CLIENT_SECRET = 'c6b74ae32d4786b440bb878c46ee2998';
         }
         $AUTH_URL = 'https://graph.facebook.com/oauth/authorize';
         $TOKEN_URL = 'https://graph.facebook.com/oauth/access_token';
         $facebook = new OAuthClient();
         $facebook->setClientId($CLIENT_ID)->setClientSecret($CLIENT_SECRET)->setScope('public_profile,email')->setAccessType('offline')->setAuthUrl($AUTH_URL)->setTokenUrl($TOKEN_URL);
         if (isset($_GET['code']) == true) {
             if ($facebook->authenticate($_GET['code']) == true) {
                 $redirectUrl = $facebook->getRedirectUrl();
                 header('location:' . $redirectUrl);
             }
             exit;
         } elseif ($facebook->getAccessToken() == null) {
             $authUrl = $facebook->getAuthenticationUrl();
             header('location:' . $authUrl);
             exit;
         }
         $data = $facebook->get('https://graph.facebook.com/me', array('fields' => 'id,email,name'));
         if ($data === false || empty($data->email) == true) {
             $this->IM->printError('API ERROR');
         }
         $accessToken = $facebook->getAccessToken();
         $refreshToken = $facebook->getRefreshToken() == null ? '' : $facebook->getRefreshToken();
         $this->socialLogin('facebook', $data->id, $data->name, $data->email, 'https://graph.facebook.com/' . $data->id . '/picture?width=250&height=250', $accessToken, $refreshToken);
     }
     if ($action == 'google') {
         if (Request('SOCIAL_REDIRECT_URL', 'session') == null) {
             $_SESSION['SOCIAL_REDIRECT_URL'] = $_SERVER['HTTP_REFERER'];
         }
         if ($this->IM->domain == 'www.arzz.com') {
             $CLIENT_ID = '367657130146-m9ojilvf3kbsv6j24uieartls0ols8t8.apps.googleusercontent.com';
             $CLIENT_SECRET = 'GVgWL29VdBiSQIuRTlL5RZDc';
         } elseif ($this->IM->domain == 'www.minitalk.kr') {
             $CLIENT_ID = '476101389490-mug55vcsit7af2sd095m3c8fhd3agssu.apps.googleusercontent.com';
             $CLIENT_SECRET = 'CJKMFEkaWkiasXWIj42WY4HU';
         } else {
             $CLIENT_ID = '995059916144-2odfvfoh0h18fhfsid1lh25d1vpunm5n.apps.googleusercontent.com';
             $CLIENT_SECRET = 'A3G-GgF_2rsWXUuvmU1hPLOv';
         }
         $AUTH_URL = 'https://accounts.google.com/o/oauth2/auth';
         $TOKEN_URL = 'https://accounts.google.com/o/oauth2/token';
         $google = new OAuthClient();
         $google->setClientId($CLIENT_ID)->setClientSecret($CLIENT_SECRET)->setScope('https://www.googleapis.com/auth/plus.me https://www.googleapis.com/auth/userinfo.email')->setAccessType('offline')->setAuthUrl($AUTH_URL)->setTokenUrl($TOKEN_URL);
         if (isset($_GET['code']) == true) {
             if ($google->authenticate($_GET['code']) == true) {
                 $redirectUrl = $google->getRedirectUrl();
                 header('location:' . $redirectUrl);
             }
             exit;
         } elseif ($google->getAccessToken() == null) {
             $authUrl = $google->getAuthenticationUrl();
             header('location:' . $authUrl);
             exit;
         }
         $data = $google->get('https://www.googleapis.com/plus/v1/people/me');
         if ($data === false || empty($data->emails) == true) {
             $this->IM->printError('API ERROR');
         }
         for ($i = 0, $loop = count($data->emails); $i < $loop; $i++) {
             if ($data->emails[$i]->type == 'account') {
                 $data->email = $data->emails[$i]->value;
                 break;
             }
         }
         $data->photo = str_replace('sz=50', 'sz=250', $data->image->url);
         $accessToken = $google->getAccessToken();
         $refreshToken = $google->getRefreshToken() == null ? '' : $google->getRefreshToken();
         $this->socialLogin('google', $data->id, $data->displayName, $data->email, $data->photo, $accessToken, $refreshToken);
     }
     if ($action == 'youtube') {
         if (Request('SOCIAL_REDIRECT_URL', 'session') == null) {
             $_SESSION['SOCIAL_REDIRECT_URL'] = $_SERVER['HTTP_REFERER'];
         }
         if ($this->isLogged() == false) {
             die($this->getError('NOT_LOGGED'));
         }
         $CLIENT_ID = '995059916144-2odfvfoh0h18fhfsid1lh25d1vpunm5n.apps.googleusercontent.com';
         $CLIENT_SECRET = 'A3G-GgF_2rsWXUuvmU1hPLOv';
         $AUTH_URL = 'https://accounts.google.com/o/oauth2/auth';
         $TOKEN_URL = 'https://accounts.google.com/o/oauth2/token';
         $youtube = new OAuthClient();
         $youtube->setClientId($CLIENT_ID)->setClientSecret($CLIENT_SECRET)->setScope('https://www.googleapis.com/auth/plus.me https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/youtube https://www.googleapis.com/auth/youtube.upload https://www.googleapis.com/auth/youtubepartner https://www.googleapis.com/auth/youtube.force-ssl')->setAccessType('offline')->setAuthUrl($AUTH_URL)->setTokenUrl($TOKEN_URL);
         if (isset($_GET['code']) == true) {
             if ($youtube->authenticate($_GET['code']) == true) {
                 $redirectUrl = $youtube->getRedirectUrl();
                 header('location:' . $redirectUrl);
             }
             exit;
         } elseif ($youtube->getAccessToken() == null) {
             $authUrl = $youtube->getAuthenticationUrl();
             header('location:' . $authUrl);
             exit;
         }
         $data = $youtube->get('https://www.googleapis.com/plus/v1/people/me');
         if ($data === false || empty($data->emails) == true) {
             $this->IM->printError('API ERROR');
         }
         for ($i = 0, $loop = count($data->emails); $i < $loop; $i++) {
             if ($data->emails[$i]->type == 'account') {
                 $data->email = $data->emails[$i]->value;
                 break;
             }
         }
         $accessToken = $youtube->getAccessToken();
         $refreshToken = $youtube->getRefreshToken() == null ? '' : $youtube->getRefreshToken();
         $check = $this->db()->select($this->table->social)->where('midx', $this->getLogged())->where('code', 'youtube')->getOne();
         if ($check == null) {
             $this->db()->insert($this->table->social, array('midx' => $this->getLogged(), 'code' => 'youtube', 'user_id' => $data->id, 'email' => $data->email, 'access_token' => $accessToken, 'refresh_token' => $refreshToken))->execute();
         } else {
             $this->db()->update($this->table->social, array('user_id' => $data->id, 'email' => $data->email, 'access_token' => $accessToken, 'refresh_token' => $refreshToken))->where('midx', $this->getLogged())->where('code', 'youtube')->execute();
         }
         unset($_SESSION['OAUTH_ACCESS_TOKEN']);
         unset($_SESSION['OAUTH_REFRESH_TOKEN']);
         $redirectUrl = Request('SOCIAL_REDIRECT_URL', 'session') != null ? Request('SOCIAL_REDIRECT_URL', 'session') : '/';
         unset($_SESSION['SOCIAL_REDIRECT_URL']);
         header('location:' . $redirectUrl);
     }
     if ($action == 'github') {
         if (Request('SOCIAL_REDIRECT_URL', 'session') == null) {
             $_SESSION['SOCIAL_REDIRECT_URL'] = $_SERVER['HTTP_REFERER'];
         }
         if ($this->IM->domain == 'www.arzz.com') {
             $CLIENT_ID = 'b3f954eccc5378afbacf';
             $CLIENT_SECRET = '4507787bbac2f89382c5b29dc07017bbc776c218';
         } elseif ($this->IM->domain == 'www.minitalk.kr') {
             $CLIENT_ID = 'a5b5c360b237ed9de0c7';
             $CLIENT_SECRET = '0f5e658a0d05f83ee918da13cfe070ff5bc42e60';
         } else {
             $CLIENT_ID = 'b3f954eccc5378afbacf';
             $CLIENT_SECRET = '4507787bbac2f89382c5b29dc07017bbc776c218';
         }
         $AUTH_URL = 'https://github.com/login/oauth/authorize';
         $TOKEN_URL = 'https://github.com/login/oauth/access_token';
         $github = new OAuthClient();
         $github->setClientId($CLIENT_ID)->setClientSecret($CLIENT_SECRET)->setAuthUrl($AUTH_URL)->setScope('user')->setAccessType('offline')->setUserAgent('Awesome-Octocat-App')->setTokenUrl($TOKEN_URL);
         if (isset($_GET['code']) == true) {
             if ($github->authenticate($_GET['code']) == true) {
                 $redirectUrl = $github->getRedirectUrl();
                 header('location:' . $redirectUrl);
             }
             exit;
         } elseif ($github->getAccessToken() == null) {
             $authUrl = $github->getAuthenticationUrl();
             header('location:' . $authUrl);
             exit;
         }
         $data = $github->get('https://api.github.com/user');
         if ($data === false || empty($data->email) == true) {
             $this->IM->printError('API ERROR');
         }
         $accessToken = $github->getAccessToken();
         $refreshToken = $github->getRefreshToken() == null ? '' : $github->getRefreshToken();
         $this->socialLogin('github', $data->id, $data->name, $data->email, $data->avatar_url, $accessToken, $refreshToken);
     }
     $this->IM->fireEvent('afterDoProcess', 'member', $action, $values, $results);
     return $results;
 }
Пример #7
0
 /**
  * ask twitter for an access token
  *
  * @author Matthias Pfefferle
  * @param string $pTokenKey
  */
 public function getAccessToken($pOAuthToken)
 {
     $lAccessToken = OAuthClient::getAccessToken($this->getConsumer(), "https://api.xing.com/v1/access_token", $pOAuthToken, "POST", array("oauth_verifier" => $pOAuthToken->verifier));
     return $lAccessToken;
 }
Пример #8
0
 function doProcess($action)
 {
     $results = new stdClass();
     $values = new stdClass();
     if ($action == 'check') {
         $name = Request('name');
         $value = Request('value');
         if ($name == 'email') {
             $siteType = $this->IM->getSites($this->IM->domain)->member;
             if (CheckEmail($value) == true) {
                 if ($this->db()->select($this->table->member)->where('email', $value)->where('idx', $this->getLogged(), '!=')->where('domain', $siteType == 'MERGE' ? '*' : $this->IM->domain)->has() == true || $this->db()->select($this->table->member)->where('email', $value)->where('idx', $this->getLogged(), '!=')->where('type', 'ADMINISTRATOR')->has() == true) {
                     $results->success = false;
                     $results->message = $this->getLanguage('signup/help/email/duplicated');
                 } else {
                     $results->success = true;
                 }
             } else {
                 $results->success = false;
                 $results->message = $this->getLanguage('signup/help/email/error');
             }
         }
         if ($name == 'name') {
             if (strlen($value) > 0) {
                 $results->success = true;
             } else {
                 $results->success = false;
                 $results->message = $this->getLanguage('signup/help/name/error');
             }
         }
         if ($name == 'nickname') {
             $siteType = $this->IM->getSites($this->IM->domain)->member;
             if (CheckNickname($value) == true) {
                 if ($this->db()->select($this->table->member)->where('nickname', $value)->where('idx', $this->getLogged(), '!=')->where('domain', $siteType == 'MERGE' ? '*' : $this->IM->domain)->has() == true || $this->db()->select($this->table->member)->where('nickname', $value)->where('idx', $this->getLogged(), '!=')->where('type', 'ADMINISTRATOR')->has() == true) {
                     $results->success = false;
                     $results->message = $this->getLanguage('signup/help/nickname/duplicated');
                 } else {
                     $results->success = true;
                 }
             } else {
                 $results->success = false;
                 $results->message = $this->getLanguage('signup/help/nickname/error');
             }
         }
         if ($name == 'old_password') {
             if ($this->isLogged() == false) {
                 $results->success = false;
                 $results->message = $this->getLanguage('error/notLogged');
             } else {
                 $mHash = new Hash();
                 if ($mHash->password_validate($value, $this->getMember()->password) == true) {
                     $results->success = true;
                     $results->message = $this->getLanguage('password/help/old_password/success');
                 } else {
                     $results->success = false;
                     $results->message = $this->getLanguage('password/help/old_password/error');
                 }
             }
         }
     }
     if ($action == 'forceLogin') {
         $code = Decoder(Request('code'));
         if ($code === false) {
             $results->success = false;
             $results->message = $this->getLanguage('error/invalidCode');
         } else {
             $data = json_decode($code);
             if ($data != null && $data->ip == $_SERVER['REMOTE_ADDR']) {
                 $this->login($data->idx);
                 $results->success = true;
             } else {
                 $results->success = false;
                 $results->message = $this->getLanguage('error/invalidCode');
             }
         }
     }
     if ($action == 'login') {
         $mHash = new Hash();
         $email = Request('email');
         $password = Request('password');
         $results->errors = array();
         $loginFail = Request('loginFail', 'session') != null && is_array(Request('loginFail', 'session')) == true ? Request('loginFail', 'session') : array('count' => 0, 'time' => 0);
         if ($loginFail['time'] > time()) {
             $results->success = false;
             $results->message = $this->getLanguage('login/error/login');
         } else {
             $siteType = $this->IM->getSites($this->IM->domain)->member;
             if ($siteType == 'MERGE') {
                 $check = $this->db()->select($this->table->member)->where('email', $email)->where('domain', '*')->getOne();
             } else {
                 $check = $this->db()->select($this->table->member)->where('email', $email)->where('domain', $this->IM->domain)->getOne();
             }
             // not found member, search ADMINISTRATOR
             if ($check == null) {
                 $check = $this->db()->select($this->table->member)->where('email', $email)->where('type', 'ADMINISTRATOR')->getOne();
             }
             if ($check == null) {
                 $results->success = false;
                 $results->errors['email'] = $this->getLanguage('login/error/email');
                 $loginFail['count']++;
                 if ($loginFail['count'] == 5) {
                     $loginFail['count'] = 0;
                     $loginFail['time'] = time() + 60 * 60 * 5;
                 }
                 $values->email = $email;
                 $values->password = $password;
             } elseif ($mHash->password_validate($password, $check->password) == false) {
                 $results->success = false;
                 $results->errors['password'] = $this->getLanguage('login/error/password');
                 $loginFail['count']++;
                 if ($loginFail['count'] == 5) {
                     $loginFail['count'] = 0;
                     $loginFail['time'] = time() + 60 * 60 * 5;
                 }
                 $values->email = $email;
                 $values->password = $password;
             } else {
                 if ($check->status == 'ACTIVE') {
                     $this->db()->update($this->table->member, array('last_login' => time()))->where('idx', $check->idx)->execute();
                     $this->login($check->idx);
                     $results->success = true;
                 } elseif ($check->status == 'VERIFYING') {
                     $_SESSION['MEMBER_REGISTER_IDX'] = Encoder($check->idx);
                     $page = $this->getMemberPage('signup');
                     $results->success = false;
                     $results->redirect = $this->IM->getUrl($page->menu, $page->page, 'verify');
                 } else {
                     $results->success = false;
                     $results->message = $this->getLanguage('error/' . $check->status);
                 }
             }
         }
         $_SESSION['loginFail'] = $loginFail;
     }
     if ($action == 'logout') {
         unset($_SESSION['MEMBER_LOGGED']);
         $results->success = true;
     }
     if ($action == 'cert') {
         $results->success = true;
     }
     if ($action == 'signup') {
         $siteType = $this->IM->getSites($this->IM->domain)->member;
         $errors = array();
         $email = CheckEmail(Request('email')) == true ? Request('email') : ($errors['email'] = $this->getLanguage('signup/help/email/error'));
         $password = strlen(Request('password')) >= 4 ? Request('password') : ($errors['password'] = $this->getLanguage('signup/help/password/error'));
         if (strlen(Request('password')) < 4 || Request('password') != Request('password_confirm')) {
             $errors['password_confirm'] = $this->getLanguage('signup/help/password_confirm/error');
         }
         $name = CheckNickname(Request('name')) == true ? Request('name') : ($errors['name'] = $this->getLanguage('signup/help/name/error'));
         $nickname = CheckNickname(Request('nickname')) == true ? Request('nickname') : ($errors['nickname'] = $this->getLanguage('signup/help/nickname/error'));
         if ($this->db()->select($this->table->member)->where('email', $email)->where('domain', $siteType == 'MERGE' ? '*' : $this->IM->domain)->has() == true || $this->db()->select($this->table->member)->where('email', $email)->where('type', 'ADMINISTRATOR')->has() == true) {
             $errors['email'] = $this->getLanguage('signup/help/email/duplicated');
         }
         if ($this->db()->select($this->table->member)->where('nickname', $nickname)->where('domain', $siteType == 'MERGE' ? '*' : $this->IM->domain)->has() == true || $this->db()->select($this->table->member)->where('nickname', $nickname)->where('type', 'ADMINISTRATOR')->has() == true) {
             $errors['nickname'] = $this->getLanguage('signup/help/nickname/duplicated');
         }
         if (empty($errors) == true) {
             $mHash = new Hash();
             $insert = array();
             $insert['email'] = $email;
             $insert['domain'] = $siteType == 'MERGE' ? '*' : $this->IM->domain;
             $insert['password'] = $mHash->password_hash($password);
             $insert['name'] = $name;
             $insert['nickname'] = $nickname;
             $insert['status'] = 'VERIFYING';
             $insert['reg_date'] = time();
             $idx = $this->db()->insert($this->table->member, $insert)->execute();
             if ($idx !== false) {
                 $results->success = true;
                 $_SESSION['MEMBER_REGISTER_IDX'] = Encoder($idx);
                 $this->sendVerifyEmail($idx);
                 unset($_SESSION['registerGIDX']);
             } else {
                 $results->success = false;
             }
         } else {
             $results->success = false;
             $results->errors = $errors;
         }
     }
     if ($action == 'verifyEmail') {
         $registerIDX = Request('registerIDX');
         if ($registerIDX == null) {
             $results->success = false;
         } else {
             $email = Request('email');
             $email_verify_code = Request('email_verify_code');
             $check = $this->db()->select($this->table->email)->where('midx', $registerIDX)->where('email', $email)->getOne();
             if ($check == null) {
                 $results->success = false;
                 $results->errors = array('email' => $this->getLanguage('verifyEmail/help/email/notFound'));
             } elseif ($check->code == $email_verify_code) {
                 $this->db()->update($this->table->email, array('status' => 'VERIFIED'))->where('midx', $registerIDX)->where('email', $email)->execute();
                 $this->db()->update($this->table->member, array('status' => 'ACTIVE'))->where('idx', $registerIDX)->execute();
                 $results->success = true;
             } else {
                 $results->success = false;
                 $results->errors = array('email_verify_code' => $this->getLanguage('verifyEmail/help/email_verify_code/error'));
             }
         }
     }
     if ($action == 'sendVerifyEmail') {
         $registerIDX = Request('registerIDX');
         $email = Request('email');
         if ($this->isLogged() == true) {
             if (CheckEmail($email) == false) {
                 $results->success = false;
                 $results->errors = array('email' => $this->getLanguage('modifyEmail/help/email/error'));
             } elseif ($this->db()->select($this->table->member)->where('email', $email)->count() == 1) {
                 $results->success = false;
                 $results->errors = array('email' => $this->getLanguage('modifyEmail/help/email/duplicated'));
             } else {
                 $check = $this->db()->select($this->table->email)->where('midx', $this->getLogged())->where('email', $email)->getOne();
                 if ($check == null || $check->status != 'SENDING' || $check->status == 'SENDING' && $check->reg_date + 300 < time()) {
                     $this->db()->delete($this->table->email)->where('midx', $this->getLogged())->where('email', $email)->execute();
                     $status = $this->sendVerifyEmail($this->getLogged(), $email);
                     $results->success = true;
                     $results->message = $this->getLanguage('verifyEmail/sending');
                 } else {
                     $results->success = false;
                     $results->message = $this->getLanguage('verifyEmail/error/sending');
                 }
             }
         } elseif ($registerIDX != null) {
             $member = $this->db()->select($this->table->member)->where('idx', $registerIDX)->getOne();
             if ($member == null || $member->status != 'VERIFYING') {
                 $results->success = false;
                 $results->message = $this->getLanguage('verifyEmail/error/target');
             } else {
                 if (CheckEmail($email) == false) {
                     $results->success = false;
                     $results->message = $this->getLanguage('verifyEmail/error/email');
                 } else {
                     $check = $this->db()->select($this->table->email)->where('midx', $registerIDX)->where('email', $email)->getOne();
                     if ($check->status == 'VERIFIED') {
                         $signupPage = $this->getMemberPage('signup');
                         $results->success = true;
                         $this->db()->update($this->table->member, array('status' => 'ACTIVE'))->where('idx', $registerIDX)->execute();
                         $results->redirect = $this->IM->getUrl($signupPage->menu, $signupPage->page, 'complete');
                     } elseif ($check == null || $check->status == 'CANCELED' || $check->status == 'SENDING' && $check->reg_date + 300 < time()) {
                         $this->db()->delete($this->table->email)->where('midx', $registerIDX)->where('email', $email)->execute();
                         $status = $this->sendVerifyEmail($registerIDX, $email);
                         $results->success = true;
                         $results->message = $this->getLanguage('verifyEmail/sending');
                     } else {
                         $results->success = false;
                         $results->message = $this->getLanguage('verifyEmail/error/sending');
                     }
                 }
             }
         } else {
             $results->success = false;
             $results->message = $this->getLanguage('error/notLogged');
         }
     }
     if ($action == 'photoEdit') {
         $templet = Request('templet');
         if ($this->isLogged() == true) {
             $results->success = true;
             $results->modalHtml = $this->getPhotoEdit($templet);
             $results->photo = $this->getMember()->photo;
         } else {
             $results->success = false;
             $results->message = $this->getLanguage('error/notLogged');
         }
     }
     if ($action == 'photoUpload') {
         $photo = Request('photo');
         if ($this->isLogged() == false) {
             $results->success = false;
             $results->message = $this->getLanguage('error/notLogged');
         } else {
             if (preg_match('/^data:image\\/(.*?);base64,(.*?)$/', $photo, $match) == true) {
                 $bytes = base64_decode($match[2]);
                 file_put_contents($this->IM->getAttachmentPath() . '/member/' . $this->getLogged() . '.jpg', $bytes);
                 $this->IM->getModule('attachment')->createThumbnail($this->IM->getAttachmentPath() . '/member/' . $this->getLogged() . '.jpg', $this->IM->getAttachmentPath() . '/member/' . $this->getLogged() . '.jpg', 250, 250, false, 'jpg');
                 $results->success = true;
                 $results->message = $this->getLanguage('photoEdit/success');
             } else {
                 $results->success = false;
                 $results->message = $this->getLanguage('photoEdit/error');
             }
         }
     }
     if ($action == 'modifyEmail') {
         $confirm = Request('confirm');
         if ($confirm == 'TRUE') {
             $email = Request('email');
             $code = Request('code');
             $check = $this->db()->select($this->table->email)->where('midx', $this->getLogged())->where('email', $email)->getOne();
             if ($check == null || $check->code != $code) {
                 $results->success = false;
                 $results->errors = array('code' => $this->getLanguage('modifyEmail/help/code/error'));
             } else {
                 $this->db()->update($this->table->email, array('status' => 'VERIFIED'))->where('midx', $this->getLogged())->where('email', $email)->execute();
                 $this->db()->update($this->table->member, array('email' => $email))->where('idx', $this->getLogged())->execute();
                 $results->success = true;
                 $results->message = $this->getLanguage('modifyEmail/success');
             }
         } else {
             $templet = Request('templet');
             if ($this->isLogged() == true) {
                 $results->success = true;
                 $results->modalHtml = $this->getModifyEmail($templet);
             } else {
                 $results->success = false;
                 $results->message = $this->getLanguage('error/notLogged');
             }
         }
     }
     if ($action == 'modify') {
         $step = Request('step');
         if ($step == 'verify') {
             $member = $this->getMember();
             $password = Request('password');
             $mHash = new Hash();
             if ($mHash->password_validate($password, $member->password) == true) {
                 $results->success = true;
                 $results->password = Encoder($password);
             } else {
                 $results->success = false;
                 $results->errors = array('password' => $this->getLanguage('verify/help/password/error'));
             }
         }
         if ($step == 'modify') {
             $errors = array();
             $values->name = Request('name') ? Request('name') : ($errors['name'] = $this->getLanguage('signup/help/name/error'));
             $values->nickname = Request('nickname') ? Request('nickname') : ($errors['nickname'] = $this->getLanguage('signup/help/nickname/error'));
             if ($this->isLogged() == false) {
                 $results->success = false;
                 $results->message = $this->getLangauge('error/notLogged');
             } elseif (count($errors) == 0) {
                 $insert = array();
                 $insert['name'] = $values->name;
                 $insert['nickname'] = $values->nickname;
                 $this->db()->update($this->table->member, $insert)->where('idx', $this->getLogged())->execute();
                 $results->success = true;
                 $results->message = $this->getLanguage('modify/success');
             } else {
                 $results->success = false;
                 $results->errors = $errors;
             }
         }
     }
     if ($action == 'password') {
         $errors = array();
         $password = strlen(Request('password')) >= 4 ? Request('password') : ($errors['password'] = $this->getLanguage('signup/help/password/error'));
         if (strlen(Request('password')) < 4 || Request('password') != Request('password_confirm')) {
             $errors['password_confirm'] = $this->getLanguage('signup/help/password_confirm/error');
         }
         if ($this->isLogged() == false) {
             $results->success = false;
             $results->message = $this->getLangauge('error/notLogged');
         } else {
             $mHash = new Hash();
             if (strlen($this->getMember()->password) == 65) {
                 $old_password = Request('old_password');
                 if ($old_password == '' || $mHash->password_validate($old_password, $this->getMember()->password) == false) {
                     $errors['old_password'] = $this->getLanguage('password/help/old_password/error');
                 }
             }
             if (count($errors) == 0) {
                 $password = $mHash->password_hash($password);
                 $this->db()->update($this->table->member, array('password' => $password))->where('idx', $this->getLogged())->execute();
                 $results->success = true;
                 $results->message = $this->getLanguage('password/success');
             } else {
                 $results->success = false;
                 $results->errors = $errors;
             }
         }
     }
     if ($action == 'facebook') {
         $OAUTH = $this->db()->select($this->table->social_oauth)->where('domain', $this->IM->domain)->where('code', $action)->getOne();
         if ($OAUTH == null) {
             $this->IM->printError('OAUTH_DOMAIN_ERROR');
         }
         $CLIENT_ID = $OAUTH->client_id;
         $CLIENT_SECRET = $OAUTH->client_secret;
         $AUTH_URL = 'https://graph.facebook.com/oauth/authorize';
         $TOKEN_URL = 'https://graph.facebook.com/oauth/access_token';
         if (Request('SOCIAL_REDIRECT_URL', 'session') == null) {
             $_SESSION['SOCIAL_REDIRECT_URL'] = $_SERVER['HTTP_REFERER'];
         }
         $facebook = new OAuthClient();
         $facebook->setClientId($CLIENT_ID)->setClientSecret($CLIENT_SECRET)->setScope('public_profile,email')->setAccessType('offline')->setAuthUrl($AUTH_URL)->setTokenUrl($TOKEN_URL);
         if (isset($_GET['code']) == true) {
             if ($facebook->authenticate($_GET['code']) == true) {
                 $redirectUrl = $facebook->getRedirectUrl();
                 header('location:' . $redirectUrl);
             }
             exit;
         } elseif ($facebook->getAccessToken() == null) {
             $authUrl = $facebook->getAuthenticationUrl();
             header('location:' . $authUrl);
             exit;
         }
         $data = $facebook->get('https://graph.facebook.com/me', array('fields' => 'id,email,name'));
         if ($data === false || empty($data->email) == true) {
             $this->IM->printError('OAUTH_API_ERROR');
         }
         $accessToken = $facebook->getAccessToken();
         $refreshToken = $facebook->getRefreshToken() == null ? '' : $facebook->getRefreshToken();
         $this->socialLogin('facebook', $data->id, $data->name, $data->email, 'https://graph.facebook.com/' . $data->id . '/picture?width=250&height=250', $accessToken, $refreshToken);
     }
     if ($action == 'google') {
         $OAUTH = $this->db()->select($this->table->social_oauth)->where('domain', $this->IM->domain)->where('code', $action)->getOne();
         if ($OAUTH == null) {
             $this->IM->printError('OAUTH_DOMAIN_ERROR');
         }
         $CLIENT_ID = $OAUTH->client_id;
         $CLIENT_SECRET = $OAUTH->client_secret;
         $AUTH_URL = 'https://accounts.google.com/o/oauth2/auth';
         $TOKEN_URL = 'https://accounts.google.com/o/oauth2/token';
         if (Request('SOCIAL_REDIRECT_URL', 'session') == null) {
             $_SESSION['SOCIAL_REDIRECT_URL'] = $_SERVER['HTTP_REFERER'];
         }
         $google = new OAuthClient();
         $google->setClientId($CLIENT_ID)->setClientSecret($CLIENT_SECRET)->setScope('https://www.googleapis.com/auth/plus.me https://www.googleapis.com/auth/userinfo.email')->setAccessType('offline')->setAuthUrl($AUTH_URL)->setTokenUrl($TOKEN_URL);
         if (isset($_GET['code']) == true) {
             if ($google->authenticate($_GET['code']) == true) {
                 $redirectUrl = $google->getRedirectUrl();
                 header('location:' . $redirectUrl);
             }
             exit;
         } elseif ($google->getAccessToken() == null) {
             $authUrl = $google->getAuthenticationUrl();
             header('location:' . $authUrl);
             exit;
         }
         $data = $google->get('https://www.googleapis.com/plus/v1/people/me');
         if ($data === false || empty($data->emails) == true) {
             $this->IM->printError('OAUTH_API_ERROR');
         }
         for ($i = 0, $loop = count($data->emails); $i < $loop; $i++) {
             if ($data->emails[$i]->type == 'account') {
                 $data->email = $data->emails[$i]->value;
                 break;
             }
         }
         $data->photo = str_replace('sz=50', 'sz=250', $data->image->url);
         $accessToken = $google->getAccessToken();
         $refreshToken = $google->getRefreshToken() == null ? '' : $google->getRefreshToken();
         $this->socialLogin('google', $data->id, $data->displayName, $data->email, $data->photo, $accessToken, $refreshToken);
     }
     if ($action == 'youtube') {
         $OAUTH = $this->db()->select($this->table->social_oauth)->where('domain', $this->IM->domain)->where('code', $action)->getOne();
         if ($OAUTH == null) {
             $this->IM->printError('OAUTH_DOMAIN_ERROR');
         }
         $CLIENT_ID = $OAUTH->client_id;
         $CLIENT_SECRET = $OAUTH->client_secret;
         $AUTH_URL = 'https://accounts.google.com/o/oauth2/auth';
         $TOKEN_URL = 'https://accounts.google.com/o/oauth2/token';
         if (Request('SOCIAL_REDIRECT_URL', 'session') == null) {
             $_SESSION['SOCIAL_REDIRECT_URL'] = $_SERVER['HTTP_REFERER'];
         }
         if ($this->isLogged() == false) {
             die($this->getError('NOT_LOGGED'));
         }
         $youtube = new OAuthClient();
         $youtube->setClientId($CLIENT_ID)->setClientSecret($CLIENT_SECRET)->setScope('https://www.googleapis.com/auth/plus.me https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/youtube https://www.googleapis.com/auth/youtube.upload https://www.googleapis.com/auth/youtubepartner https://www.googleapis.com/auth/youtube.force-ssl')->setAccessType('offline')->setAuthUrl($AUTH_URL)->setTokenUrl($TOKEN_URL);
         if (isset($_GET['code']) == true) {
             if ($youtube->authenticate($_GET['code']) == true) {
                 $redirectUrl = $youtube->getRedirectUrl();
                 header('location:' . $redirectUrl);
             }
             exit;
         } elseif ($youtube->getAccessToken() == null) {
             $authUrl = $youtube->getAuthenticationUrl();
             header('location:' . $authUrl);
             exit;
         }
         $data = $youtube->get('https://www.googleapis.com/plus/v1/people/me');
         if ($data === false || empty($data->emails) == true) {
             $this->IM->printError('OAUTH_API_ERROR');
         }
         for ($i = 0, $loop = count($data->emails); $i < $loop; $i++) {
             if ($data->emails[$i]->type == 'account') {
                 $data->email = $data->emails[$i]->value;
                 break;
             }
         }
         $accessToken = $youtube->getAccessToken();
         $refreshToken = $youtube->getRefreshToken() == null ? '' : $youtube->getRefreshToken();
         $check = $this->db()->select($this->table->social_token)->where('midx', $this->getLogged())->where('code', 'youtube')->getOne();
         if ($check == null) {
             $this->db()->insert($this->table->social_token, array('midx' => $this->getLogged(), 'code' => 'youtube', 'user_id' => $data->id, 'email' => $data->email, 'access_token' => $accessToken, 'refresh_token' => $refreshToken))->execute();
         } else {
             $this->db()->update($this->table->social_token, array('user_id' => $data->id, 'email' => $data->email, 'access_token' => $accessToken, 'refresh_token' => $refreshToken))->where('midx', $this->getLogged())->where('code', 'youtube')->execute();
         }
         unset($_SESSION['OAUTH_ACCESS_TOKEN']);
         unset($_SESSION['OAUTH_REFRESH_TOKEN']);
         $redirectUrl = Request('SOCIAL_REDIRECT_URL', 'session') != null ? Request('SOCIAL_REDIRECT_URL', 'session') : '/';
         unset($_SESSION['SOCIAL_REDIRECT_URL']);
         header('location:' . $redirectUrl);
     }
     if ($action == 'github') {
         $OAUTH = $this->db()->select($this->table->social_oauth)->where('domain', $this->IM->domain)->where('code', $action)->getOne();
         if ($OAUTH == null) {
             $this->IM->printError('OAUTH_DOMAIN_ERROR');
         }
         $CLIENT_ID = $OAUTH->client_id;
         $CLIENT_SECRET = $OAUTH->client_secret;
         $AUTH_URL = 'https://github.com/login/oauth/authorize';
         $TOKEN_URL = 'https://github.com/login/oauth/access_token';
         if (Request('SOCIAL_REDIRECT_URL', 'session') == null) {
             $_SESSION['SOCIAL_REDIRECT_URL'] = $_SERVER['HTTP_REFERER'];
         }
         $github = new OAuthClient();
         $github->setClientId($CLIENT_ID)->setClientSecret($CLIENT_SECRET)->setAuthUrl($AUTH_URL)->setScope('user')->setAccessType('offline')->setUserAgent('Awesome-Octocat-App')->setTokenUrl($TOKEN_URL);
         if (isset($_GET['code']) == true) {
             if ($github->authenticate($_GET['code']) == true) {
                 $redirectUrl = $github->getRedirectUrl();
                 header('location:' . $redirectUrl);
             }
             exit;
         } elseif ($github->getAccessToken() == null) {
             $authUrl = $github->getAuthenticationUrl();
             header('location:' . $authUrl);
             exit;
         }
         $data = $github->get('https://api.github.com/user');
         if ($data === false || empty($data->email) == true) {
             $this->IM->printError('OAUTH_API_ERROR');
         }
         $accessToken = $github->getAccessToken();
         $refreshToken = $github->getRefreshToken() == null ? '' : $github->getRefreshToken();
         $this->socialLogin('github', $data->id, $data->name, $data->email, $data->avatar_url, $accessToken, $refreshToken);
     }
     $this->IM->fireEvent('afterDoProcess', 'member', $action, $values, $results);
     return $results;
 }
Пример #9
0
session_start();
require_once '../OAuthClient.class.php';
$CLIENT_ID = '262048643983887';
$CLIENT_SECRET = 'ff6440811c9834222fd8cbc60efd1ccd';
$AUTH_URL = 'https://graph.facebook.com/oauth/authorize';
$TOKEN_URL = 'https://graph.facebook.com/oauth/access_token';
$facebook = new OAuthClient();
$facebook->setClientId($CLIENT_ID)->setClientSecret($CLIENT_SECRET)->setAuthUrl($AUTH_URL)->setTokenUrl($TOKEN_URL);
if (isset($_GET['code']) == true) {
    if ($facebook->authenticate($_GET['code']) == true) {
        $redirectUrl = $facebook->getRedirectUrl();
        header('location:' . $redirectUrl);
    }
    exit;
} elseif ($facebook->getAccessToken() == null) {
    $authUrl = $facebook->getAuthenticationUrl();
    header('location:' . $authUrl);
    exit;
}
?>
<html lang="ko">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=1000">
<title>SimpleOAuth2Client Examples - Facebook</title>
</head>
<body>
	<pre>
<?php 
Пример #10
0
 /**
  * ask twitter for an access token
  *
  * @author Matthias Pfefferle
  * @param string $pTokenKey
  */
 public function getAccessToken($pOAuthToken)
 {
     $lAccessToken = OAuthClient::getAccessToken($this->getConsumer(), "http://api.yigg.local/oauth/1/access", $pOAuthToken, "GET", array("oauth_verifier" => $pOAuthToken->verifier));
     return $lAccessToken;
 }
Пример #11
0
 /**
  * ask tumblr for an access token
  *
  * @author Matthias Pfefferle
  * @param string $pTokenKey
  */
 public function getAccessToken($pOAuthToken)
 {
     $lAccessToken = OAuthClient::getAccessToken($this->getConsumer(), "http://www.tumblr.com/oauth/access_token", $pOAuthToken, "GET", array("oauth_verifier" => $pOAuthToken->verifier));
     return $lAccessToken;
 }
Пример #12
0
session_start();
require_once '../OAuthClient.class.php';
$CLIENT_ID = 'b3f954eccc5378afbacf';
$CLIENT_SECRET = '4507787bbac2f89382c5b29dc07017bbc776c218';
$AUTH_URL = 'https://github.com/login/oauth/authorize';
$TOKEN_URL = 'https://github.com/login/oauth/access_token';
$github = new OAuthClient();
$github->setClientId($CLIENT_ID)->setClientSecret($CLIENT_SECRET)->setAuthUrl($AUTH_URL)->setScope('user')->setUserAgent('Awesome-Octocat-App')->setTokenUrl($TOKEN_URL);
if (isset($_GET['code']) == true) {
    if ($github->authenticate($_GET['code']) == true) {
        $redirectUrl = $github->getRedirectUrl();
        header('location:' . $redirectUrl);
    }
    exit;
} elseif ($github->getAccessToken() == null) {
    $authUrl = $github->getAuthenticationUrl();
    header('location:' . $authUrl);
    exit;
}
?>
<html lang="ko">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=1000">
<title>SimpleOAuth2Client Examples - GitHub</title>
</head>
<body>
	<pre>
<?php 
Пример #13
0
    </head>
    <body>
        <?php 
require_once 'OAuth\\AppConfig.php';
require_once 'OAuth\\OAuthClient.php';
// THIS ONLY APPLIES FOR 3rd PARTY APPLICATIONS
// Get the "authenticated" request token here. The Service provider will append this token to the query string when
// redirecting the user's browser to the Callback page
$oauth_token = $_GET["oauth_token"];
// The is the token secret which you got when you requested the request_token
// You should get this because you appended this token secret when you got redirected to the
// Service Provider's login screen
$token_secret = $_GET["oauth_token_secret"];
print 'oauth_token is: ' . $oauth_token . ", oauth_token_secret: " . $token_secret . '<br/>';
$apiConsumer = new OAuthClient(AppConfig::$base_url, AppConfig::$consumer_key, AppConfig::$consumer_secret);
$success = $apiConsumer->getAccessToken($oauth_token, $token_secret);
$access_token = $apiConsumer->getToken();
$token_secret = $apiConsumer->getTokenSecret();
print "Access token: " . $access_token . ", Token Secret: " . $token_secret . '<br/>';
// STORE THE ACCESS TOKEN AND TOKEN SECRET HERE
// This may be database or session or some other mechanism based on what you choose
// If we get the access token successfully, the response header includes the url to get the authenticated user.
$responseHeaders = $apiConsumer->getResponseHeader();
print "Response Header: " . implode("<br/>", $responseHeaders);
// Iterate over the response headers to find the current logged in person
foreach ($responseHeaders as $val) {
    $start = 'Content-Location:';
    $contentLocation = substr($val, 0, 17);
    if ($contentLocation == $start) {
        $personLocation = str_replace($start, "", $val);
    }
Пример #14
0
        /* No, we have no access token, we need to get one by generating a request token then
          asking the user to authorize it */
        
        /* Get request token */
        $request_token = $api->getRequestToken($ECC_ACCESS, $APP_CALLBACK_URL);
        #print_r($request_token); # Useful if you're not sure you've got one
        $_SESSION['request_token'] = serialize($request_token);
        
        /* Redirect user to authorize URL (in this case, it'll be somewhere on entrecredits.com) */
        header("Location: " . $api->getAuthorizeUrl($request_token));
        die;
        
    } else {
        /* Yep, callback, so we're authorized and we can trade our request token for an access token */
        $request_token = unserialize($_SESSION['request_token']);
        $access_token = $api->getAccessToken($request_token, $_GET['oauth_verifier']);
        
        /* Put access token into session. It's all we need now */
        $_SESSION['access_token'] = serialize($access_token);
        
        /* Redirect to cointoss game, now with access token */
        header('Location: ' . $APP_CALLBACK_URL);
        die;
    }
}

/* If we reach this point, we have an access token. Yay! we can get information */

/* Get app api as well */
$app_api = new OAuthClient(new EccServiceProvider(), $consumer);
$app_token = $app_api->selfAuthorize($APP_ACCOUNT_ID);