private function retrieveOAuthInfo(PhabricatorOAuthProvider $provider)
 {
     $oauth_info = id(new PhabricatorUserOAuthInfo())->loadOneWhere('oauthProvider = %s and oauthUID = %s', $provider->getProviderKey(), $provider->retrieveUserID());
     $scope = $this->getRequest()->getStr('scope');
     if (!$oauth_info) {
         $oauth_info = new PhabricatorUserOAuthInfo();
         $oauth_info->setOAuthProvider($provider->getProviderKey());
         $oauth_info->setOAuthUID($provider->retrieveUserID());
         // some providers don't tell you what scope you got, so default
         // to the minimum Phabricator requires rather than assuming no scope
         if (!$scope) {
             $scope = $provider->getMinimumScope();
         }
     }
     $oauth_info->setAccountURI($provider->retrieveUserAccountURI());
     $oauth_info->setAccountName($provider->retrieveUserAccountName());
     $oauth_info->setToken($provider->getAccessToken());
     $oauth_info->setTokenStatus(PhabricatorUserOAuthInfo::TOKEN_STATUS_GOOD);
     $oauth_info->setTokenScope($scope);
     // If we have out-of-date expiration info, just clear it out. Then replace
     // it with good info if the provider gave it to us.
     $expires = $oauth_info->getTokenExpires();
     if ($expires <= time()) {
         $expires = null;
     }
     if ($this->tokenExpires) {
         $expires = $this->tokenExpires;
     }
     $oauth_info->setTokenExpires($expires);
     return $oauth_info;
 }