【发布时间】:2021-05-12 17:32:49
【问题描述】:
我以这种方式使用 Traefik 实现了负载均衡器:
http:
routers:
mydomain-web-http:
service: mydomain-web
rule: "Host(`mydomain.com`,`www.mydomain.com`)"
entryPoints:
- http
middlewares:
- https-redirect
mydomain-web-https:
service: mydomain-web
rule: "Host(`mydomain.com`,`www.mydomain.com`)"
entryPoints:
- https
tls:
certResolver: letsEncrypt
services:
mydomain-web:
loadBalancer:
sticky:
cookie:
name: mydomain_sticky
secure: true
httpOnly: true
passHostHeader: false
servers:
- url: https://www2.mydomain.com
- url: https://www1.mydomain.com
现在我配置了一个 webapp 客户端 OAuth 2.0。用这种方式用谷歌登录:
public void ConfigureAuth(IAppBuilder app)
{
var googleOAuth2AuthenticationOptions = new GoogleOAuth2AuthenticationOptions
{
ClientId = "xxx.apps.googleusercontent.com",
ClientSecret = "-sn_xxx",
Provider = new GoogleOAuth2AuthenticationProvider()
{
OnAuthenticated = async context =>
{
context.Identity.AddClaim(new Claim("GoogleAccessToken", context.AccessToken));
}
}
};
app.UseGoogleAuthentication(googleOAuth2AuthenticationOptions);
}
在使用负载均衡器进行配置之前,此代码工作正常,但现在我收到此错误:
错误 400:redirect_uri_mismatch 请求中的重定向 URI https://www2.mydomain.com/signin-google 与授权给 OAuth 客户端的不匹配...
我需要为我的“主”域 (www.mydomain.com) 授权 google 登录...我尝试以这种方式实现此目的:
app.Use((ctx, next) => { ctx.Request.Host = new HostString("www.mydomain.com"); return next(); });
没有运气......
【问题讨论】: