我的应用程序通过在我的请求中的hd参数中指定abc.com来限制Oauth2登录到特定域,如abc.com.使用Google OAuth2.0将登录电子邮件限制为特定域名,但由于过去几天它允许任何拥有Google帐户的人登录.我确信我没有更改代码甚至验证结果uri已在其中指定了我的域名高级参数跟随此链接说明https://developers.google.com/identity/protocols/OpenIDConnect#hd-param .so cany任何人告诉我我做错了什么?这是我的代码
`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")`
Run Code Online (Sandbox Code Playgroud) 编辑:我改变了我想要这样做的方式我想我会使用MySQL表将设计登录列入白名单.已更改的问题发布在此处:使用Ruby限制使用Google OAuth2.0登录并设置为特定白名单表
好吧所以我试图使用Devise和Omni-Auth2并仅谷歌获得我在ruby on rails网站上的受限身份验证.到目前为止一切正常,但我只希望接受来自某个域的电子邮件.无论如何我都愿意这样做.
我做了一些谷歌搜索,但似乎一些PHP用户比我更多的本地文件,可能是因为在本地使用谷歌API客户端?我并不完全确定,因为我对编码一般都很陌生并且很惊讶我做到了这一点.
以下是一个示例:使用Python的Google Oauth2.0:如何限制对特定域的访问?
在这里:使用Google OAuth2.0将登录电子邮件限制为特定域名
两者似乎都使用"hd:domain"或类似的东西,但似乎有问题加上我不确定如何在我的应用程序中实现它.
现在获取更多信息,我只使用gem devise和omniauth-google-oauth2(https://github.com/zquestz/omniauth-google-oauth2)我觉得这是一种方法来处理这个宝石但仍然不完全确定.如果我可以发布任何更多信息让我知道,任何帮助将不胜感激.
我的omniauth_callbacks_controller:
class User::OmniauthCallbacksController < Devise::OmniauthCallbacksController
def google_oauth2
# You need to implement the method below in your model (e.g. app/models/user.rb)
@user = User.find_for_google_oauth2(request.env["omniauth.auth"], current_user)
if @user.persisted?
flash[:notice] = I18n.t "devise.omniauth_callbacks.success", :kind => "Google"
sign_in_and_redirect @user, :event => :authentication
else
session["devise.google_data"] = request.env["omniauth.auth"]
redirect_to new_user_registration_url
end
end
end
Run Code Online (Sandbox Code Playgroud) 根据brijieshb42的使用requests_oauthlib 的文章,开发供公司内部使用的Flask应用程序(Python3 / Heroku),并成功实现了Google Login(Oauth2)。
研究表明,如果我在授权URL中传递参数“ hd”(托管域),则可以解决问题。例如
https://accounts.google.com/o/oauth2/auth?response_type=code&client_id=OUR_CLIENT_ID&redirect_uri=https%3A%2F%2FOUR_APP.herokuapp.com%2Fconnect&scope=profile+email&state=STATE&hd = our_google_apps_domain.com&access_type = offline
我的理解是,此参数应提供客户端限制,并且仅允许基于Google文档,此邮件列表帖子和以下stackoverflow帖子使用来自Google Apps域的电子邮件登录(服务器端,我将在此之后处理!):post1,post2。
但是,尽管我的代码生成了我上面粘贴的授权URL,但是我仍然可以使用我的个人gmail帐户(@ gmail.com与@our apps domain.com)登录。
任何人都可以阐明为什么它不起作用吗?还是提供不同的方法?基本上,宁愿阻止非员工登录。
我可以根据需要共享代码,但是几乎可以从brijeshb42文章中粘贴出来,并且基本上是这样的:
OAuth2Session(
OUR_CLIENT_ID,
redirect_uri=https://OUR_APP.herokuapp.com/connect,
scope=['profile', 'email']).authorization_url(
https://accounts.google.com/o/oauth2/auth,
hd='our_google_apps_domain.com',
access_type='offline')
Run Code Online (Sandbox Code Playgroud)
哪个返回我上面粘贴的身份验证网址!
我知道如何通过google-signin-client_id 3089273xx-xxxxxxxxxxxx.apps.googleusercontent.com&创建经过Google身份验证的应用<script src="https://apis.google.com/js/platform.js" async defer></script>,但问题是,我无法将登录限制为仅限我公司的G Suite实例.
我的应用程序是一个托管在S3上的"无服务器"JS包.登录的Google令牌与访问敏感资源的AWS角色相关联.
因此,检查电子邮件googleUser.getBasicProfile()或传递hd参数的典型解决方案没有任何安全意义,因为它们可以使用浏览器开发工具IIUC进行操作.
我可以使用其他一些Google API或我可以应用的策略吗?我想这个解决方案将以我公司域名的特殊google-signin-client_id的形式出现,该域名由G Suite托管.这就是它与AWS角色的关系:
我知道我可以在AWS"用户池"中设置重复的用户并使用Cognito,但我正在尝试为公司员工提供"单一事实来源"并减轻管理负担.
我在网站上有 Django Social Auth(pypi 包social-auth-app-django)与 Google OAuth2 一起使用。
当他们打开页面时,他们会被重定向到 Google 的 OAuth2 身份验证。这非常有效,如果他们尝试使用不在我的限制列表中的电子邮件地址登录,他们会收到 AuthForbidden 异常。我为此添加了一个陷阱,并向他们显示一个不允许他们登录此网站的页面。到目前为止一切都很好。
但是,我希望无效的电子邮件帐户根本不显示在 Google 身份验证页面的列表中。在使用带有参数的 javascript 之前,我已经通过手动调用身份验证页面来完成此操作,但我不确定如何使用罐装 Django 社交身份验证模块来执行此操作。
这可以做到吗?如果可以,怎么做?
我有中间件可以检测用户是否未登录并返回一个 login() 视图,该视图将用户重定向到 Google 身份验证页面。
视图.py
# Login using OAuth2.
@csrf_protect
def login(request):
next_page = request.path
if next_page is None or next_page == '':
next_page = request.POST.get('next', request.GET.get('next', ''))
# Check if they are already logged in and redirect them to the original page if so.
if hasattr(request, 'user') and request.user.is_authenticated:
return HttpResponseRedirect(next_page)
# Otherwise, send them …Run Code Online (Sandbox Code Playgroud) 我想限制用户使用特定的 gmail 域登录我的 Firestore 应用程序。我在这里发现了类似的问题,但这与 Firestore 完全不同。所以让我解释一下我的要求我想要什么。
Suppose one company called abc.com are using the gmail services and they have integrated their all email accounts to gmail. So they can use gmail email services using that account. So I want to restrict to users that only use the username@abc.com gmail account to login to my firestore app.
I have searched a lot but didn't found any documentation about this.
firebase ×2
google-oauth ×2
oauth-2.0 ×2
android ×1
devise ×1
django ×1
flask ×1
google-api ×1
google-login ×1
grails ×1
heroku ×1
python-3.x ×1
security ×1