检查 google oauth 的电子邮件 ID 的域名
Check domain name of email Id for google oauth
我正在尝试使用 google oauth 验证我的应用程序。我只想允许一组具有特定“@eg.com”的特定人员能够获得访问权限。
我试过包括
hd="eg.com"
在我的 url 中。
但它甚至接受“@gmail.com”或“@company.com”域。
有没有办法做到这一点,让像 "users@eg.com" 这样的用户只获得访问令牌和其他东西?
编辑:
我在我的应用程序中使用 webview 来执行授权
我想你必须在你的应用程序中实现它
如果域部分不是允许的,只是不存储令牌并显示一些错误消息。
您可以使用
在 c# 中获取域部分
string s = "users@eg.com";
string[] words = s.Split('@');
words[0]
将是 users
而 words[1]
将是 eg.com
或者您可以使用 MailAddress
您可以(并且应该!)通过调用 google api 来验证您的 id_token。调用 https://www.googleapis.com/oauth2/v3/tokeninfo?id_token=XYZ123
并检查响应的各个字段。如果您请求 "profile" 权限,您还将获得 email
字段。然后您可以根据您的域检查此电子邮件,如果不适合则拒绝访问。
有关详细文档,请参阅:
https://developers.google.com/identity/sign-in/web/backend-auth#calling-the-tokeninfo-endpoint
我正在尝试使用 google oauth 验证我的应用程序。我只想允许一组具有特定“@eg.com”的特定人员能够获得访问权限。
我试过包括
hd="eg.com"
在我的 url 中。 但它甚至接受“@gmail.com”或“@company.com”域。 有没有办法做到这一点,让像 "users@eg.com" 这样的用户只获得访问令牌和其他东西?
编辑: 我在我的应用程序中使用 webview 来执行授权
我想你必须在你的应用程序中实现它 如果域部分不是允许的,只是不存储令牌并显示一些错误消息。
您可以使用
在 c# 中获取域部分string s = "users@eg.com";
string[] words = s.Split('@');
words[0]
将是 users
而 words[1]
将是 eg.com
或者您可以使用 MailAddress
您可以(并且应该!)通过调用 google api 来验证您的 id_token。调用 https://www.googleapis.com/oauth2/v3/tokeninfo?id_token=XYZ123
并检查响应的各个字段。如果您请求 "profile" 权限,您还将获得 email
字段。然后您可以根据您的域检查此电子邮件,如果不适合则拒绝访问。
有关详细文档,请参阅: https://developers.google.com/identity/sign-in/web/backend-auth#calling-the-tokeninfo-endpoint