首页 文章

具有EF标识数据库的Identity Server 4 - OpenID Connect失败

提问于
浏览
0

请注意:这篇文章没有解决这个问题 . 我被要求创建一个新帖子 . 请参阅 Headers 为的新帖子:

带有EF标识数据库的Identity Server 4 - OpenID Connect失败(1)

我有一个带有EF Identity DB的Identity Server 4解决方案 . 我可以使用我的电子邮件和外部Gmail帐户登录,但是当我尝试使用OpenID(用户名和密码)登录时,我收到以下错误 . 问题可能与存储在Identity DB表中的信息有关 . 我是Identity Server的新手,这是我第一次尝试使用EF Identity DB . 我可以发布数据库信息,如果它有助于解决问题 .

源代码:https://github.com/gotnetdude/GotNetDude-PublicRepository/tree/master/AuthServer

Identity Server日志文件:https://github.com/gotnetdude/GotNetDude-PublicRepository/blob/master/AuthServer_log.txt

MVC客户端日志:https://github.com/gotnetdude/GotNetDude-PublicRepository/blob/master/MVCClient_log.txt

任何建议,将不胜感激 . 保罗

EDIT

请在下面找到身份表中的客户端配置信息 . 我不确定在DB中设置AllowedRedirectUris的位置 . 我的另一个问题是,当我使用我的电子邮件帐户登录时,为什么会这样?

enter image description here

enter image description here

enter image description here

这是AuthServer启动代码,我将oidc mvc客户端添加为失败的挑战选项(“OpenID Connect”) . 如果我使用电子邮件凭据登录,MVC客户端工作正常 . 我想这与mvc客户端上处理作用域的方式有关 . 任何建议都表示赞赏 .

services.AddAuthentication()
                .AddGoogle("Google", options =>
                {
                    options.ClientId = "434483408261-55tc8n0cs4ff1fe21ea8df2o443v2iuc.apps.googleusercontent.com";
                    options.ClientSecret = "3gcoTrEDPPJ0ukn_aYYT6PWo";
                })
                .AddOpenIdConnect("oidc", "OpenID Connect", options =>
                {
                    //options.Authority = "https://demo.identityserver.io/";
                    //options.ClientId = "implicit";
                    //options.SaveTokens = true;

                    options.Authority = "http://localhost:5000";
                    options.RequireHttpsMetadata = false;
                    options.SaveTokens = true;
                    options.ClientId = "mvc";

                    options.TokenValidationParameters = new TokenValidationParameters
                    {
                        NameClaimType = "name",
                        RoleClaimType = "role"
                    };
                });

我正在尝试从MVC客户端(:5002)连接到权限(:5000),请参见下图:
enter image description here

来自AccountService的调试结果:
enter image description here

在上下文客户端的客户端存储中有3个实例IdentityServer4.EntityFramework.Entities.Client . 所有3个实例都将EnableLocalLogin设置为True . 我在选择OpenID Connect选项后点击了断点 .

我还在登录控制器的顶部设置了一个断点,它从未到达:
enter image description here

2 回答

  • 0

    我认为问题在于来自AuthServer / Startup的74

    .AddOpenIdConnect("oidc", "OpenID Connect", options =>
        {
            ...
            options.ClientId = "mvc";
            ...
        });
    

    服务器不是mvc客户端 . 我认为这是'confusing' IdentityServer . 您不需要将oidc添加到服务器 . 如果你删除这些行,那么它应该工作 .

    如果您从mvc客户端网站(:5002)登录,那么您应该被重定向 . 如果您登录IdentityServer(:5000),则无需重定向 . 服务器是权限,资源由范围和客户端由clientid标识 .

  • 0

    检查您提供的日志文件 . 您收到的错误是

    无效的redirect_uri:http:// localhost:5000 / signin-oidc .

    如果您检查客户端配置, AllowedRedirectUris 包含 http://localhost:5002/signin-oidc .

    你在港口有一个(错字)错误 . 它必须是 5002 .

    EDIT

    根据您的屏幕截图和日志文件,您的客户端在Identity Server端正确配置 . 问题出在您的MVC客户端,而不是数据库中 . 您需要查看那里,并找到启动客户端本身时设置的 RedirectUrl .

    EDIT 2:

    好的,看了你的代码,我意识到@Ruard van Elburg告诉你的是造成这个问题的原因 . 使用内部身份验证时,您不需要像这样指定它(您真的很混淆Identity Server) . 此规范仅适用于外部Oidc提供程序(例如Okta,或您拥有的任何其他Oidc提供程序) . 检查here . 您看到 - Identity Server Startup.cs 不包含您拥有的此代码(第74到89行here) . 我们为什么不一步一步地这样做 . 尝试删除我提到的行 .

相关问题