通过 Google oAuth 仅向拥有商业公司邮件地址的人授予访问权限

Grant access via Google oAuth only to those who have a business company mail address

我想使用 Google 的 oAuth 对内部系统的用户进行身份验证。我们使用 GMail 的商业版本。意思是名字@company.com。现在我想只向在公司内拥有电子邮件的人授予访问权限。

我没有找到使用 Google 的 oAuth 的 Java 文档的线索。这可能吗?

建议您使用Google's OpenID connect实现。

当您收到用户的身份令牌时,内容将类似于:

{"iss":"accounts.google.com",
 "at_hash":"HK6E_P6.....DB1Q",
 "email_verified":"true",
 "sub":"10769150350006150715113082367",
 "azp":"1234987819200.apps.googleusercontent.com",
 "email":"bob@example.com",
 "aud":"1234987819200.apps.googleusercontent.com",
 "iat":1353601026,
 "exp":1353604926,
 "hd":"example.com" }

电子邮件参数将包含您可以用来确定有效性的电子邮件地址。 "hd"参数为域名。

您可以尝试使用您的域。转到 https://developers.google.com/oauthplayground/ 和 select: Google OAuth2 API v2 然后: https://www.googleapis.com/auth/userinfo.email

然后"Authorize API",回答"Request for Permissions"

然后Select"Exchange Authorization code for tokens"

然后上车https://www.googleapis.com/oauth2/v2/userinfo (这会将 ID 令牌呈现给用户信息端点)

return 类似于:

{
  "family_name": "Example", 
  "name": "Bob Example", 
  "picture": "https://lh5.googleusercontent.com/-.....jpg", 
  "gender": "male", 
  "email": "bob@example.com", 
  "link": "https://plus.google.com/+BobExample", 
  "given_name": "Bob", 
  "id": "117157805301848682081", 
  "hd": "example.com", 
  "verified_email": true
}