2017-08-03 75 views
1

我正在嘗試檢查用戶的登錄是否屬於特定組織。Google登錄 - 檢查用戶是否屬於特定組織

按組織,我指的是GSuite組織。例如,我工作的公司是XYZ,我想知道用戶X是否在該組織內。

我按照Google Sign In上的文檔工作,它檢索基本的用戶詳細信息。

這裏就是我到:

<head> 
 
    <title>Pricing</title> 
 
    <meta name="google-signin-client_id" content="<Client ID>"> 
 
</head> 
 

 
<body> 
 
    <div class="g-signin2" data-onsuccess="onSignIn"></div> 
 
    <a href="#" onclick="signOut();">Sign out</a> 
 
    <script src="https://apis.google.com/js/platform.js" async defer></script> 
 
    <script> 
 
    function onSignIn(googleUser) { 
 
     var profile = googleUser.getBasicProfile(); 
 
     console.log('Name: ' + profile.getName()); 
 

 
     /* 
 
     At this point, I want to check if the user belongs to a specific GSuite organisation 
 
     */ 
 
    } 
 

 
    function signOut() { 
 
     var auth2 = gapi.auth2.getAuthInstance(); 
 
     auth2.signOut().then(function() { 
 
     console.log('User signed out.'); 
 
     }); 
 
    } 
 
    </script> 
 
</body>

+0

'這裏是我的位置 - 你在哪裏檢查GSuite組織的會員資格?看起來你只是有一個評論,這實際上不會做任何事情 –

回答

1

我建議只查詢用戶的電子郵件,然後檢查電子郵件地址的域名。

function onSignIn(googleUser) { 
    console.log('Email: ' + profile.getEmail()); // This is null if the 'email' scope is not present. 
}