c# - IdentityServer 3 不会启动

标签 c# identityserver3

我在启动 IdentityServer 3 时遇到问题。这是一个非常简单的设置,我打算将其用于开发环境,但我在诊断问题时遇到了问题。这是我的代码:

Startup.cs

    using Owin;
    using System;
    using System.Security.Cryptography.X509Certificates;
    using IdentityServer3.Core.Models;
    using IdentityServer3.Core.Configuration;

    namespace IdentityServer3
    {
        public class Startup
        {
            public void Configuration(IAppBuilder app)
            {
                app.Map("/identity", idsrvApp =>
                {
                    idsrvApp.UseIdentityServer(new IdentityServerOptions
                    {
                        SiteName = "Embedded IdentityServer",
                        SigningCertificate = LoadCertificate(),

                        Factory = new IdentityServerServiceFactory()
                                    .UseInMemoryUsers(Users.Get())
                                    .UseInMemoryClients(Clients.Get())
                                    .UseInMemoryScopes(StandardScopes.All)
                    });
                });
            }

            X509Certificate2 LoadCertificate()
            {
                return new X509Certificate2(
                    string.Format(@"{0}bin\idsrv3test.pfx", AppDomain.CurrentDomain.BaseDirectory), "idsrv3test");
            }
        }
}

Users.cs

using IdentityServer3.Core;
using IdentityServer3.Core.Services.InMemory;
using System.Collections.Generic;
using System.Security.Claims;

namespace IdentityServer3
{
    public static class Users
    {
        public static List<InMemoryUser> Get()
        {
            return new List<InMemoryUser>
            {
                new InMemoryUser
                {
                    Username = "bob",
                    Password = "secret",
                    Subject = "1",

                    Claims = new[]
                    {
                        new Claim(Constants.ClaimTypes.GivenName, "Bob"),
                        new Claim(Constants.ClaimTypes.FamilyName, "Smith")
                    }
                }
            };
        }
    }
}

Clients.cs

using IdentityServer3.Core.Models;
using System.Collections.Generic;

namespace IdentityServer3
{
    public static class Clients
    {
        public static IEnumerable<Client> Get()
        {
            return new[]
            {
                new Client
                {
                    Enabled = true,
                    ClientName = "MVC Client",
                    ClientId = "mvc",
                    Flow = Flows.Implicit,

                    RedirectUris = new List<string>
                    {
                        "https://localhost:44319/"
                    },

                    AllowAccessToAllScopes = true
                }
            };
        }
    }
}

证书来自IdentityServer's github examples .它已通过 mmc 证书管理单元导入,我在 Visual Studio 2015 中将“复制到输出目录”设置为“始终复制”。我还在 VS 项目上启用了 SSL,并在 Web 配置/系统中设置了 runAllManagedModulesForAllRequests="true".webServer/modules 部分。

当我尝试通过“开始调试”启动它时,我得到:

{"Could not load type 'IdentityServer3.Core.Configuration.IdentityServerOptions' from assembly 'IdentityServer3, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.":"IdentityServer3.Core.Configuration.IdentityServerOptions"}

还有其他人遇到过这种情况,或者有人对如何诊断它有任何见解吗?

最佳答案

我遇到了同样的问题,它似乎是使用的项目/命名空间的名称。

将我的项目命名为 IdentityServer3 我遇到了同样的问题。我用不同的名称创建了一个项目,这解决了问题。

关于c# - IdentityServer 3 不会启动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42768966/

相关文章:

c# - 这个 Resharper 对处置关闭警告的修复是否有意义?

c# - 处理 Identity Server 客户端凭据流时发出自签名客户端证书

android - 针对身份服务器进行身份验证时 AppAuth oidc 无效状态错误

angularjs - 从 AngularJs http web api 请求重定向到 Identity Server 登录页面

certificate - 使用 OpenId Connect 时验证签名证书

c# - 填充的用户中没有访问 token (Claimsprincipal)

c# - 启动进程时出现 System.ComponentModel.Win32Exception - 找不到文件,但文件存在

c# - 放一个类名=命名空间,在使用

c# - 两种冒泡排序算法的区别

c# - 如何从 asp :TextBox when using MaxLength property? 中删除空格