Oauth2限制使用hd的具有特定域名的电子邮件不起作用 [英] Oauth2 restrict to emails with specific domain name using hd not working

查看:93
本文介绍了Oauth2限制使用hd的具有特定域名的电子邮件不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用通过在我的请求的hd参数中指定abc.com来限制Oauth2的登录到特定域,例如abc.com.

My app was restricting logins by Oauth2 to specific domain like abc.com by specifying abc.com in the hd parameter in my request .Restrict Login Email with Google OAuth2.0 to Specific Domain Name but since these past few days its allowing anyone with a Google account login.I am sure i didn't change the code and even verified the result uri has my domain name specified in its hd parameter following this link instruction https://developers.google.com/identity/protocols/OpenIDConnect#hd-param .so cany any one tell me what i am doing wrong? here is my code

     `redirect( uri : "https://accounts.google.com/o/oauth2/auth?" +
            "redirect_uri=${redirectUri}&" +
            "response_type=code&" +
            "client_id="${my_client_id}"& +
            "scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email" +
            "+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.profile&" +
            "approval_prompt=auto&" +
            "hd=apposit.com")`

推荐答案

我不知道为什么会这样,但是您可以使用java的contains()检查用户电子邮件中是否包含abc.com,从而在hd之外添加第二种安全机制.方法或 endsWith()(更可靠),然后您才允许用户在您的应用中进行任何操作.

I dont know why this is happening,but you can add a second security mechanism besides hd by checking if the user email contains abc.com using java's contains() method or endsWith() which is more reliable before u allow the user to go any further in Your app.

但这仍然是一个快速解决方案,其他有解决方案的人应该回答这个问题

But still this is a quick fix and others with a solution should answer this question

这篇关于Oauth2限制使用hd的具有特定域名的电子邮件不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆