托管在 IONOS widows 上成功验证 OAuth 2.0 后出现错误 500

问题描述 投票:0回答:1

非常感谢您提供的任何建议或指导。

尝试使用 Google 和 Microsoft API 进行身份验证。 使用 nugets Microsoft.AspNetCore.Authentication.Google 和 Microsoft.AspNetCore.Authentication.MicrosoftAccount

根据文件:- ASP.NET Core 中的 Facebook、Google 和外部提供商身份验证 配置 ASP.NET Core 以与代理服务器和负载均衡器配合使用

在我的开发 PC 上一切正常,但在上传到主机站点(IONOS Windows 主机)后 身份验证成功后出现以下错误:-

TaskCanceledException:任务被取消。 System.Threading.Tasks.TaskCompletionSourceWithCancellation.WaitWithCancellationAsync(CancellationToken取消令牌)

TimeoutException:任务被取消。 System.Threading.Tasks.TaskCompletionSourceWithCancellation.WaitWithCancellationAsync(CancellationToken CancellationToken)

TaskCanceledException:由于配置的 HttpClient.Timeout 已过 60 秒,请求被取消。 System.Net.Http.HttpClient.HandleFailure(异常e,布尔遥测开始,HttpResponseMessage响应,CancellationTokenSource cts,CancellationToken取消令牌,CancellationTokenSource挂起的RequestsCts)

AuthenticationFailureException:处理远程登录时遇到错误。 Microsoft.AspNetCore.Authentication.RemoteAuthenticationHandler.HandleRequestAsync()

在向 Microsoft 进行身份验证时,我也得到了类似的响应。

详情:- 我有一个 c# NET 8.0 core MVC 风格的 web 应用程序。

Program.cs 有:-

builder.Services.AddAuthentication()
    .AddCookie("social_login")
    .AddMicrosoftAccount(microsoftOptions =>
    {
        microsoftOptions.ClientId = builder.Configuration["Authentication:Microsoft:ClientId"];
        microsoftOptions.ClientSecret = builder.Configuration["Authentication:Microsoft:ClientSecret"]; 
    })
    .AddGoogle(googleOptions =>
    {
        IConfigurationSection googleAuthNSection =
            builder.Configuration.GetSection("Authentication:Google");

        googleOptions.ClientId = googleAuthNSection["ClientId"];
        googleOptions.ClientSecret = googleAuthNSection["ClientSecret"];
    });

    
builder.Services.Configure<CookiePolicyOptions>(options =>
{
    // This lambda determines whether user consent for non-essential cookies is needed for a given request.
    options.CheckConsentNeeded = context => true;
    options.MinimumSameSitePolicy = SameSiteMode.Lax;
});
builder.Services.AddControllersWithViews();
builder.Services.AddRazorPages();
builder.Services.AddCors();
builder.Services.AddAntiforgery(o => o.SuppressXFrameOptionsHeader = true);

builder.Services.Configure<ForwardedHeadersOptions>(options =>
        {
            options.ForwardedHeaders =
                ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto;
        });

var app = builder.Build();
app.UseForwardedHeaders();
app.UseHttpsRedirection();
app.UseStaticFiles();

app.UseCookiePolicy();
app.UseRouting();

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

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

//For x-frame-options errpr:-
app.UseCors(x => x.AllowAnyOrigin()
    .AllowAnyHeader()
    .AllowAnyMethod());

app.Run();

谷歌API:-

请求的 URL 如下所示:- https://example.com/signin-google?state={已删除}&code={已删除}&scope=email+profile+openid+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.profile+https %3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email&authuser=1&prompt=同意

据我所知,IONOS 使用我添加的代理服务器:-


builder.Services.Configure<ForwardedHeadersOptions>(options =>
        {
            options.ForwardedHeaders =
                ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto;
        });
app.UseForwardedHeaders();

还尝试添加

app.Use((context, next) =>
{
    context.Request.Scheme = "https";
    return next();
});
windows .net-core oauth-2.0 ionos
1个回答
0
投票

我遇到了类似的问题,因为我尝试在 IONOS 托管上使用 Azure B2C 身份验证和 .net 8。 .net 7 与 Azure B2C 在 IONOS 上运行良好。

暂时没有找到解决办法,你的问题没有解决吗?

© www.soinside.com 2019 - 2024. All rights reserved.