首页 > 解决方案 > 如何设置redirect_uri登录google .Net Core 2,Docker

问题描述

我正在尝试在 .net core 2 docker 中使用 google 进行身份验证

services
            .AddAuthentication(options =>
            {
                options.DefaultSignOutScheme = IdentityConstants.ApplicationScheme;
                options.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme;
                options.DefaultSignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
                options.DefaultChallengeScheme = CookieAuthenticationDefaults.AuthenticationScheme;
            })
            .AddGoogle("Google", options =>
            {
                options.CallbackPath = "/api/i/v1/identity/handle-external-login/Google/callback";
                options.ClaimActions.MapJsonKey("urn:google:picture", "picture", "url");
                options.ClaimActions.MapJsonKey("urn:google:locale", "locale", "string");
                options.SaveTokens = true;
                options.ClientId = Configuration["Authentication:Google:ClientId"];
                options.ClientSecret = Configuration["Authentication:Google:ClientSecret"];
                options.Events = new OAuthEvents
                {
                    OnRemoteFailure = (RemoteFailureContext context) =>
                    {
                        context.Response.Redirect("/home/denied");
                        context.HandleResponse();
                        return Task.CompletedTask;
                    }
                };
            })
[HttpGet("signin-{provider}")]
        [AllowAnonymous]
        public IActionResult SignInWithGoogle(string provider)
        {
            var redirectUrl = Url.Action(nameof(HandleExternalLogin), "Identity", new { provider });
            var authenticationProperties = _signInManager.ConfigureExternalAuthenticationProperties(provider, redirectUrl);

            return Challenge(authenticationProperties, provider);
        } 

当重定向到谷歌登录页面时:

 400. That’s an error.

Error: invalid_request

Invalid parameter value for redirect_uri: Non-public domains not allowed: http://identity.service/api/i/v1/identity/handle-external-login/Google/callback

如何将 identity.service 更改为 localhost 或其他内容?对不起,我的英语不好,

标签: c#.netdocker.net-core

解决方案


推荐阅读