【问题标题】:Extend User authentication object in Azure Mobile Services在 Azure 移动服务中扩展用户身份验证对象
【发布时间】:2013-05-07 05:42:55
【问题描述】:

是否可以在 WAMS 中向服务器上的用户对象添加其他属性?我想存储我的 User 表的 Id 主键以在我的表脚本中(安全)使用。目前唯一的 id 是供应商特定的身份验证 ID,但我希望能够允许用户选择一种身份验证方法。目前我的(简化的)表格设计如下:

用户表:

  • 身份证
  • googleId
  • twitterId
  • facebookId
  • 姓名等...

联赛表

  • 身份证
  • 用户ID
  • 姓名等

我想将用户主键存储在联赛表的 userId 字段中,然后对其进行查询以确保用户只能看到他们创建的联赛。目前,表脚本中的用户对象通过带有 Google/Twitter/Windows 身份验证令牌的用户对象发送,每次我想对表执行操作时,我都必须进行查询以获取主键 userID一个 userId 列。

理想的解决方案是,当我的用户表上的插入脚本在注册和登录时被调用时,我可以这样做:

// PSEUDO CODE
function insert(item, user, request) {
    var appUserId;
    Query the user table using the user.userId Google/Twitter/Facebook id
    If user exists {
       // Set a persisted appUserId to use in all subsequent table scripts.
       user.appUserId = results.id;
    } else {
         Set the GooTwitFace columns on the user table, from user.userId
         insert the user then get the inserted record id
             // Set a persisted appUserId to use in all subsequent table scripts
            user.appUserId = insertUserPK;
    }
}

然后,在后续的表格脚本中,我想在查询中使用user.appUserId

【问题讨论】:

    标签: azure-mobile-services


    【解决方案1】:

    如果您要做的只是授权用户只能访问他们自己的数据,我不确定您是否需要“用户”表。只需在用户对象上使用特定于提供者的 userId 来查询您的“联盟”表(确保 userId 列已编入索引)。这些值将是特定于提供者的,但这不应该有任何区别。

    如果您试图在用户的 Google/Facebook/Twitter 登录中维护单一用户身份的概念,那么这是一个更复杂的问题,您需要一个“用户”表和您所描述的查找类型。我们希望将这种场景的支持作为开箱即用的功能提供。自己做这件事是可能的(但相当混乱),如果这就是你想要做的,请告诉我。

    【讨论】:

    • 感谢 Yavor,我正在尝试使用多个提供商的 1 个用户 ID。我想解决我的问题的另一种方法可能是会话对象?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-13
    • 1970-01-01
    • 2016-01-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多