简体   繁体   English

AWS Cognito 登录返回 Bad gateway 错误

[英]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.

相关问题 AWS Cognito:在 Auth.signIn 中出现错误(验证 amazon-cognito-identity-js 已链接) - AWS Cognito: Getting error in Auth.signIn (Validate that amazon-cognito-identity-js has been linked) 连接到 AWS Opensearch 的 AWS Grafana `OpenSearch 错误:网关错误` - AWS Grafana connecting to AWS Opensearch `OpenSearch error: Bad Gateway` 将 api 网关与 aws cognito 一起用于受保护的路由 - using api gateway with aws cognito for protected routes AWS Cognito + API 网关 + 调用 Cognito 令牌端点 - AWS Cognito + API Gateway + Calling Cognito Token Endpoint AWS 的 elasticbeanstalk 中的 502 Bad Gateway - 502 Bad Gateway in elasticbeanstalk of AWS 使用 NextJS 和 Amplify 的 AWS Cognito 登录 - 在前端或后端调用端点? - AWS Cognito Signin with NextJS and Amplify - call endpoint on front or backend? 具有外部 IDP (SAML) 的 AWS Cognito 用于注册后/登录操作 - AWS Cognito with external IDP (SAML) for Post-Signup/Signin Actions AWS Api 网关和 Cognito 导致 CORS 错误 - AWS Api Gateway and Cognito cause CORS errors AWS API 网关 + Cognito + Lambda - $context.authorizer.principalId 为空 - AWS API Gateway + Cognito + Lambda - $context.authorizer.principalId empty Api Gateway Cognito 授权方:客户端令牌适用于 AWS ui 但不适用于 Postman - Api Gateway Cognito Authorizer: client token works on AWS ui but not on Postman
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM