googleProvider = new Google([ 'clientId' => $_ENV['GOOGLE_CLIENT_ID'] ?? '', 'clientSecret' => $_ENV['GOOGLE_CLIENT_SECRET'] ?? '', 'redirectUri' => $_ENV['APP_URL'] . '/auth/google/callback' ?? 'http://localhost:18000/auth/google/callback', ]); $this->githubProvider = new Github([ 'clientId' => $_ENV['GITHUB_CLIENT_ID'] ?? '', 'clientSecret' => $_ENV['GITHUB_CLIENT_SECRET'] ?? '', 'redirectUri' => $_ENV['APP_URL'] . '/auth/github/callback' ?? 'http://localhost:18000/auth/github/callback', ]); } public function getGoogleAuthorizationUrl(): string { return $this->googleProvider->getAuthorizationUrl([ 'scope' => ['email', 'profile'] ]); } public function getGithubAuthorizationUrl(): string { return $this->githubProvider->getAuthorizationUrl([ 'scope' => ['user:email'] ]); } public function handleGoogleCallback(ServerRequestInterface $request): array { $code = $request->getQueryParams()['code'] ?? null; if (!$code) { throw new \Exception('No authorization code received from Google'); } $token = $this->googleProvider->getAccessToken('authorization_code', [ 'code' => $code ]); $user = $this->googleProvider->getResourceOwner($token); return [ 'provider' => 'google', 'id' => $user->getId(), 'email' => $user->getEmail(), 'name' => $user->getName(), 'avatar' => $user->getAvatar(), ]; } public function handleGithubCallback(ServerRequestInterface $request): array { $code = $request->getQueryParams()['code'] ?? null; if (!$code) { throw new \Exception('No authorization code received from GitHub'); } $token = $this->githubProvider->getAccessToken('authorization_code', [ 'code' => $code ]); $user = $this->githubProvider->getResourceOwner($token); return [ 'provider' => 'github', 'id' => $user->getId(), 'email' => $user->getEmail(), 'name' => $user->getName(), 'avatar' => $user->getAvatarUrl(), ]; } }