Exemplo n.º 1
0
 /**
  * Exchange an auth code for an access token, then send the user back to
  * the home page, now logged in.
  *
  * @return mixed
  */
 public function callback()
 {
     $auth_code = Input::get('code');
     if ($auth_code) {
         $response = OAuth::token($auth_code);
         $access_token = $response['access_token'];
         $expiry_date = Carbon::now()->addSeconds($response['expires_in']);
         Session::set('access_token', $access_token);
         Session::set('access_token_expiry', $expiry_date);
         Api::setAccessToken($access_token);
     }
     return Redirect::to('/');
 }
Exemplo n.º 2
0
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     $now = Carbon::now();
     # look for a token in the session.
     list($token, $expiry) = $this->getSessionToken();
     if ($token == null || $expiry->lte($now)) {
         # look for a token in the cache.
         list($token, $expiry) = $this->getCachedToken();
         if ($token == null || $expiry->lte($now)) {
             # still nothing, then we'll have to get a new one.
             list($token, $expiry) = $this->getNewToken();
             Cache::forever('access_token', $token);
             Cache::forever('access_token_expiry', $expiry);
         }
     }
     # store the access token in the session for later use.
     Session::set('access_token', $token);
     Session::set('access_token_expiry', $expiry);
     Api::setAccessToken($token);
     # permit the action.
     return $next($request);
 }