Reputation: 155
Based on the EntityFramework and CustomUserService samples, I'm trying to authenticate users against a separate user database.
In the factory, I'm registering the service like this:
factory.UserService = new Registration<IUserService>(resolver => new CustomUserService());
However, if I want to use multiple user databases, how can I inject the repository or the connection string that I want to use?
The goal is have different clients getting authorization to use resources (like API) from the same authorization server, but point to different user repository. So, identity server would use a database where clients, scopes, redirect URIs, etxc, would be set. But to authenticate a user, I would like to use different database, depending on the client.
Is there any way of doing this?
Thanks
Upvotes: 0
Views: 873
Reputation: 164
We had a very similar problem and solved it by using the tenant on the acr_values i.e. on the call to /connect/token, we passed in the following in addition to username, password etc:
acr_values=tenant:YourTenantString
YourTenantString will identify the database environment and from there, inside your user service you can extract it via:
var dbid = context.SignInMessage.Tenant;
from dbid we are able to get the connection string from config
Upvotes: 1