gpt4 book ai didi

javascript - Google 登录 - 检查用户是否属于特定组织

转载 作者:行者123 更新时间:2023-11-30 21:17:46 25 4
gpt4 key购买 nike

我正在尝试检查登录用户是否属于特定组织。

我所说的组织是指 G Suite 组织。比如我所在的公司是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>

最佳答案

我建议只查询用户电子邮件,然后检查该电子邮件地址的域。

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

关于javascript - Google 登录 - 检查用户是否属于特定组织,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45496302/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com