/** * Handling the OAuth login */ public function handleOAuthLogin() { // get data from input $code = Input::get('code'); // get google service $googleService = OAuth::consumer('Google'); // check if code is valid // if code is provided get user data and sign in if (!empty($code)) { // This was a callback request from google, get the token $token = $googleService->requestAccessToken($code); // Send a request with it $result = json_decode($googleService->request('https://www.googleapis.com/oauth2/v1/userinfo'), true); $SentryUser = new SentryUser(); // checking if the email domain is allowed if ($SentryUser->validateOAuthAllowedDomains($result['email'])) { $SentryUser->handleOAuthLogin($result); return Redirect::to($this->dashboard); } else { SentryHelper::dsm('This domain is not allowed on this site.', 'warning'); } } else { // get googleService authorization $url = $googleService->getAuthorizationUri(); // return to google login url return Redirect::to((string) $url); } }