okta / okta-sdk-dotnet

A .NET SDK for interacting with the Okta management API, enabling server-side code to manage Okta users, groups, applications, and more.
Other
160 stars 100 forks source link

Multiple IOktaClients in Startup ConfigureServices for multi-tenancy/multiple domains #591

Closed dillonkuester closed 2 years ago

dillonkuester commented 2 years ago

Describe the feature request?

We're looking to target multiple Okta domains in our microservice which utilizes the OktaSDK.

Here is what we are thinking so far, but to do this dynamically we will need to use each okta client individually? Is it possible to instantiate multiple IOktaClients or is there documentation for this?

    ```
    .AddSingleton<IOktaClient, OktaClient>(factory =>
            {
                return new OktaClient(new Okta.Sdk.Configuration.OktaClientConfiguration
                {
                    Token = Configuration["Config:Okta:Token"],
                    OktaDomain = Configuration["Config:Okta:Domain"]
                }, factory.GetService<ILogger<OktaClient>>());
            })
            .AddSingleton<IOktaClient, OktaClient>(factory =>
            {
                return new OktaClient(new Okta.Sdk.Configuration.OktaClientConfiguration
                {
                    Token = Configuration["Config:**OktaNewClient**:Token"],
                    OktaDomain = Configuration["Config:**OktaNewClient**:Domain"]
                }, factory.GetService<ILogger<OktaClient>>());
            })

Would configuration 2 be similar?
https://developer.okta.com/docs/concepts/multi-tenancy/#hub-and-spoke-physical-layout

Additionally is this something that can be dynamic solely based on our appsettings?

### New or Affected Resource(s)

IOktaClient 

### Provide a documentation link

https://developer.okta.com/okta-sdk-dotnet/latest/api/Okta.Sdk.IOktaClient.html

### Additional Information?

_No response_
bryanapellanes-okta commented 2 years ago

@dillonkuester Thanks for reaching out! It is possible to instantiate any number of OktaClients that you may need. However, registering them each as singletons the way you describe will likely require additional code to resolve which instance you want. Is it a limited list of known domains or potentially many domains somehow determined dynamically at runtime?

A couple approaches, without knowing all the details of your requirements:

laura-rodriguez commented 2 years ago

CLosing due to inactivity