微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决外部登录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 举报,一经查实,本站将立刻删除。