/**
  * Attempts to authenticate the user.
  *
  * @param \App\Models\User\User  $user
  * @param \Illuminate\Auth\Guard $auth
  *
  * @return \Illuminate\Http\RedirectResponse
  */
 public function callback(User $user, Guard $auth)
 {
     try {
         $payload = $this->socialite->user();
     } catch (Exception $e) {
         $this->flash('Failed to sign in via GitHub, did you decline?', Controller::FLASH_ERROR);
         return redirect()->route('get::front.home');
     }
     try {
         $response = app('GuzzleHttp\\Client')->get('https://api.github.com/user/emails?access_token=' . $payload->token, ['headers' => ['Accept' => 'application/vnd.github.v3+json']]);
         $emails = $response->json();
     } catch (Exception $e) {
         $this->flash('Failed to sign in via GitHub, is your GitHub account verified?', Controller::FLASH_ERROR);
         return redirect()->route('get::front.home');
     }
     $email = array_filter($emails, function ($email) {
         return $email['primary'];
     });
     if (count($email) === 0) {
         $this->flash('Failed to sign in via GitHub, is your GitHub account verified?', Controller::FLASH_ERROR);
         return redirect()->route('get::front.home');
     }
     $email = array_get(array_values($email)[0], 'email');
     $user = $user->firstOrCreate(['uid' => $payload->id]);
     $user->update(['token' => $payload->token, 'email' => $email, 'nickname' => $payload->nickname, 'name' => $payload->nickname]);
     $auth->login($user, true);
     return redirect()->intended('/home');
 }
 protected function getUserByToken($token)
 {
     $user = parent::getUserByToken($token);
     $user['groups'] = $this->getGroupsByToken($token, $user['login']);
     return $user;
 }
Example #3
0
 /**
  * @param Request $clientId
  * @param string  $clientSecret
  * @param string  $redirectUrl
  */
 public function __construct($clientId, $clientSecret, $redirectUrl)
 {
     /** @var Request $request */
     $request = \Request::instance();
     parent::__construct($request, $clientId, $clientSecret, $redirectUrl);
 }