Пример #1
0
 public function getCurrentSession()
 {
     if (empty($_SESSION[self::SessionKey])) {
         throw new \ForbiddenException('Odnoklassniki token not found');
     }
     $session = $_SESSION[self::SessionKey];
     $token = new Token($session['type'], $session['accessToken'], $session['identifier'], $session['expires']);
     $api = new ApiOd($this->config['app_public'], $this->config['app_secret'], $token);
     $user = $api->getProfile();
     if (empty($user)) {
         throw new \RuntimeException($api->getError());
     }
     return ['id' => $user->id, 'name' => $user->firstName . ' ' . $user->lastName];
 }
Пример #2
0
 protected function parseToken($token)
 {
     if (!is_array($token)) {
         throw new \RuntimeException('Not an array. $token - ' . print_r($token, true));
     }
     $data = ['application_key' => $this->publicKey, 'method' => 'users.getCurrentUser', 'access_token' => $token['access_token'], 'format' => 'json'];
     $response = ApiOd::request($data, $this->getSecret());
     if (isset($response['error'])) {
         throw new \RuntimeException($response['error']);
     }
     $token['user_id'] = $response['uid'];
     $token['expires_in'] = static::TOKEN_EXPIRES_IN;
     return $token;
 }