【问题标题】:AADB2C90006 with https-> http transition in redirect_uriAADB2C90006 在 redirect_uri 中带有 https-> http 转换
【发布时间】:2019-06-17 10:40:12
【问题描述】:

我有一个 ASP.NET Core 应用程序,它使用 Azure Active Directory B2C 进行身份验证,我将其部署到 Google App Engine 实例中。在我的 AD B2C 应用程序配置中,我有 https://<domain>/signin-oid 作为我的重定向 URL,但是当我登录时,我收到错误 AADB2C90006,说域 http://<domain>/signin-oid 无效。我的代码中的任何位置都没有指定此 url 的 http 版本。

我已尝试在我的开发环境中本地运行它,它按预期工作。我了解 Nginx 在启动的 Kestrel 实例之前充当代理,并且我已在我的 Kestrel 实例中配置 SSL 以使用 App Engine 实例使用的相同证书。我提到这一点是因为我怀疑 App Engine 和 Kestrel 配置之间存在某种脱节,尽管问题可能出在哪里非常模糊。

      return new WebHostBuilder()
            .ConfigureKestrel((context, options) =>
            {
                if (!string.IsNullOrEmpty(aspEnv) && !string.Equals(aspEnv,"Development"))
                {                        
                    options.ListenAnyIP(443,opt => opt.UseHttps("myfile.pfx","mypass"));
                }
            })

我的Configure 函数中也有这一行:

                app.UseForwardedHeaders(new ForwardedHeadersOptions
                {
                    ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
                });

【问题讨论】:

  • 我认为这是因为 Web 应用程序在重定向到期待 https 回复 URL 的 Azure AD B2C 之前没有从 http 重定向到 httpsthis 有帮助吗?
  • 我对这个建议做了一些进一步的改进,它重定向到 https 地址,但给了我一个 404,因为来自 B2C 的响应仍在寻找 http .还尝试添加github.com/Azure-Samples/active-directory-b2c-dotnetcore-webapp/…,但没有运气。

标签: asp.net-core google-apps azure-ad-b2c


【解决方案1】:

在 Linux 上将 .NET Core 应用程序部署到 Azure 应用程序服务时,我遇到了同样的问题。我可以通过转发Startup.cs 中的XForwardedProto 标头来解决它,如this answer 中指定的那样。

【讨论】:

    【解决方案2】:

    好吧,我仍然不知道为什么 http: 而不是 https: 会通过,但我确实有一个解决办法。

    在我的项目中,我有一个名为 OpenIdConnectOptionsSetup 的类,我从 Azure AD B2C sample 中获得。在这个类中,我配置了OpenIdConnectEvents,其中包括一个OnRedirectToIdentityProvider 委托,其中我有一些代码在寻找http:,但隐藏在if 语句中,以寻找身份验证策略中的差异,我还没有看到代码被叫,但我离题了。

    我的代表现在看起来像这样:

                public Task OnRedirectToIdentityProviderAsync(RedirectContext context)
                {
                    Logger.LogInformation($"redirect URI for B2C: {context.ProtocolMessage.RedirectUri} !!!!!!!");
    
                    if (context.ProtocolMessage.RedirectUri.Contains("http:"))
                    {                    
                        Logger.LogInformation("http: found in RedirectUri, replacing with https");
                        context.ProtocolMessage.RedirectUri = context.ProtocolMessage.RedirectUri.Replace("http:", "https:");
                    }
    
                    //in case of error, show us the problem
                    if (string.IsNullOrEmpty(context.ProtocolMessage.ErrorUri))
                    {
                        Logger.LogInformation("ErrorUri is empty! replacing with ErrorUri property.");
                        context.ProtocolMessage.ErrorUri = GCPSettings.ErrorUri;
                    }
                }
    

    使用此配置,我能够使用 Azure AD B2C 成功登录到我的站点。

    【讨论】:

      猜你喜欢
      • 2019-11-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-30
      • 1970-01-01
      • 1970-01-01
      • 2011-03-08
      • 2019-12-12
      相关资源
      最近更新 更多