我正在使用 ASP.NET Core 2
和 Nginx
开发一个网站。我想添加 Google 身份验证。
服务器是 Linux,运行 Nginx,启用 SSL。 ASP.NET运行在http://localhost:5000/
上,Nginx使用反向代理访问。
问题是,当我尝试访问 Google 时,URL 模式是 http
,因为 ASP.NET 在 http 中运行。我收到错误提示“错误:redirect_uri_mismatch”,因为 https
是在 Google 端定义的。
我尝试了 OnRedirectToAuthorizationEndpoint
事件并更改了 RedirectUri
但没有成功。
我也尝试过将 CallbackPath
更改为完整的 URL,但据说 URL 必须以 /
开头;它需要相对路径。
我使用的包是:Microsoft.AspNetCore.Authentication.Google (2.0.0)
有什么建议吗?
服务代码是:
services.AddAuthentication()
.AddGoogle(options =>
{
options.ClientId = Configuration["Authentication:Google:ClientId"];
options.ClientSecret = Configuration["Authentication:Google:ClientSecret"];
options.CallbackPath = "/Login/GoogleCallback";
options.Events.OnRedirectToAuthorizationEndpoint += context =>
{
context.Properties.RedirectUri = context.Properties.RedirectUri.Replace("http://", "https://");
return Task.FromResult(0);
};
});
最佳答案
将这些添加到配置文件 /etc/nginx/sites-available/default
后,它开始工作。
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
https://stackoverflow.com/questions/45923776/
相关文章:
apache-spark - Kafka 结构化流 java.lang.NoClassDefFoun
selenium - 使用 SendKeys 向 IE 11 发送 '@' 特殊字符
azure - Azure WebApp 是否自动进行速率限制/DOS 保护?
google-cloud-platform - Google Cloud Endpoints 以 V
php - 找不到属性 Application\Sonata\NewsBundle\Entity\P
c# - Signalr net client On 事件泛型类型参数