Asp.net IdentityServer3-客户端证书验证

Asp.net IdentityServer3-客户端证书验证,asp.net,oauth-2.0,openid-connect,identityserver3,Asp.net,Oauth 2.0,Openid Connect,Identityserver3,我有IdentityServer3,我正在尝试运行他们的原始示例WebHost(minimal)作为服务器,并且控制台客户端凭据使用Certificate作为客户端,因为我想测试客户端是否可以通过使用X509指纹而不是共享密钥来验证IdS3以获得访问令牌 我遇到的问题是,我得到了一个错误响应:无效的\u客户端。 显然,这是因为IdS3没有收到传入请求的证书,所以它认为令牌请求无效(我通过添加一个定制的SecretParser并检查environment参数来测试这一点,没有ssl.ClientC

我有IdentityServer3,我正在尝试运行他们的原始示例
WebHost(minimal)
作为服务器,并且
控制台客户端凭据使用Certificate
作为客户端,因为我想测试客户端是否可以通过使用X509指纹而不是共享密钥来验证IdS3以获得访问令牌

我遇到的问题是,我得到了一个错误响应:
无效的\u客户端
。 显然,这是因为IdS3没有收到传入请求的证书,所以它认为令牌请求无效(我通过添加一个定制的
SecretParser
并检查
environment
参数来测试这一点,没有
ssl.ClientCertificate
值,它是
X509CertificateScretParser
用来解析它的值)


我只是将Visual Studio的两个不同实例中的两个项目运行到IIS Express中,而没有修改项目上的任何其他内容。在这件事上我是否缺少任何内容?为了使此工作正常,我还需要设置哪些内容?

您需要做的第一件事是在IIS Express中启用客户端证书

您可以通过编辑此文件来执行此操作:

.vs\config\applicationhost.config

改变

<access sslFlags="None" />


现在IIS Express支持客户端证书,但它也会检查证书是否可信

示例证书Client.pfx无法开箱即用

您可以让Windows信任此证书的颁发者(不推荐),也可以从证书存储中加载现有证书,代码如下:

        X509Store store = new X509Store(StoreLocation.CurrentUser);
        store.Open(OpenFlags.ReadOnly);
        string thumb = "<thumbprint>";
        X509Certificate2Collection cers = store.Certificates.Find(X509FindType.FindByThumbprint, thumb, false);
        X509Certificate2 cert = null;
        if (cers.Count > 0)
        {
            cert = cers[0];
        }
        store.Close();
X509Store store=新的X509Store(StoreLocation.CurrentUser);
打开(OpenFlags.ReadOnly);
弦拇指=”;
X509Certificate2Collection cers=store.Certificates.Find(X509FindType.FindBythythumbPrint,thumb,false);
X509Certificate2Cert=null;
如果(cers.Count>0)
{
证书=核证的排减量[0];
}
store.Close();
您还需要将此证书的指纹放入Identity Server上客户端列表中的ClientSecret属性中

这是您需要更改的示例代码:

            new Client
            {
                ClientName = "Client Credentials Flow Client",
                Enabled = true,
                ClientId = "clientcredentials.client",
                Flow = Flows.ClientCredentials,

                ClientSecrets = new List<Secret>
                    {
                        new Secret("secret".Sha256()),
                        new Secret
                        {
                            Value = "<your thumbprint here>",
                            Type = Constants.SecretTypes.X509CertificateThumbprint,
                            Description = "Client Certificate"
                        },
                    },

                AllowedScopes = new List<string>
                    {
                        "read",
                        "write"
                    },

                Claims = new List<Claim>
                    {
                        new Claim("location", "datacenter")
                    }
            },
新客户端
{
ClientName=“客户端凭据流客户端”,
启用=真,
ClientId=“clientcredentials.client”,
Flow=Flows.ClientCredentials,
ClientSecrets=新列表
{
新秘密(“Secret.Sha256()),
新秘密
{
Value=“”,
类型=常量.SecretTypes.X509CertificateThumbprint,
Description=“客户端证书”
},
},
AllowedScopes=新列表
{
“读”,
“写”
},
索赔=新名单
{
新索赔(“位置”、“数据中心”)
}
},

对于没有证书且客户端不需要证书的请求(如没有指纹机密),这是否有效?
            new Client
            {
                ClientName = "Client Credentials Flow Client",
                Enabled = true,
                ClientId = "clientcredentials.client",
                Flow = Flows.ClientCredentials,

                ClientSecrets = new List<Secret>
                    {
                        new Secret("secret".Sha256()),
                        new Secret
                        {
                            Value = "<your thumbprint here>",
                            Type = Constants.SecretTypes.X509CertificateThumbprint,
                            Description = "Client Certificate"
                        },
                    },

                AllowedScopes = new List<string>
                    {
                        "read",
                        "write"
                    },

                Claims = new List<Claim>
                    {
                        new Claim("location", "datacenter")
                    }
            },