【发布时间】:2021-09-06 03:09:45
【问题描述】:
我有一个应用程序 (.NET 5.0 ASP Net Core) 应用程序,我正在尝试将它部署到 AWS Amazon Linux 2 服务器。除了使用 AWS Congnito 和 Microsoft.AspNetCore.Authentication.OpenIdConnect 进行授权之外,部署的所有方面似乎都很好。在 dev/local 中一切正常,问题仅在 prod 部署时表现出来。
问题表现为“请求的页面遇到错误”。尝试登录时在托管 UI 中的 https://auth.<mydomain>.com/error?error=redirect_mismatch&client_id=<myclientid>。我已确认并再次确认回调 URL 设置正确:https://sub.domain.com/signin-oidc, https://localhost:5001/signin-oidc。
我的应用程序在 apache 反向代理后面的 http://localhost:5000 上运行。我怀疑 Apache 和 Kestrel 之间路径的非 HTTPS 部分是问题所在。
我注意到的是,Microsoft.AspNetCore.Authentication.OpenIdConnect 在它调用的 /oauth2/authorize 端点中创建的 redirect_uri 值中缺少 https。
这是我部署时看到的,注意redirect_uri是http:
在 App 客户端设置中,我无法将 signin-oidc 端点设置为使用 HTTP。
我的配置服务:
public void ConfigureServices(IServiceCollection services)
{
services.AddControllersWithViews();
services.AddAuthentication(options =>
{
options.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultSignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
})
.AddCookie()
.AddOpenIdConnect(options =>
{
options.ResponseType = "code";
options.ResponseType = Configuration["Authentication:Cognito:ResponseType"];
options.MetadataAddress = Configuration["Authentication:Cognito:MetadataAddress"];
options.ClientId = Configuration["Authentication:Cognito:ClientId"];
options.TokenValidationParameters = new TokenValidationParameters
{
RoleClaimType = "cognito:groups"
};
options.Events = new OpenIdConnectEvents
{
OnTicketReceived = e =>
{
e.ReturnUri = string.Format("/Home/CheckProfile?url={0}", HttpUtility.UrlEncode(e.ReturnUri));
return Task.CompletedTask;
}
};
});
}
那么,为什么 Microsoft.AspNetCore.Authentication.OpenIdConnect 在生成 /oauth2/authorize 端点的 redirect_uri 值时使用 HTTP。那是我需要在某个地方调整的东西吗?而且,这似乎是导致我的整体https://auth.<mydomain>.com/error?error=redirect_mismatch&client_id=<myclientid> 问题的核心问题吗?
【问题讨论】:
-
请分享配置auth的相关代码?
标签: asp.net-core amazon-cognito openid-connect