.net6 oidc signin-oidc报错

问题描述

语言框架:.NET 6
使用OpenIdConnect方式认证,启动项目成功跳转到authing登录页,当输入完手机号+验证码后,跳转回客户端signin-oidc端点,发生如下报错:

An unhandled exception occurred while processing the request.

Exception: Correlation failed.
Unknown location
Exception: An error was encountered while handling the remote login.
Microsoft.AspNetCore.Authentication.RemoteAuthenticationHandler.HandleRequestAsync()

System.Exception: An error was encountered while handling the remote login.
—> System.Exception: Correlation failed.
— End of inner exception stack trace —
at Microsoft.AspNetCore.Authentication.RemoteAuthenticationHandler`1.HandleRequestAsync()
at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)

代码配置如下:

using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Authentication.OpenIdConnect;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.
builder.Services.AddControllersWithViews();

builder.Services.AddAuthentication(options =>
    {
        options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
        options.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
    }).AddCookie(CookieAuthenticationDefaults.AuthenticationScheme)
    .AddOpenIdConnect(options =>
    {
        options.SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
        options.Authority = "https://custom-domain.authing.cn/oidc";
        options.RequireHttpsMetadata = false;
        options.ClientId = "xxxxxx";
        options.ClientSecret = "xxxxxx"
        options.ResponseType = "code id_token";
        options.GetClaimsFromUserInfoEndpoint = true;
        options.SaveTokens = true;
    });

var app = builder.Build();

// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
    app.UseExceptionHandler("/Home/Error");
}
app.UseStaticFiles();

app.UseRouting();

app.UseAuthentication();
app.UseAuthorization();

app.MapControllerRoute(
    name: "default",
    pattern: "{controller=Home}/{action=Index}/{id?}");

app.Run();

应用配置和协议配置截图如下:

这个问题令我不得其解,希望有大佬来指点一下,多谢

能提供一个可以复现的 demo 吗?

1赞

多谢,由于之前是在localhost本地环境测试,我把应用部署到服务器上,然后配置ssl证书,解决了这个问题,现在可以正常的使用oidc模式