# How to authenticate users from different realms against a single application?

**URL:** <https://forum.keycloak.org/t/how-to-authenticate-users-from-different-realms-against-a-single-application/10659>\
**Category:** Securing applications\
**Tags:** authentication\
**Created:** [August 24, 2021, 2:42pm UTC](https://forum.keycloak.org/t/how-to-authenticate-users-from-different-realms-against-a-single-application/10659 "2021-08-24T14:42:05Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![beleza](https://avatars.discourse-cdn.com/v4/letter/b/3bc359/32.png) [@beleza](https://forum.keycloak.org/u/beleza)\
**Post date:** [August 24, 2021, 2:42pm UTC](https://forum.keycloak.org/t/how-to-authenticate-users-from-different-realms-against-a-single-application/10659/1 "2021-08-24T14:42:05Z")

</div>

Dear all,

I have the following situation:

My application consists in a frontend and a backend micro service, which both authenticate themselves via the same realm on one keycloak server. This set-up has been used for development, but now I need to extend it to support multi tenancy, because in the future each customer (tenant) should get its own realm with individual user accounts. However, since the user’s realm must already be known before logging in, I am wondering if this is even possible with Keycloak.  
An alternative would be to work with one single realm for all tenants and to do the mapping (users - tenant) via groups/roles. However, this is no suitable solution for me, as the tenants should not be able to see each other’s user accounts in keycloak. I need to have them in different realms.  
So my question would be if there is any solution to authenticate users from different realms against a single application?

Your help will be much appreciated.

---

<div class="post-metadata">

**Author:** ![xgp](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/xgp/32/2589_2.png) [@xgp](https://forum.keycloak.org/u/xgp)\
**Post date:** [August 24, 2021, 5:17pm UTC](https://forum.keycloak.org/t/how-to-authenticate-users-from-different-realms-against-a-single-application/10659/2 "2021-08-24T17:17:25Z")

</div>

You can find a lot of discussions here and on the mailing lists about multi-tenancy. There is no one right way to do it.

The multiple realms can be IdPs to a single realm that is used by your application, but your customers must know which realm to use (some people have solved this with a custom authenticator that looks them up by their email address to route them to the correct IdP).

The single realm solution, with mapping done by groups is also a good solution. There is nothing that requires users to “see each other’s user accounts”, unless you are giving them that admin role.

A few docs:

- [Using Keycloak for Multi-Tenancy With One Realm | by Dale Bingham | The Startup | Medium](https://medium.com/swlh/using-keycloak-for-multi-tenancy-with-one-realm-7be81583ed7b)
- [Securing Applications and Services Guide](https://www.keycloak.org/docs/latest/securing_apps/#_multi_tenancy)
- [keycloak/examples/multi-tenant at master · keycloak/keycloak · GitHub](https://github.com/keycloak/keycloak/tree/master/examples/multi-tenant)

Also, a good ol’ search for “multi tenant keycloak” came up with a lot of great articles.
