Bladeren bron

Avoid loading user if the userinfo request failed, refs #441

Jordi Boggiano 6 jaren geleden
bovenliggende
commit
48d4f965f7
1 gewijzigde bestanden met toevoegingen van 11 en 0 verwijderingen
  1. 11 0
      src/Packagist/WebBundle/Security/Provider/UserProvider.php

+ 11 - 0
src/Packagist/WebBundle/Security/Provider/UserProvider.php

@@ -55,6 +55,9 @@ class UserProvider implements OAuthAwareUserProviderInterface, UserProviderInter
     public function connect($user, UserResponseInterface $response)
     {
         $username = $response->getUsername();
+        if (!$username || $username <= 0) {
+            throw new \LogicException('Failed to load info from GitHub');
+        }
 
         /** @var User $previousUser */
         $previousUser = $this->userManager->findUserBy(array('githubId' => $username));
@@ -87,6 +90,10 @@ class UserProvider implements OAuthAwareUserProviderInterface, UserProviderInter
     public function loadUserByOAuthUserResponse(UserResponseInterface $response)
     {
         $username = $response->getUsername();
+        if (!$username || $username <= 0) {
+            throw new \LogicException('Failed to load info from GitHub');
+        }
+
         /** @var User $user */
         $user = $this->userManager->findUserBy(array('githubId' => $username));
 
@@ -94,6 +101,10 @@ class UserProvider implements OAuthAwareUserProviderInterface, UserProviderInter
             throw new AccountNotLinkedException(sprintf('No user with github username "%s" was found.', $username));
         }
 
+        if ($user->getGithubId() !== (string) $response->getUsername()) {
+            throw new \LogicException('This really should not happen but checking just in case');
+        }
+
         if ($user->getGithubToken() !== $response->getAccessToken()) {
             $user->setGithubToken($response->getAccessToken());
             $oldScope = $user->getGithubScope();