ASPNET Core OIDC关联失败

jpaull

我在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"]));
jpaull

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

https://docs.microsoft.com/zh-cn/aspnet/core/host-and-deploy/proxy-load-balancer?view=aspnetcore-2.1#when-it-isnt-possible-to-add-forwarded-标头和所有请求都是安全的

在启动时的Configure方法中,需要添加它来处理http / https冲突。

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

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章