[英]AWS Cognito Signin returning Bad gateway error
My.Net Core application is published to an elastic beanstalk load balanced environment and I'm using the Cognito hosted UI for authentication but after entering correct login details I get a 502 error. My.Net Core 应用程序已发布到弹性 beantalk 负载平衡环境,我正在使用 Cognito 托管 UI 进行身份验证,但在输入正确的登录详细信息后,我收到 502 错误。
snippet from startup.cs来自 startup.cs 的片段
services.AddAuthentication(options =>
{
options.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultSignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultSignOutScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
})
.AddCookie()
.AddOpenIdConnect(options =>
{
options.ResponseType = Configuration["Authentication:Cognito:ResponseType"];
options.MetadataAddress = Configuration["Authentication:Cognito:MetadataAddress"];
options.ClientId = Configuration["Authentication:Cognito:ClientId"];
options.SaveTokens = true;
options.ClientSecret = Configuration["Authentication:Cognito:Secret"];
options.Scope.Add(Configuration["Authentication:Cognito:Scope"]);
options.Events = new OpenIdConnectEvents()
{
OnRedirectToIdentityProviderForSignOut = OnRedirectToIdentityProviderForSignOut,
OnRedirectToIdentityProvider = (async context =>
{
context.ProtocolMessage.RedirectUri = context.ProtocolMessage.RedirectUri.Replace("http:", "https:");
await Task.FromResult(0);
})
};
});
When I inspect the.network activity in the browser I'm seeing this...当我在浏览器中检查 the.network 活动时,我看到了这个......
...which suggests that cognito is redirecting to /signin-oidc but there's no authorisation so it redirects back to cognito which then redirects back, and this repeats until it eventually throws the 502 error.
...这表明 cognito 正在重定向到 /signin-oidc 但没有授权,因此它重定向回 cognito 然后再重定向回来,并且重复直到它最终抛出 502 错误。
When I'm testing locally I'm able to login okay which makes me think it's maybe some kind of loadbalancing issue??当我在本地测试时,我可以正常登录,这让我觉得这可能是某种负载平衡问题??
I kept getting a Bad Gateway 502
until I discovered that my next.config.js
had async rewrites enabled for the source/destination URLs in my clumsy attempt to fix a CORS issue.在我笨拙地尝试修复 CORS 问题时,我一直收到
Bad Gateway 502
,直到我发现我的next.config.js
为源/目标 URL 启用了异步重写。 Removing that fixed my problem to get next-auth working with cognito.删除它解决了我的问题,让 next-auth 使用 cognito。 Then I had to fix the underlying CORS problem with server side policy settings.
然后我必须修复服务器端策略设置的底层 CORS 问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.