2016-07-22 27 views
0

我正在使用Google PHP API對用戶登錄進行身份驗證。我想限制對特定電子郵件域的登錄訪問,例如只有擁有電子郵件@ thedomain.com的用戶才能登錄。限制OAuth登錄到特定的電子郵件域

我試過按照建議設置hd parameter,沒有運氣。我也注意到,返回$client = new Google_Client();對象返回["hd"]=> string(0) ""

檢查email domain after authentication可能是可行的一個空字符串,但我一樣下跌必有谷歌API中的一個方法。

任何人有想法或建議嗎?

回答

0

結束了使用的hd對象,這需要實例化新$service

if (isset($_SESSION['access_token']) && $_SESSION['access_token']) { 
     $client->setAccessToken($_SESSION['access_token']); 
     // create service to pull userinfo 
     $service = new Google_Service_Oauth2($client); 
     $user = $service->userinfo->get(); 
     $userHd = $user['hd']; 
     if ($userHd === 'thedomain.com') { 
      // log the user in 
     } 
相關問題