Multitenant - Dynamic ClientRegistrationRepository #230
-
Hi! I have searched over spring security/spring authorization server/spring-oauth2-client and Stack and I got to the conclusion that what I am trying to achieve might not be possible (or not in the way I want to do it); I am working on the next scenario (requirements):
I am asking here cause I have seen a lot of ch4mp comments on the internet but most of them are from ~ 2 years ago. maybe there is a new perspective? I am not using webflux. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 3 replies
-
You'll probably have to write your own
It might be possible, but there might be easier solutions. Please tell me more about your "Multitenant" use case. Why do you need to add registrations at runtime in an OAuth2 client? How do you intend the possible ClientRegistrations to be selected? etc. P.S.
With Spring Boot, |
Beta Was this translation helpful? Give feedback.
-
thank you for the response. I was thinking of identifying tenants by the URL. What I wish to accomplish is a multi-tenant federator app where I could add a new tenant and his IDPs at runtime. Each tenant might have his own requirements about what identity providers he is going to use. For example, tenant 1 might use Google and Okta, while tenant 2 might choose GitHub. (I have not investigated yet but probably they should be able to also choose SAML). I have tried to write my own ClientRegistrationRepository but it seems like spring security is calling findByRegistrationId just once at initialization. I could register all the clients together with an InMemoryClientRegistrationRepository and use an OncePerRequestFilter to keep for each tenant the right idps, but I cannot register a new client without restarting the app or refreshing some beans (but this is something that I was referring to when I was saying I want to maintain some kind of standard); |
Beta Was this translation helpful? Give feedback.
-
Hi, i am working with @andrei-vss on this. I will try to give more details: So because of the need to be able to add customers at runtime, and because each customer has it's own ClientRegistrations, we need to be able to also add those at runtime. Hope this makes it more clear. |
Beta Was this translation helpful? Give feedback.
If you haven't read this article already, you should. In the solution I built there, I expose a controller endpoint on the BFF with all the "login options" it supports (one per
registration
withauthorization_code
).This list is static, but you could adapt it easily once you have written a mutable
ReactiveClientRegistrationRepository
(again, be careful to make your implementation thread-safe). Of course, instead of building the list in the constructor like I did, you should re-evaluate it each time the login options are queried.The same controller would probably have another endpoint to create the new "tenants" (add registrations - and optionally providers - to the mutable repo).
From th…