Nei*_*ham 1 c# identityserver3
我在启动 IdentityServer 3 时遇到问题。这是一个非常简单的设置,我打算将它用于开发环境,但我在诊断问题时遇到了问题。这是我的代码:
启动文件
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");
}
}
}
Run Code Online (Sandbox Code Playgroud)
用户.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")
}
}
};
}
}
}
Run Code Online (Sandbox Code Playgroud)
客户端.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
}
};
}
}
}
Run Code Online (Sandbox Code Playgroud)
该证书来自IdentityServer 的 github examples。它已通过 mmc 证书管理单元导入,我在 Visual Studio 2015 中将“复制到输出目录”设置为“始终复制”。我还在 VS 项目上启用了 SSL,并在 web 配置/系统中设置了 runAllManagedModulesForAllRequests="true" .webServer/modules 部分。
当我尝试通过“开始调试”启动它时,我得到:
{"无法从程序集 'IdentityServer3, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' 加载类型 'IdentityServer3.Core.Configuration.IdentityServerOptions'。":"IdentityServer3.Core.Configuration.IdentityServerOptions"}
其他人有这个或有任何人对如何诊断它有任何见解?