【问题标题】:ASP .NET Core 2.0 - OpenId Connect Auth : Correlation errorASP .NET Core 2.0 - OpenId Connect Auth:相关错误
【发布时间】:2018-12-12 04:19:34
【问题描述】:

我正在尝试在 ASP.NET Core 2.0 Web 应用上创建身份验证。

我的公司正在使用 Ping Federate,我正在尝试使用公司登录页面对我的用户进行身份验证,并使用我的签名密钥(X509SecurityKey 在此处)验证返回的令牌。

ping 登录链接如下:

https://auth.companyname.com

我将 Startup.cs 配置为能够登录并挑战此站点。

我用 [Authorize(Policy="Mvc")] 装饰了我的 HomeController。

我能够访问登录页面,但是,每当我从它返回时,我都会得到 ( 我尝试关闭/打开多个多重验证):

异常:关联失败。

未知位置

异常:处理远程登录时遇到错误。

Microsoft.AspNetCore.Authentication.RemoteAuthenticationHandler.HandleRequestAsync()

错误信息不是很有帮助...以前有人遇到过这样的问题吗?

    public void ConfigureServices(IServiceCollection services)
{
    services.AddMvc();

    services.AddAuthentication(options =>
    {
        options.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme;
        options.DefaultSignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
        options.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
    })
    .AddCookie()
    .AddOpenIdConnect(options =>
    {
        options.Authority = PF_LOGINPATH;
        options.ClientId = Configuration["ClientId"];
        options.ClientSecret = Configuration["ClientSecret"];
        options.Scope.Clear();

        options.ResponseType = OpenIdConnectResponseType.CodeIdTokenToken;
        options.SaveTokens = false;

        options.GetClaimsFromUserInfoEndpoint = false;//true;

        options.TokenValidationParameters = new TokenValidationParameters
        {
            RequireSignedTokens =  false,
            ValidateActor = false,
            ValidateAudience = false,
            ValidateIssuer = false,
            ValidateIssuerSigningKey = false,
            ValidateTokenReplay = false,

            // Compensate server drift
            ClockSkew = TimeSpan.FromHours(24),
            //ValidIssuer = PF_LOGINPATH;
            // Ensure key
            IssuerSigningKey = CERTIFICATE,                    

            // Ensure expiry
            RequireExpirationTime = false,//true,
            ValidateLifetime = false,//true,                    

            // Save token
            SaveSigninToken = false
        };                

    });

    services.AddAuthorization(options =>
    {
        options.AddPolicy("Mvc", policy =>
        {
            policy.AuthenticationSchemes.Add(OpenIdConnectDefaults.AuthenticationScheme);
            policy.RequireAuthenticatedUser();
        });
    });
}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
    if (env.IsDevelopment())
    {
        app.UseBrowserLink();
        app.UseDeveloperExceptionPage();
    }
    else
    {
        app.UseExceptionHandler("/Home/Error");
    }

    app.UseStaticFiles();

    app.UseAuthentication();

    app.UseMvc(routes =>
    {
        routes.MapRoute(
            name: "default",
            template: "{controller=Home}/{action=Index}/{id?}");
    });
}

【问题讨论】:

  • 找到原因了吗?
  • 一直没找到原因,暂时换了工作/行业,抱歉

标签: c# asp.net-core oauth-2.0 asp.net-core-2.0 pingfederate


【解决方案1】:

我也有类似的情况。我的应用程序网址是这样的:“https://domain/appname” 因此,当有人键入 url "https://domain/appname/" [带有斜杠] 时,它会给出相关性错误。这就是我解决它的方法(从其他网站找到)

public void ConfigureServices(IServiceCollection services)
        {
            services.AddAuthentication(options =>
                {
                    //Auth schemes here
                })
                .AddOpenIdConnect(oid =>
                {
                    //Other config here
                    oid.Events = new OpenIdConnectEvents()
                    {
                        OnRemoteFailure = OnRemoteFailure

                    };
                });
        }

private Task OnRemoteFailure(RemoteFailureContext context)
        {

            if (context.Failure.Message.Contains("Correlation failed"))
            {
                context.Response.Redirect("/AppName"); // redirect without trailing slash
                context.HandleResponse();
            }

            return Task.CompletedTask;
        }

【讨论】:

  • 感谢您的分享,不幸的是,这不是我遇到的问题,我在处理“/signin-oidc”操作时发生相关错误
【解决方案2】:

以斜杠结束回调 url

【讨论】:

    猜你喜欢
    • 2018-07-03
    • 1970-01-01
    • 2021-11-14
    • 1970-01-01
    • 2019-01-09
    • 2019-11-09
    • 1970-01-01
    • 2021-05-31
    • 2014-08-28
    相关资源
    最近更新 更多