[英]Google authentication with load balancer in c#
I have implemented a Load Balancer with Traefik in this way:我以这种方式使用 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
Now I configure a webapp client OAuth 2.0.现在我配置一个 webapp 客户端 OAuth 2.0。 for login with google in this way:
以这种方式使用谷歌登录:
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);
}
Before the configuration with Load balancer this code work fine but now I receive this error:在使用负载均衡器配置之前,此代码工作正常,但现在我收到此错误:
Error 400: redirect_uri_mismatch The redirect URI in the request, https://www2.mydomain.com/signin-google , does not match the ones authorized for the OAuth client...错误 400:redirect_uri_mismatch 请求中的重定向 URI https://www2.mydomain.com/signin-google与授权给 OAuth 客户端的 URI 不匹配...
i need to authorize google login for my "main" domain ( www.mydomain.com )... I try to achieves this in this way:我需要为我的“主”域( www.mydomain.com )授权谷歌登录...我尝试以这种方式实现这一目标:
app.Use((ctx, next) => { ctx.Request.Host = new HostString("www.mydomain.com"); return next(); });
with no luck...没有运气...
after to much pain, i solved by setting the schema in this way:在经历了很多痛苦之后,我通过以这种方式设置架构来解决:
app.Use((ctx, next) => { ctx.Request.Scheme = "https"; ctx.Request.Host = new HostString("www.mydomain.com"); return next(); });
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.