创建具有多个数据库的单个应用程序 [英] Creating single application with multi dbs

查看:107
本文介绍了创建具有多个数据库的单个应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为我没有通过标题正确描述问题.但是,我有一个.NET Core Web Api应用程序,所有租户都将使用该应用程序.除了单个API实例之外,我还有一个前端Vuejs实例,所有租户都可以将其用作门户".

I don't think I described the problem properly through the title. However, I have a .NET Core Web Api application which all of my tenants will use. As well as the single API instance I have a single frontend Vuejs instance which all tenants can use as a 'portal'.

这些租户每个都有自己的数据库.目前,api均在请求中要求标头tenant来指定要向哪个租户发出请求,然后将根据请求中的租户创建数据库连接.

These tenants each have their own database. Currently the api's all require a header of tenant within a request to specify which tenant the request is being made for, this will then create a db connection according to the tenant from the request.

您不能假装您的其他租户,因为所有api都需要针对租户db的授权.

You can't pretend your a different tenant as all of the api's require authorization against a tenants db.

我想坚持的事情是在使用单个前端vuejs实例登录时确定用户所属的租户.当仅使用api时这不是问题,因为可以通过请求的标头发送承租人,但是我不确定如何解析承租人以便确定将由哪个符号使用的正确db.在所有租户中使用.

I guess the thing I'm stuck on is determining the tenant a user belongs to when logging in using the single frontend vuejs instance. It's not a problem when it comes to just using the api's as the tenant can be sent via the header of the request, but im not sure how to resolve the tenant in order to determine the correct db to use by a sign in which will be used across all tenants.

抱歉,如果我不能很好地解释问题,那是一个棘手的情况.

Apologies if I didn't explain the problem well, it's a tricky situation.

推荐答案

您的用户住在哪里?您可能必须将用户信息提取到一个单独的身份数据库中,该数据库包含该用户属于哪个租户的信息.可以像键值存储一样简单:email-> TenantId.因此,对于登录,您必须查找此tenantId,然后根据正确的租户数据库中的用户信息进行身份验证.

where are your users live? You might have to extract users info into a separate identity database that contains info which user belongs to which tenant. That can be as simple as Key-Value store: email->TenantId. So for login you'll have to look up this tenantId, then authenticate against user info in the correct tenant database.

或者,您可以将所有用户信息拉入一个数据库,其中包含有关该用户的所有信息,包括密码哈希.您还可以使用某些身份提供程序,例如Auth0或IdentityServer-这些功能可以添加用户属性,例如TenantId.

Or you can pull all your user information into a single database that contains all the info about the user, including password hash. You can also use some identity provider like Auth0 or IdentityServer - these have ability to add user properties like TenantId.

无论选择哪种方案,都必须将用户映射到租户的位置只有一个.在多个数据库中查找用户信息并不理想.

Whatever the scenario you choose, you'll have to have a single place where you map user to a tenant. Looking through multiple databases for user info is not ideal.

如果您的Vue.js应用使用的是后端API,则可以通过Cookie或其他方式设置TenantId,以在两次调用之间保留此信息.

If your Vue.js app is using your backend API you can set TenantId in cookie or other way to persist this info between calls.

这篇关于创建具有多个数据库的单个应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆