asp.net-web-api - 从 .NET Framework 4.6 的 azure-service-fabric 服务调用 OWIN 启动调用以使用 Okta
问题描述
我创建了一个针对 .NET Framework 4.6 的 .NET 无状态服务,并希望在同一服务中实现 Okta。
该解决方案对于 .NET Core 应用程序来说非常简单,而且我可以正常工作。
看了很多文章,发现需要使用OWIN启动类来使用okta作为Authentication。
这是做同样事情的示例应用程序: https ://github.com/okta/samples-aspnet/tree/master/okta-hosted-login
现在的问题是服务结构类有自己的 Startup.cs 文件。我已经添加了包来添加一个 Owin 启动类,但我无法调用该 Startup 类,因为它已经有一个。
为此,我发现我们可以创建自己的通信侦听器并按照本文的相同 https://github.com/uglide/azure-content/blob/master/articles/service-fabric/service-fabric-reliable-服务-通信-webapi.md
我已经在使用内置HttpSysCommunicationLisener
的命名空间Microsoft.ServiceFabric.Services
我当前的代码如下所示:
protected override IEnumerable<ServiceInstanceListener> CreateServiceInstanceListeners()
{
return new[]
{
// new ServiceInstanceListener((initParams) => new OwinCommunicationListener("Symphony", new Startup(), initParams), "MyOwin"),
new ServiceInstanceListener(serviceContext =>
new HttpSysCommunicationListener(serviceContext, "Facade", (url, listener) =>
{
url += string.IsNullOrWhiteSpace(TenantCode) ? $"/{ApplicationName}" : $"/{ApplicationName}-{TenantCode}";
var tenantApplicationName = string.IsNullOrWhiteSpace(TenantCode) ? ApplicationName : $"{ApplicationName}/{TenantCode}";
var environment = FabricRuntime.GetActivationContext()
?.GetConfigurationPackageObject("Config")
?.Settings.Sections["Environment"]
?.Parameters["ASPNETCORE_ENVIRONMENT"]?.Value;
return new WebHostBuilder()
.UseHttpSys()
.ConfigureServices(
services => services
.AddSingleton(serviceContext)
.AddSingleton<OracleHelper>(_oracleHelper)
.AddSingleton<ILoggerClient>(_loggerClient)
.AddSingleton<IFacadeRepository>(new FacadeRepository(ApplicationName, TenantCode, ServiceBusConnectionString, ErrorQueueFragment, GatewayFacadeInboundQueueFragment, EmailSender, EmailRecipientList, CompositionRoot.SymphonyEmailFunc))
.AddSingleton(new ServiceProxyFactory(c => new FabricTransportServiceRemotingClientFactory()).CreateServiceProxy<IOrchestratorServices>(new Uri($"fabric:/{tenantApplicationName}/MessageOrchestrator"), null, Microsoft.ServiceFabric.Services.Communication.Client.TargetReplicaSelector.PrimaryReplica, "rpcListener")))
.UseContentRoot(Directory.GetCurrentDirectory())
.UseStartup<Startup>()
.UseEnvironment(environment)
.UseServiceFabricIntegration(listener, ServiceFabricIntegrationOptions.None)
.UseUrls(url)
.Build();
}))
};
}
我想以某种方式调用我的 OwinCommunication 侦听器或调用我的 OWIN 启动类
解决方案
推荐阅读
- go - Go Test 删除 logger.SetLogging 日志文件
- css - 未找到模块:错误:无法解析 './@fortawesome/fontawesome-free/css/fontawesome.css'
- php - 如何在 PHP 中将父类转换为其子类?
- java - 运行项目时“通过构造函数参数 0 表示的不满足的依赖关系”
- c - MATLAB 嵌入式 C 函数问题
- spring - Spring Security (java.lang.NullPointerException: null at org.springframework.security.authentication.ProviderManager.authenticate)
- reactjs - 升级到 React 16.4.1 后酶测试不起作用
- javascript - 在另一个 div 的活动状态下更改图像
- android - 在 SDK 26 中从本地存储安装 APK 时出现问题
- angular - 日期范围选择器