I'm currently using PnPCoreAuthenticationX509CertificateOptions as my authentication method. The problem is it runs correctly on my desktop, but when I upload the code to the AWS lambda function, it throws this exception right away. Here is the guide I'm following PnP Core Auth
System.ArgumentNullException: Value cannot be null. (Parameter 'certificate')
or
The specified X509 certificate store does not exist
Here the sample code to load certificate
private X509Certificate2 LoadCertificate(string certificateThumbprint)
{
try
{
var store = new X509Store(StoreName.My, StoreLocation.CurrentUser);
store.Open(OpenFlags.ReadOnly | OpenFlags.OpenExistingOnly);
var certificateCollection = store.Certificates.Find(X509FindType.FindByThumbprint, certificateThumbprint, false);
store.Close();
return certificateCollection.First();
}
catch (Exception err)
{
Console.WriteLine(err.ToString());
return null;
}
}
My configuration for authentication
// Add the PnP Core SDK library
services.AddPnPCore(options =>
{
options.PnPContext.GraphFirst = true;
options.HttpRequests.UserAgent = "ISV|Contoso|ProductX";
options.Sites.Add("Default", new PnPCoreSiteOptions
{
SiteUrl = siteUrl
});
});
services.AddPnPCoreAuthentication(
options =>
{
// Configure an Authentication Provider relying on Windows Credential Manager
options.Credentials.Configurations.Add("x509certificate",
new PnPCoreAuthenticationCredentialConfigurationOptions
{
ClientId = clientId,
TenantId = tenantId,
X509Certificate = new PnPCoreAuthenticationX509CertificateOptions
{
StoreName = StoreName.My,
StoreLocation = StoreLocation.CurrentUser,
Thumbprint = thumbprintCerf
}
});
// Configure the default authentication provider
options.Credentials.DefaultConfiguration = "x509certificate";
// Map the site defined in AddPnPCore with the
// Authentication Provider configured in this action
options.Sites.Add("Default",
new PnPCoreAuthenticationSiteOptions
{
AuthenticationProviderName = "x509certificate"
});
});