/// add Google as a provider $googleProvider->setUserID($user->getID()); $googleProvider->setGoogleID($userGoogleData['id']); $googleProvider->getDataFromDB(); $googleProvider->save(); // refresh providers $user->fetchProviders(); $jwt = $user->getJWT(); $headersHandler->sendJSONData(['token' => $jwt]); $outputHandler->write($jwt); } } break; case "facebook": $code = $headersHandler->getHeader('code'); $facebookClient = new FacebookProvider($database); $accessToken = $facebookClient->exchangeCodeForAccessToken($headersHandler->getHeader('clientId'), $headersHandler->getHeader('redirectUri'), $headersHandler->getHeader('code')); $facebookClient->setAccessToken($accessToken); $facebookClient->extendAccessToken(); /*$facebookClient->retrieveAccessTokenFromRedirect(); $accessToken = $facebookClient->getAccessToken();*/ $userData = $facebookClient->getUserData(); $outputHandler->write("user data: "); $outputHandler->write($userData); $outputHandler->write("access token: "); $outputHandler->write($accessToken); if ($headersHandler->isAuthenticated()) { // Link accounts if not linked previously and facebookID does not repeat $user = new User($database, $headersHandler->getBearer()); $facebookClient->setUserID($user->getID()); if ($facebookClient->facebookIDRepeatsAmount() == 0) {
public function fetchProviders() { $googleClient = new Google_Client(); $facebookProvider = new FacebookProvider($this->db, $this->id); $facebookProvider->searchByUserID(); $this->auth = ['google' => new GoogleProvider($this->db, $this->id, $googleClient), 'facebook' => $facebookProvider]; }