如何设置redirect_uri登录谷歌.Net Core 2,Docker

时间:2019-11-19 04:11:12

标签: c# .net docker .net-core

我正在尝试在.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);
        } 

重定向到Google登录页面时:

 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或其他? 对不起,我的英语不好,

0 个答案:

没有答案