托管WIF身份提供商并为其生成自签名证书

时间:2017-05-31 17:00:00

标签: asp.net azure-web-sites x509certificate wif claims-based-identity

在我的最后一年项目中,我开发了一个ASP.NET网站,并使用Windows Identity Foundation实现了单点登录系统(与此处显示的教程类似:http://www.primaryobjects.com/2013/08/08/using-single-sign-on-with-windows-identity-foundation-in-mvc-net)< / p>

这意味着我目前拥有2个网站,我的身份提供商网站以及使用IP并包含大部分功能的网站.IP使用X509证书生成令牌,为此我迄今为止已经能够使用自签名证书。这是我用来从本地计算机检索证书的代码:

 var store = new X509Store(StoreName.My, StoreLocation.LocalMachine);
        X509Certificate2Collection certificates = null;
        store.Open(OpenFlags.ReadOnly);

        try
        {
            certificates = store.Certificates;
            var certs = certificates.OfType<X509Certificate2>().Where(x => x.SubjectName.Name.Equals(subjectName, StringComparison.OrdinalIgnoreCase)).ToList();

            if (certs.Count == 0)
                throw new ApplicationException(string.Format("No certificate was found for subject Name {0}", subjectName));
            else if (certs.Count > 1)
                throw new ApplicationException(string.Format("There are multiple certificates for subject Name {0}", subjectName));

            return new X509Certificate2(certs[0]);
        }

为了能够展示我的项目,我将被要求在网上主持,但这意味着我需要替换我的自签名证书。

我可以使用像azure网站这样的东西来托管我的网站,但到目前为止我找不到能够在Azure等服务上生成自签名证书并以编程方式检索它的解决方案。

你能否建议我解决这个问题?

1 个答案:

答案 0 :(得分:0)

理想情况下,您不必创建自己的IDP。你可以使用像ADFS这样的东西。

Azure AD是一个IDP并拥有自己的证书,因此您无需创建任何证书。

您只需要元数据,就可以在AppServices / Endpoints下找到URL。

有一个例子here,但请注意,这使用WS-Fed OWIN而不是WIF。 (WIF有些老派)。

为了让您的生活更轻松,您可以通过向global.asax添加代码来更新您的web.config programmatically

或者只是将整个解决方案移动到Azure中的VM。