asp.net-core - AADB2C90006 在redirect_uri 中具有 https-> http 转换

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

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

我尝试在我的开发环境中本地运行它,它按预期工作。据我了解,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
                });

最佳答案

好吧,我仍然不知道为什么 http: 会通过而不是 https:,但我确实有一个修复它。

在我的项目中,我有一个名为 OpenIdConnectOptionsSetup 的类,它是我从 Azure AD B2C sample 中获取的。 。在此类中,我配置了 OpenIdConnectEvents,其中包括一个 OnRedirectToIdentityProvider 委托(delegate),其中我有一些代码在查找 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 成功登录到我的站点。

关于asp.net-core - AADB2C90006 在redirect_uri 中具有 https-> http 转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54334040/

相关文章:

google-api - 获取 403 - 禁止 Google 服务帐户

authentication - 以 Google Apps super 管理员身份通过 API 为用户关闭两步验证

delphi - 使用 Google 代替现有客户端服务器应用程序的 Web 界面

azure - 在 Azure 中,为什么我在应用程序注册的 "Authorized client applications"页面上看不到 "Expose an API"部分

node.js - 如何从缓存位置:本地存储中检索msal对象?

c# - Autorest + Swagger 无法正确生成 ENUM

c# - 覆盖 FindByEmail 以按租户查找

asp.net-core - Asp.Net Core 3 正常关机抛出 OperationCanceledException

.net - 使用 Entity Framework Core 的分片策略

azure - 应用程序架构 - 多个 B2C 订阅 - 一个全局应用程序