gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:16:21 26 4
gpt4 key购买 nike

我对我的 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com