外部登录Google和Facebook无法与身份服务器4一起使用

问题描述

注册服务

public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllersWithViews();
            services.ConfigureIdentityServer(Configuration);

            services.ConfigureExternalOidcProvider(); --> Here is the register code

            services.AddRazorPages();
        }

 public static void ConfigureExternalOidcProvider(this IServiceCollection services)
        {
            services.AddAuthentication().AddGoogle("Google",options =>
            {
                options.SignInScheme = IdentityServerConstants.ExternalCookieAuthenticationScheme;

                options.ClientId = "xxxxxxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxx.apps.googleusercontent.com";
                options.ClientSecret = "xxxxxxxxxxxxxxxxxxxxxx";
            }).AddFacebook(options =>
            {
                options.SignInScheme = IdentityServerConstants.ExternalCookieAuthenticationScheme;
                options.AppId = "xxxxxxxxxxxxxxxxxxxxxxxx";
                options.AppSecret = "xxxxxxxxxxxxxxxx";
            });
        }

#Identity Server外部控制器

 public IActionResult Challenge(string scheme,string returnUrl)
        {
            if (string.IsNullOrEmpty(returnUrl)) returnUrl = "~/";

            // validate returnUrl - either it is a valid OIDC URL or back to a local page
            if (Url.IsLocalUrl(returnUrl) == false && _interaction.IsValidReturnUrl(returnUrl) == false)
            {
                // user might have clicked on a malicIoUs link - should be logged
                throw new Exception("invalid return URL");
            }
            
            // start challenge and roundtrip the return URL and scheme 
            var props = new AuthenticationProperties
            {
                RedirectUri = Url.Action(nameof(Callback)),Items =
                {
                    { "returnUrl",returnUrl },{ "scheme",scheme },}
            };
            return Challenge(props,scheme);   
        }

在屏幕上,我具有Facebook和Google按钮

enter image description here

页面的初始加载中,我具有以下网址

https:// localhost:5001 / Account / Login?ReturnUrl =%2Fconnect%2Fauthorize%2Fcallback%3Fclient_id%3DLocal%26redirect_uri%3Dhttps%253A%252F%252Flocalhost%253A5001%252Fauth-callback%26response_type%3Dcode%26scope% 3Dopenid%2520profile%2520email%26state%3Df4821bac074e4ea0aa23c1c21071d309%26code_challenge%3D6rh-RLATVdTIeiOQ5Rzj-9uC5AV6cw1gYTNTMPBfPVY%26code_challenge_method%3DS256%26res

点击Google或Facebook后,URL更改为https:// localhost:5001 / Account / Login?ReturnUrl =%2FExternal%2FCallback

但是它没有重定向到Google或Facebook

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)