linux - 外部服务登录链接 asp core

标签 linux asp.net-core oauth

我对我的 asp 核心应用程序使用外部身份验证。在本地主机上一切正常,但是当我尝试在 ubuntu 服务器上部署项目时出现问题。 我的网站在 linux 服务器的 5001 端口上工作,当我调用 Challenge 方法将用户重定向到登录页面时,它返回 http://localhost:5001/signin-google 并且 in 不起作用,因为谷歌无法将结果返回到无法从 internet localhost 访问(我可以从我的计算机调用该项目,当它在我计算机上的 localhost 上时,而不是当它在服务器上的 localhost 上时)。我试图像这样明确定义 auth url:options.CallbackPath = "https://myproject.com/signin-google"; 但 options.CallbackPath 需要以“/”开头的值。那我该怎么办?

已更新

尝试像这样自己设置请求 cookie:

.AddGoogle(options =>
                {
                    options.ClientId = Configuration["Authentication:Google:ClientId"];
                    options.ClientSecret = Configuration["Authentication:Google:ClientSecret"];
                    options.Events = new OAuthEvents
                    {
                        OnRedirectToAuthorizationEndpoint = async context =>
                        {
                            context.Request.Headers.Remove("Scheme");
                            context.Request.Headers.Add("Scheme", "https");
                            context.Request.Headers.Remove("Host");
                            context.Request.Headers.Add("Host", "myhost.com");
                        }
                    };
                    options.CallbackPath = "/signin-google";

但在 Challenge 之后没有重定向到 google auth 页面

最佳答案

我意识到了。我只需要像这样配置 nginx:

 server {
                listen 80;
                server_name example.com;
                location / {
                        proxy_pass http://localhost:5001;
                        proxy_http_version 1.1;
                        proxy_set_header  X-Real-IP $remote_addr;
                        proxy_set_header  X-Forwarded-Proto http;
                        proxy_set_header  X-Forwarded-For $remote_addr;
                        proxy_set_header  X-Forwarded-Host $remote_addr;
                        proxy_set_header Upgrade $http_upgrade;
                        proxy_set_header Connection keep-alive;
                        proxy_set_header Host $host;
                        proxy_cache_bypass $http_upgrade;
                }

并添加了

app.UseForwardedHeaders(new ForwardedHeadersOptions
            {
                ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
            });

就这样

关于linux - 外部服务登录链接 asp core,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51220837/

相关文章:

c# - 从显式类型化的 ASP.NET Core API Controller (不是 IActionResult)返回 404

java - 使用 javax.ws.rs 的 Twitter oauth2

oauth - 使用 ASP.net API 的不记名 token 身份验证

linux - 如何创建 Debian bundle ?

c# - *.json 文件更改后 IOptionsSnapshot 不刷新

linux - 将程序的执行传递给另一个窗口管理器

asp.net - Web 部署无法修改目标上的文件 'xxx.exe',因为该文件已被外部进程锁定

api - 当主应用程序基于 OAuth API 时如何对其进行身份验证

linux - 更改虚拟机 KVM 中的 root 密码

linux - 在 x86_64 redhat 6.2 上安装 32 位库