상속: extends Illuminate\Support\Facades\Facade
예제 #1
0
 public function refreshAccessToken()
 {
     $access_token = $this->access_token;
     $service = Facades\Social::service($this->provider);
     if (2 === Facades\Social::oauthSpec($this->provider)) {
         $token = new StdOAuth2Token();
         $token->setAccessToken(array_get($access_token, 'token'));
         $token->setRefreshToken(array_get($access_token, 'refresh_token'));
     } else {
         $token = new StdOAuth1Token();
         $token->setAccessToken(array_get($access_token, 'token'));
         $token->setAccessTokenSecret(array_get($access_token, 'secret'));
         $token->setRefreshToken(array_get($access_token, 'refresh_token'));
     }
     $service->getStorage()->storeAccessToken(ucfirst($this->provider), $token);
     try {
         $new_token = $service->refreshAccessToken($token);
     } catch (\Exception $e) {
         return false;
     }
     if (!$new_token->getAccessToken()) {
         return false;
     }
     $access_token['token'] = $new_token->getAccessToken();
     if ($new_token->getEndOfLife()) {
         $access_token['end_of_life'] = $new_token->getEndOfLife();
     }
     if ($new_token->getExtraParams()) {
         $access_token['extra_params'] = $new_token->getExtraParams();
     }
     if (2 !== Facades\Social::oauthSpec($this->provider) && $new_token->getAccessTokenSecret()) {
         $access_token['secret'] = $new_token->getAccessTokenSecret();
     }
     $this->access_token = $access_token;
     $this->save();
     return true;
 }
예제 #2
0
 /**
  * Connect action.
  *
  * @param string $provider
  * 
  * @return mixed
  */
 public function getConnect($provider = null)
 {
     if (empty($provider)) {
         App::abort(404);
     }
     $referer = Request::header('referer', '/');
     $referer_parts = parse_url($referer);
     $onboth = array_get($referer_parts, 'path');
     if (array_get($referer_parts, 'query')) {
         $onboth .= '?' . array_get($referer_parts, 'query');
     }
     if (!Input::get('code') && !Input::get('oauth_token')) {
         Session::put('mmanos.social.onsuccess', Input::get('onsuccess', $onboth));
         Session::put('mmanos.social.onerror', Input::get('onerror', $onboth));
     }
     if (!Auth::check()) {
         return Redirect::to(Session::pull('mmanos.social.onerror', '/'))->with(Config::get('laravel-social::error_flash_var'), 'There was a problem connecting your account (1).');
     }
     if (Input::get('denied') || Input::get('error')) {
         return Redirect::to(Session::pull('mmanos.social.onerror', '/'))->with(Config::get('laravel-social::error_flash_var'), 'There was a problem connecting your account (2).');
     }
     $provider = ucfirst($provider);
     try {
         $service = Social::service($provider);
         if (Config::get('laravel-social::providers.' . strtolower($provider) . '.offline')) {
             $service->setAccessType('offline');
         }
     } catch (Exception $e) {
         App::abort(404);
     }
     if (2 === Social::oauthSpec($provider)) {
         return $this->oauth2Connect($provider, $service);
     } else {
         return $this->oauth1Connect($provider, $service);
     }
 }