【问题标题】:Ionic and Firebase Authentication Security with Domain Restrictions具有域限制的 Ionic 和 Firebase 身份验证安全性
【发布时间】:2018-06-12 05:53:46
【问题描述】:

我正在使用 Ionic 和 Firebase 身份验证(Google 登录方法)来对用户进行身份验证。我的身份验证工作正常。问题是如果用户来自我公司的域 (jimmy @neutron.ca),我只想允许访问我的应用程序(登录 --- 而不是身份验证)。

我只希望我的员工登录应用程序并访问登录页面之外的界面。我只希望我的员工能够提交他们的工作时间(这是登录后申请的范围)。

我的问题是,对用户进行身份验证和登录的安全方法是什么?

在我们从firebase google登录方法获取身份验证对象后,在客户端离子应用程序上计算用户是否属于特定域是否安全?

login() {
  this.afAuth.auth.signInWithPopup(new firebase.auth.GoogleAuthProvider())
    .then(res => {
      // example email object = 'jimmy@neutron.com'
      // get email object, split('@')[1] on it
      // if result of split (@neutron.com) is eqaul to my domain (neutron.com), which it is, then log user in
        this.navCtrl.setRoot(AuthenticatedPage);
      // if not, unauthenticate and present unauthorized message to user.
    })
}

如果在客户端的 ionic 中这样做不安全,那么我们该如何计算呢? firebase 可以计算吗?

【问题讨论】:

    标签: security firebase authentication ionic-framework firebase-authentication


    【解决方案1】:

    如果我理解正确的话。您需要将 hd 自定义 OAuth 参数传递给 Google 提供商:

    const provider = new firebase.auth.GoogleAuthProvider();
    provider.setCustomParameters({hd: 'neutron.ca'});
    this.afAuth.auth.signInWithPopup(provider);
    

    但是,用户仍然可以绕过它,因为 Google 没有强制执行(检查电子邮件域)。 您还需要通过安全规则(如果您使用 Firebase 规则)或在解析 ID 令牌并通过 Firebase Admin SDK 进行验证时强制执行。

    【讨论】:

    • 我没有使用 Firebase 数据库,只是使用 Firebase Auth,这意味着我不能使用规则,因为它们适用于数据库。我最终做的是在客户端检查域,然后在匹配时允许访问该应用程序。然后存储firebase用户节点并将其与任何其他数据一起发送到服务器,然后在服务器端不允许访问,除非他们被允许。我不认为这是最好的方法,但我认为它仍然是一种安全的方法。
    • 您在服务器上解析时需要检查 ID 令牌。 ID 令牌包含 email 字段,这是安全的做法。当您向服务器发送请求时,您应该始终发送 ID 令牌以识别用户。
    猜你喜欢
    • 1970-01-01
    • 2020-12-12
    • 1970-01-01
    • 2016-05-13
    • 2015-07-23
    • 2019-01-20
    • 1970-01-01
    相关资源
    最近更新 更多