Guidance creating multi-tenant api

I’m investigating multiple frameworks / approaches to building a new multi-tenant api to support our desktop software. Laminas API tools looks really promising, but I can’t find any examples in the documentation for how to do exactly what I want. Briefly:

Each API call needs to authenticate against a master (or “landlord”) database where all details of each tenant are stored.
Once authenticated, the api call needs to be processed against a different database, one specific to the tenant.

Can I:
Set up multiple database connections, at least one of which will be dynamic? i.e., it connects to one of many tenant databases, depending on the authentication information provided in the request…

Are there any examples of doing any of the above?

Thanks!

Hey Kimball,

a warm welcome to the Laminas forums.

1. Is it possible to use several database connections?
Completely independent of which module you choose, it is always possible to establish multiple database adapters. You can use the native laminas/laminas-db component when using Laminas API Tool. These adapters can be configured for development and production use. An alternative to laminas/laminas-db could be the doctrine module for laminas. A popular object related mapper system.

2. Can database adapters be dependent on a tenant?
Yes, they can. The Laminas API Tools come with a authentication and authorization layer. Then you can read the tenant configuration and apply the database adapter mentioned in it for this tenant. I would the use the authorization capabilities, that the API Tools provide. Then you can read the configuration and apply the database adapter mentioned in it for this tenant. I would use the authorization for such a use case.) for such a use case. A tenant can have specific roles or rights to use a specifig database adapter.

3. Are there many code examples for this purpose?
I guess there is no ready to use solution for your project. What you have in mind can be realized with several components. Each component by itself has application examples in its own documentation. You just have to tie the whole thing together for your needs. On the other hand, there are many smart people in this forum who will be happy to help you.

Hi ezkimo - thank you for the response! I’ll be diving deeper into your suggestions later today. It appears that the link you provided in part 2 is broken. Should I just be looking for an “authorization” module?

Thanks!

Hey,

I 've edited the link. Authentication and Authorization are parts of the API tools. If you want, you can extend that by a RBAC system (Role Based Access Control). Laminas got its own permission package: GitHub - laminas/laminas-permissions-rbac: Provides a role-based access control management. Depending how your tennants should have access in your system, you are totally free to design your authorization system.