У меня есть приложение asp.net core web api (app1), которое вызывает другой asp.net core web api (app2), и я рассматриваю app1 как приложение deamon, и я хотел бы отслеживать учетные данные клиента с помощью сертификата, а не приложения. секреты.
https://github.com/Azure-Samples/active ... pplication -using-client-credentials-with-certificates
Все работает нормально, пока оба моих
Код: Выделить всё
app1
Код: Выделить всё
app2
Код: Выделить всё
private static X509Certificate2 ReadCertificate(string certificateName)
{
if (string.IsNullOrWhiteSpace(certificateName))
{
throw new ArgumentException("certificateName should not be empty. Please set the CertificateName setting in the appsettings.json", "certificateName");
}
X509Certificate2 cert = null;
using (X509Store store = new X509Store(StoreName.My, StoreLocation.CurrentUser))
{
store.Open(OpenFlags.ReadOnly);
X509Certificate2Collection certCollection = store.Certificates;
// Find unexpired certificates.
X509Certificate2Collection currentCerts = certCollection.Find(X509FindType.FindByTimeValid, DateTime.Now, false);
// From the collection of unexpired certificates, find the ones with the correct name.
X509Certificate2Collection signingCert = currentCerts.Find(X509FindType.FindBySubjectDistinguishedName, certificateName, false);
// Return the first certificate in the collection, has the right name and is current.
cert = signingCert.OfType().OrderByDescending(c => c.NotBefore).FirstOrDefault();
}
return cert;
}
Код: Выделить всё
using (X509Store store = new X509Store(StoreName.My, StoreLocation.CurrentUser))
Thanks!
Источник: https://stackoverflow.com/questions/626 ... pp-service