【问题标题】:Auth0 access controlAuth0 访问控制
【发布时间】:2016-08-28 09:47:38
【问题描述】:

我正在使用 Auth0 管理多个不同应用程序中的大量用户,其中一些是基于 Web 的,而另一些是基于桌面和移动的。在每个用户的元数据下,我有一个每个用户可以访问的应用程序数组,我想知道在身份验证时如何检查它,以便如果不在该列表中,访问将被拒绝。

我可以在应用程序上非常轻松地做到这一点,但是在 Auth0 上做到这一点会很棒。

【问题讨论】:

    标签: node.js authentication access-control auth0


    【解决方案1】:

    使用如下定义的规则为我提供了我正在寻找的功能:

    function (user, context, callback) {
        // ACL object
        var acl = {
            "someAppName": [ 'user1@mail.com', 'user2@mail.com' ],
            "otherApp": ['user2@mail.com']
        }
    
        // if App is not in the ACL, skip
        if(!acl.hasOwnProperty(context.clientName)){
            return callback(null, user, context);
        }
    
        // check if user has access to app
        var userHasAccess = acl[context.clientName].some(
            function (email) {
                return email === user.email;
            }
        );
    
        if (!userHasAccess) {
            return callback(new UnauthorizedError('Access denied.'));
        }
        callback(null, user, context);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-12-01
      • 2016-11-02
      • 2017-12-29
      • 2019-07-20
      • 2011-06-17
      • 1970-01-01
      • 2018-06-04
      • 2011-03-16
      相关资源
      最近更新 更多