Search code examples
c#azurex509http-status-code-403xero-api

Connect Azure Website to Xero Partner Application


I'm integrating my app with Xero which requires two certificates. I uploaded them to Azure with help from this article, but I'm still unable to connect to the Xero API. I'm hoping someone has experience integrating a Xero Partner Application with an Azure Web App.

I've uploaded two pfx files; one is a self-signed certificate and the other is the partner certificate issued by Xero. The latter pfx file contains two certificates; an Entrust Commercial Private Sub CA1 (whatever than means) and a unique Entrust Id certificate for my app.

I'm using the following code to load the certificates by their unique thumbprint:

    static X509Certificate2 GetCertificateFromStore(string thumbprint)
    {
        var store = new X509Store(StoreLocation.CurrentUser);

        try
        {
            thumbprint = Regex.Replace(thumbprint, @"[^\da-zA-z]", string.Empty).ToUpper();
            store.Open(OpenFlags.ReadOnly);

            var certCollection = store.Certificates;
            var currentCerts = certCollection.Find(X509FindType.FindByTimeValid, DateTime.Now, false);
            var signingCert = currentCerts.Find(X509FindType.FindByThumbprint, thumbprint, false);

            if (signingCert.Count == 0)
            {
                throw new Exception($"Could not find Xero SSL certificate. cert_name={thumbprint}");
            }

            return signingCert[0];
        }
        finally
        {
            store.Close();
        }
    }

This works fine locally, but on my azure web site I get a 403.7 error:

The page you are attempting to access requires your browser to have a Secure Sockets Layer (SSL) client certificate that the Web server recognizes.

I've also looked at the following references to try and resolve the issue:

What I haven't tried yet:

  • Converting my web app to a cloud service; trying to avoid doing this however I'm not sure what steps are involved.
  • Using a VM; I haven't found any detailed steps on how to do this but seems like a better option than above.

Screenshot of the error: Error


Solution

  • Finally got this working and I will post my solution which will hopefully save developers a lot of time and frustration when connecting with Xero.

    The Xero Partner Application will not work with Azure App Services (Web Sites). You have to upload two additional certificates along with your self-signed and the Xero partner certificate. These can be found on your local machine and can be exported in cer format (details of these certificates below). Not being able to upload these certificates for Azure app services is indeed the crutch. They also have to be uploaded to specific stores (Root/CA), which you cannot do with app services. These are the steps I took to connect with Xero.

    1. Converted my web site to Azure Cloud Services: I was weary of changing our environment as we already have a live site. It turns out that cloud services is essentially the same as app services; you still are deploying to a VM somewhere. However, you have more control over the back end and you can remote desktop in. Read more here. Used links below to create and convert my website to cloud services:

    2. Uploaded 4 certificates to my cloud project using the azure portal. You will need to upload the following:

      • Your self-signed certificate (the one you created here)
      • The partner certificate issued by Xero (you probably got it here)
      • The Intermediate Entrust certificate (this one should be contained within the .p12 file you downloaded above)
      • The Entrust Root certificate (this should be in your Trusted Root Store**)
    3. Added the certificates to my Web Role in the Cloud project. You have to right click on the properties of your web role and go to the certificates tab. Add all 4 certificates to your web role using the thumbprint which will be visible in the portal after you uploaded them. Take note of the Store Name for the two entrust certs:

    enter image description here

    You may have to adopt a lot of patience as I have to get through step one. You'll have to figure out the new deployment process, how to debug your project locally, and probably a lot of other frustrating tidbits!

    **This is the correct Entrust Root certificate you can get by using certmgr.msc:

    enter image description here