设计用于单点登录的用户表以跨子域使用

时间:2023-04-03
本文介绍了设计用于单点登录的用户表以跨子域使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我们有一个包含子域的站点,例如:

We have a site which has sub domains like:

  1. example.com - 主站点
  2. food.example.com
  3. fashion.example.com

并且每个域和子域都有不同的数据库,如下所示:

And each domain and sub domain has a different database, like this:

  1. exampleDB - 带有用户表的主数据库
  2. foodDB
  3. 时尚数据库

你尝试过什么?

  1. 现在,对于单点登录,我们计划重定向主站点中的用户进行注册.

  1. Right now, for single sign in we have planned to redirect users in our Main Site for signing up.

子域中的订单处理从主数据库中获取 UserID 并存储在相应子域的 Orders 表中.

While order processing in sub domains get the UserID from main DB and store in respective sub domain's Orders table.

出于报告目的,我们将没有 FK 约束UserID 存储在 Orders 表中,因为我们有单独的数据库.

For reporting purposes we store the UserID without FK constraint in the Orders table since we have separate database.

我可以在这里看到 堆栈交换站点有单独的数据库,但它有单独的 用户 表也是吗?

I can see here that stack exchange sites have separate databases, but does it have separate users tables too?

StackExchange Network 配置文件是否存储在单独的数据库中?

我可以从这里看到 每个站点的用户表都有 StackExchange Network 配置文件的 AccountId.

I can see from here that Every site's user table has AccountId of StackExchange Network profile.

示例:

  1. 这里是 ID:7598 的 Nick Craver 网络配置文件

  1. Here is Nick Craver Network Profile with ID:7598

他在历史站点中的个人资料的帐户 ID 与相同 ID 关联:7598 检查 this 查询.

His profile in History Site has Account ID Linked with same ID:7598 check this query.

我在数据哑巴中的任何地方都看不到Accounts表,那么 AccountId 被存储了吗?以及如何使用 AccountId 在多个站点中完成 SSO?

I can't see the Accounts table anywhere in data dumbs , So Were is AccountId stored? And how is SSO done in multiple sites using AccountId ?

我的问题:我们是否需要主数据库中的单个用户表,或者我们必须为子域的数据库和Link Main DB UserID创建单独的用户表,但不需要FK 约束?哪个是购物网站的最佳设计?

My Question: Do we need a single user table in Main DB or we have to create separate user tables for the sub domain's database and Link Main DB UserID but not FK constraint? Which is the best design for a shopping site?

任何帮助都会很棒.

推荐答案

您提到的 UserID 仅在单个 DB 的特定 Users 表中相同.它实际上不是您域中任何用户的标识符.要识别多个数据库中的用户,您需要为每个用户提供域级 ID.一种简单的方法是将一个名为 UID 或类似名称的属性(列)添加到全局唯一 ID(GUID,请参阅 https://msdn.microsoft.com/en-us/library/system.guid(v=vs.110).aspx) 并将其用作域级 ID 来识别用户而不是 UserId.通过这种方式,您可以自由地将用户信息存储在域中的多个数据库中.所以:

The UserID you mentioned is only identical in a specific Users table in a single DB. It's actually not an identifier of any user in your domain. To identify users across multiple databases, you will need a domain-level ID for every user. A simple way is to add one more property (column) named UID or something like that to User class (table), of Global Unique Id (GUID, see https://msdn.microsoft.com/en-us/library/system.guid(v=vs.110).aspx) and use it as domain-level ID to identify users instead of UserId. This way you can freely store user information in multiple databases in your domain. So:

  • 您只能在每个子域的数据库中保存域级 ID,并使用该 ID 从主域数据库中查询完整的用户配置文件.优点:消耗更少的内存.权衡:在分布式系统中,从子域查询用户信息需要更长的时间,因为信息驻留在主数据库中.
  • 您可以在所有数据库中保存完整的用户信息,包括主数据库和子数据库.优点:更快的查询.缺点:消耗更多内存,当用户信息发生变化时,您必须在所有数据库之间同步.

这篇关于设计用于单点登录的用户表以跨子域使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

上一篇:SQL Server 中数据库数量的实际限制? 下一篇:用于报告和日常交易的数据库

相关文章