Search code examples
azure-active-directorycertificatex509pem

Unable to add certificate during Azure AD app integration


I encounter the following error when attempting to add a certificate, it's filename cert.pem, for an Azure AD app that I am integrating:

Failed to add certificate. Error detail: Upload a certificate (public key) with one of the following file types: .cer, .pem, .crt

I am sure that even though the file type is correct (.pem) the structure and content of the file is incorrect, but I don't know how to fix it.


Solution

  • As you said, the content of the file is incorrect. You could create a certificate for testing purposes using PowerShell with New-SelfSignedCertificate. Try to refer to here. Make sure you open PowerShell as an admin account.

    $pwd = "<password>"
    $currentDate = Get-Date
    $endDate = $currentDate.AddYears(10) #10 years is nice and long
    $thumb = (New-SelfSignedCertificate -DnsName "techmikael.com" -CertStoreLocation "cert:\LocalMachine\My"  -KeyExportPolicy Exportable -Provider "Microsoft Enhanced RSA and AES Cryptographic Provider" -NotAfter $endDate).Thumbprint
    $pwd = ConvertTo-SecureString -String $pwd -Force -AsPlainText
    Export-PfxCertificate -cert "cert:\localmachine\my\$thumb" -FilePath .\techmikael.pfx -Password $pwd
    $path = (Get-Item -Path ".\").FullName
    $cert = New-Object System.Security.Cryptography.X509Certificates.X509Certificate("$path\techmikael.pfx", $pwd)
    $keyValue = [System.Convert]::ToBase64String($cert.GetRawCertData())