我在启动 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/