0

我正在尝试一个解决方案,其中一个 Web 应用程序服务于多个域,对于每个域我想配置自己的提供程序,使用外部提供程序的应用程序 ID 和秘密,我想要cookie 域提供程序信息根据当前域名从数据库中读取,例如:

switch (currentDomainName)
{
case "web1.com": load cookie domain and providers information for web1.com ...
case "web2.com": load cookie domain and providers information for web2.com ...
...
}

我面临两个主要问题:

  1. 我在 Owin 启动 ConfigureAuth() 中没有可用的 HttpContext,我不确定如何确定在启动早期使用哪个域名...
  2. 我知道每个 Web 应用程序只运行一次 Startup,例如,在第一次访问 web1.com 后,一旦 web1.com 已经设置了 ConfigureAuth(),它就不会再次为 web2.com 运行

我想知道我是否可以覆盖一些 Owin 方法并使其成为非静态的......或者也许找到一种方法以不同的方式实现它(但我仍然喜欢使用 Owin)

我从哪说起呢?

4

1 回答 1

0

您可以获取请求 url,然后在数据库中查找与域相关的客户。可能有一个表格列出了该域的身份提供者

例子

TenantDomains
*************
TenantId      URL ......
tenant1       https://tenant1.company.com
tenant2       https://tenant2.company.com

IdProviders
***********
TenantId       ProviderIds       ......
tenant1        Custom, Social
tenant2        Social

为了便于阅读,这里使用名称而不是标识符。但是,方法仍然保持不变。

您可以在中间件中进行上述所有查找,然后使用中的值,Environment然后根据数据或之前做出的决策设置管道。

例子:

您可以从 OWIN 上下文访问传入请求,并从 owin 上下文的请求本身执行对 HttpRequest 执行的所有操作。

        app.MapWhen(req => req.Request.Headers.ContainsKey("Authorization"), apiAuth =>
        {
            // do anything that matches this request
            apiAuth.UseBearerAuthentication(new BearerAuthenticationOptions());

        });

高温高压

于 2016-07-06T11:27:10.723 回答