【问题标题】:Dynamic ports with Azure Ad Authentication具有 Azure 广告身份验证的动态端口
【发布时间】:2018-01-02 13:55:36
【问题描述】:

我正在 Azure Service Fabric 中开发 ASP.Net Core 2.0 应用程序。此应用程序使用 Azure 广告身份验证。此身份验证需要在 Azure 门户中注册回复 URL。然而,Service Fabric 会根据可用端口为我的应用程序分配一个端口。如何在不注册超过一百个不同的回复 URL 的情况下使用动态分配的端口实现这种身份验证方式?目前通过使用 Service Fabric 反向代理解析端口。

在我的创业公司中,我在 ConfigureServices 中输入了我的 Azure 广告配置:"

services.AddAzureAd(options =>
{
     Configuration.Bind("AzureAd", options);
})

我的应用设置包含:

{
  "AzureAd": {
    "Instance": "https://login.microsoftonline.com/",
    "Domain": "mydomain.com",
    "TenantId": "AD tenant id (GUID)",
    "ClientId": "registered app id (GUID)",
    "CallbackPath": "/signin-oidc"
  },
  ...
}

【问题讨论】:

  • 您的客户如何找到应用程序?
  • 通过 Service Fabric 反向代理。我会将它添加到原始帖子中。
  • 你能运行一个专门的应用程序和服务来承载回复端点吗?
  • @HiredMind 这不起作用,因为它们不相等并且 RP 地址不必指向同一服务器。
  • @LoekD 这听起来比它应该的麻烦多了,我也不知道应该如何通过使用 asp.net 核心中间件来实现。

标签: authentication azure-active-directory azure-service-fabric asp.net-core-2.0


【解决方案1】:

对于它的价值,这是我的建议。

使用 SF 反向代理 url 作为ReplyUrl
对于给定的应用注册,您不需要在ReplyUrls 部分中注册每个可能的私有地址以及端口。当您通过 SF Reverse Proxy 与服务通信时,请将其地址作为回复 url。

调整代码以构建正确的 redirect_uri
您需要进行更改以确保 redirect_uri 指向您的反向代理而不是本地 ip。确切的代码取决于许多因素,包括安装在您机器上的 asp.net core build,但这里是我在 .net core 2.1.4 上工作的原型 -

services.AddAuthentication(options =>
                {
                    options.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme;
                    options.DefaultSignInScheme = OpenIdConnectDefaults.AuthenticationScheme;
                    options.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
                })
                .AddCookie()
                .AddOpenIdConnect(options =>
                {                
                    options.ClientId = "xxx-xxxxx-xxxx";
                    options.Authority = "xxx-xxxxx-xxxx";
                    options.CallbackPath = "/signin-oidc";
                    options.Events = new OpenIdConnectEvents
                    {
                        OnRedirectToIdentityProvider = ctx =>
                        {
                            ctx.ProtocolMessage.RedirectUri = $"https://reverse_proxy_url/app_name/service_name{options.CallbackPath}";

                            return Task.CompletedTask;
                        }
                    };

                });

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-09-29
    • 2018-04-12
    • 2017-11-17
    • 1970-01-01
    • 2020-02-01
    • 1970-01-01
    • 2018-03-19
    • 2021-04-10
    相关资源
    最近更新 更多