首页 > 解决方案 > 从 .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 启动类

标签: asp.net-web-apiowinazure-service-fabricoktaowin-middleware

解决方案


推荐阅读