【问题标题】:ASPNET Core OIDC Correlation FailedASPNET Core OIDC 关联失败
【发布时间】:2018-12-29 04:27:03
【问题描述】:

我在 StackOverflow 上查看了一堆与此类似的类似问题,但没有一个解决方案对我有用。

这个问题快把我逼疯了!

我与这里的许多类似服务器的主要区别是负载均衡器后面只有一台服务器,所以问题不在于我的请求发送到不同的服务器。我已经实现了数据保护中间件,更改了我的回调路径,尝试捕获错误事件,为状态数据添加了缓存等。没有什么可以解决这个问题。我不知道我错过了什么。

如果有人能就此提供一些见解,我将不胜感激。

services.AddAuthentication(options =>
            {
                options.DefaultScheme = "Cookies";
                options.DefaultChallengeScheme = "oidc";
            })
            .AddCookie("Cookies")
            .AddOpenIdConnect("oidc", options =>
            {
                options.SignInScheme = "Cookies";
                options.ClientId = Configuration["IdServerClientId"];
                options.ClientSecret = Configuration["IdServerClientSecret"];
                options.Authority = Configuration["IdServerBaseUri"];
                options.CallbackPath = "/sign-in-oidc2";
                options.RequireHttpsMetadata = false;
                options.ResponseType = "code id_token";
                options.SaveTokens = true;
                options.TokenValidationParameters = new TokenValidationParameters()
                {
                    NameClaimType = "name"
                };
                options.Scope.Add("openid");
                options.Scope.Add("profile");
                options.Scope.Add("email");
                options.Events = new OpenIdConnectEvents()
                {
                    //OnRedirectToIdentityProvider = OnRedirectToProvider,
                    OnRemoteFailure = OnRemoteFailure,
                    OnAuthenticationFailed = OnAuthenticationFailed
                };
            });

        services.AddOidcStateDataFormatterCache("foo");

        services.AddDataProtection()
            .PersistKeysToFileSystem(new DirectoryInfo(Configuration["KeyPersistenceLocation"]));

【问题讨论】:

    标签: asp.net-core-2.0 identityserver4 openid-connect


    【解决方案1】:

    如果其他人遇到此问题,请在此处找到答案:

    https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/proxy-load-balancer?view=aspnetcore-2.1#when-it-isnt-possible-to-add-forwarded-headers-and-all-requests-are-secure

    在启动时的配置方法中,需要添加这个来处理http/https冲突。

    app.Use((context, next) =>
    {
        context.Request.Scheme = "https";
        return next();
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-08-25
      • 2018-10-11
      • 2017-04-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多