Options
All
  • Public
  • Public/Protected
  • All
Menu

Class CertificateClient

Package version

The client to interact with the KeyVault certificates functionality

Hierarchy

  • CertificateClient

Index

Constructors

constructor

  • Creates an instance of CertificateClient.

    Parameters

    • vaultUrl: string

      the base URL to the vault.

    • credential: TokenCredential

      An object that implements the TokenCredential interface used to authenticate requests to the service. Use the @azure/identity package to create a credential that suits your needs.

    • Default value pipelineOptions: CertificateClientOptions = {}

      Pipeline options used to configure Key Vault API requests. Omit this parameter to use the default pipeline configuration.

    Returns CertificateClient

Properties

vaultUrl

vaultUrl: string

The base URL to the vault

Methods

backupCertificate

  • Requests that a backup of the specified certificate be downloaded to the client. All versions of the certificate will be downloaded. This operation requires the certificates/backup permission.

    Example usage:

    const client = new CertificateClient(url, credentials);
    await client.beginCreateCertificate("MyCertificate", {
      issuerName: "Self",
      subject: "cn=MyCert"
    });
    const backup = await client.backupCertificate("MyCertificate");

    Generates a backup of a certificate

    Parameters

    • certificateName: string

      The name of the certificate

    • Default value options: BackupCertificateOptions = {}

      The optional parameters

    Returns Promise<Uint8Array | undefined>

beginCreateCertificate

  • Creates a new certificate. If this is the first version, the certificate resource is created. This function returns a Long Running Operation poller that allows you to wait indefinitely until the certificate is fully recovered.

    Note: Sending Self as the issuerName of the certificate's policy will create a self-signed certificate.

    This operation requires the certificates/create permission.

    Example usage:

    const client = new CertificateClient(url, credentials);
    const certificatePolicy = {
      issuerName: "Self",
      subject: "cn=MyCert"
    };
    const createPoller = await client.beginCreateCertificate("MyCertificate", certificatePolicy);
    
    // The pending certificate can be obtained by calling the following method:
    const pendingCertificate = createPoller.getResult();
    
    // Serializing the poller
    const serialized = createPoller.toString();
    
    // A new poller can be created with:
    // const newPoller = await client.beginCreateCertificate("MyCertificate", certificatePolicy, { resumeFrom: serialized });
    
    // Waiting until it's done
    const certificate = await createPoller.pollUntilDone();
    console.log(certificate);

    Creates a certificate

    Parameters

    Returns Promise<PollerLike<CreateCertificateState, KeyVaultCertificateWithPolicy>>

beginDeleteCertificate

  • The DELETE operation applies to any certificate stored in Azure Key Vault. DELETE cannot be applied to an individual version of a certificate. This function returns a Long Running Operation poller that allows you to wait indefinitely until the certificate is fully recovered.

    This operation requires the certificates/delete permission.

    Example usage:

    const client = new CertificateClient(url, credentials);
    const createPoller = await client.beginCreateCertificate("MyCertificate", {
      issuerName: "Self",
      subject: "cn=MyCert"
    });
    await createPoller.pollUntilDone();
    
    const deletePoller = await client.beginDeleteCertificate("MyCertificate");
    
    // Serializing the poller
    const serialized = deletePoller.toString();
    
    // A new poller can be created with:
    // const newPoller = await client.beginDeleteCertificate("MyCertificate", { resumeFrom: serialized });
    
    // Waiting until it's done
    const deletedCertificate = await deletePoller.pollUntilDone();
    console.log(deletedCertificate);

    Deletes a certificate from a specified key vault.

    Parameters

    Returns Promise<PollerLike<DeleteCertificateState, DeletedCertificate>>

beginRecoverDeletedCertificate

  • Recovers the deleted certificate in the specified vault. This operation can only be performed on a soft-delete enabled vault. This operation This function returns a Long Running Operation poller that allows you to wait indefinitely until the certificate is fully recovered.

    This operation requires the certificates/recover permission.

    Example usage:

    const client = new CertificateClient(url, credentials);
    
    const deletePoller = await client.beginDeleteCertificate("MyCertificate");
    await deletePoller.pollUntilDone();
    
    const recoverPoller = await client.beginRecoverDeletedCertificate("MyCertificate");
    
    // Serializing the poller
    const serialized = deletePoller.toString();
    
    // A new poller can be created with:
    // const newPoller = await client.beginRecoverDeletedCertificate("MyCertificate", { resumeFrom: serialized });
    
    // Waiting until it's done
    const certificate = await recoverPoller.pollUntilDone();
    console.log(certificate);

    Recovers a deleted certificate

    Parameters

    Returns Promise<PollerLike<RecoverDeletedCertificateState, KeyVaultCertificateWithPolicy>>

createIssuer

  • The createIssuer operation adds or updates the specified certificate issuer. This operation requires the certificates/setissuers permission.

    Example usage:

    const client = new CertificateClient(url, credentials);
    await client.createIssuer("IssuerName", "Test");

    Sets the specified certificate issuer.

    Parameters

    • issuerName: string

      The name of the issuer.

    • provider: string

      The issuer provider.

    • Default value options: CreateIssuerOptions = {}

      The optional parameters

    Returns Promise<CertificateIssuer>

deleteCertificateOperation

  • Deletes the creation operation for a specified certificate that is in the process of being created. The certificate is no longer created. This operation requires the certificates/update permission.

    Example usage:

    const client = new CertificateClient(url, credentials);
    await client.beginCreateCertificate("MyCertificate", {
      issuerName: "Self",
      subject: "cn=MyCert"
    });
    await client.deleteCertificateOperation("MyCertificate");
    await client.getCertificateOperation("MyCertificate"); // Throws error: Pending certificate not found: "MyCertificate"

    Delete a certificate's operation

    Parameters

    Returns Promise<CertificateOperation>

deleteContacts

  • Deletes all of the certificate contacts. This operation requires the certificates/managecontacts permission.

    Example usage:

    let client = new CertificateClient(url, credentials);
    await client.setContacts([{
      email: "b@b.com",
      name: "b",
      phone: "222222222222"
    }]);
    await client.deleteContacts();

    Deletes all of the certificate contacts

    Parameters

    Returns Promise<CertificateContact[] | undefined>

deleteIssuer

  • The deleteIssuer operation permanently removes the specified certificate issuer from the vault. This operation requires the certificates/manageissuers/deleteissuers permission.

    Example usage:

    const client = new CertificateClient(url, credentials);
    await client.createIssuer("IssuerName", "Provider");
    await client.deleteIssuer("IssuerName");

    Deletes the specified certificate issuer.

    Parameters

    • issuerName: string

      The name of the issuer.

    • Default value options: DeleteIssuerOptions = {}

      The optional parameters

    Returns Promise<CertificateIssuer>

getCertificate

  • Gets the latest information available from a specific certificate, including the certificate's policy. This operation requires the certificates/get permission.

    Example usage:

    const client = new CertificateClient(url, credentials);
    const poller = await client.beginCreateCertificate("MyCertificate", {
      issuerName: "Self",
      subject: "cn=MyCert"
    });
    await poller.pollUntilDone();
    const certificate = await client.getCertificate("MyCertificate");
    console.log(certificate);

    Retrieves a certificate from the certificate's name (includes the certificate policy)

    Parameters

    • certificateName: string

      The name of the certificate

    • Default value options: GetCertificateOptions = {}

      The optional parameters

    Returns Promise<KeyVaultCertificateWithPolicy>

getCertificateOperation

  • Gets the creation operation associated with a specified certificate. This operation requires the certificates/get permission. This function returns a Long Running Operation poller that allows you to wait indefinitely until the certificate is fully recovered.

    Example usage:

    const client = new CertificateClient(url, credentials);
    const createPoller = await client.beginCreateCertificate("MyCertificate", {
      issuerName: "Self",
      subject: "cn=MyCert"
    });
    
    const poller = await client.getCertificateOperation("MyCertificate");
    const pendingCertificate = poller.getResult();
    
    const certificateOperation = poller.getOperationState().certificateOperation;
    console.log(certificateOperation);

    Gets a certificate's poller operation

    Parameters

    Returns Promise<PollerLike<CertificateOperationState, KeyVaultCertificateWithPolicy>>

getCertificatePolicy

  • The getCertificatePolicy operation returns the specified certificate policy resources in the specified key vault. This operation requires the certificates/get permission.

    Example usage:

    const client = new CertificateClient(url, credentials);
    await client.beginCreateCertificate("MyCertificate", {
      issuerName: "Self",
      subject: "cn=MyCert"
    });
    const policy = await client.getCertificatePolicy("MyCertificate");
    console.log(policy);

    Gets a certificate's policy

    Parameters

    Returns Promise<CertificatePolicy>

getCertificateVersion

  • Gets information about a specific certificate on a specific version. It won't return the certificate's policy. This operation requires the certificates/get permission.

    Example usage:

    const client = new CertificateClient(url, credentials);
    const poller = await client.beginCreateCertificate("MyCertificate", {
      issuerName: "Self",
      subject: "cn=MyCert"
    });
    await poller.pollUntilDone();
    const certificateWithPolicy = await client.getCertificate("MyCertificate");
    const certificate = await client.getCertificateVersion("MyCertificate", certificateWithPolicy.properties.version!);
    console.log(certificate);

    Retrieves a certificate from the certificate's name and a specified version

    Parameters

    • certificateName: string

      The name of the certificate

    • version: string

      The specific version of the certificate

    • Default value options: GetCertificateVersionOptions = {}

      The optional parameters

    Returns Promise<KeyVaultCertificate>

getContacts

  • Returns the set of certificate contact resources in the specified key vault. This operation requires the certificates/managecontacts permission.

    Example usage:

    let client = new CertificateClient(url, credentials);
    await client.setContacts([{
      email: "b@b.com",
      name: "b",
      phone: "222222222222"
    }]);
    const contacts = await client.getContacts();
    console.log(contacts);

    Sets the certificate contacts.

    Parameters

    Returns Promise<CertificateContact[] | undefined>

getDeletedCertificate

  • retrieves the deleted certificate information plus its attributes, such as retention interval, scheduled permanent deletion and the current deletion recovery level. This operation requires the certificates/get permission.

    Example usage:

    const client = new CertificateClient(url, credentials);
    const deletedCertificate = await client.getDeletedCertificate("MyDeletedCertificate");
    console.log("Deleted certificate:", deletedCertificate);

    Gets a deleted certificate

    Parameters

    Returns Promise<DeletedCertificate>

getIssuer

  • The getIssuer operation returns the specified certificate issuer resources in the specified key vault. This operation requires the certificates/manageissuers/getissuers permission.

    Example usage:

    const client = new CertificateClient(url, credentials);
    await client.createIssuer("IssuerName", "Test");
    const certificateIssuer = await client.getIssuer("IssuerName");
    console.log(certificateIssuer);

    Gets he specified certificate issuer.

    Parameters

    • issuerName: string

      The name of the issuer.

    • Default value options: GetIssuerOptions = {}

      The optional parameters

    Returns Promise<CertificateIssuer>

importCertificate

  • Imports an existing valid certificate, containing a private key, into Azure Key Vault. The certificate to be imported can be in either PFX or PEM format. If the certificate is in PEM format the PEM file must contain the key as well as x509 certificates. This operation requires the certificates/import permission.

    Example usage:

    const client = new CertificateClient(url, credentials);
    // See: @azure/keyvault-secrets
    const certificateSecret = await secretClient.getSecret("MyCertificate");
    const base64EncodedCertificate = certificateSecret.value!;
    let buffer: Uint8Array;
    
    if (isNode) {
      buffer = Buffer.from(base64EncodedCertificate, "base64");
    } else {
      buffer = Uint8Array.from(atob(base64EncodedCertificate), (c) => c.charCodeAt(0));
    }
    
    await client.importCertificate("MyCertificate", buffer);

    Imports a certificate from a certificate's secret value

    Parameters

    • certificateName: string

      The name of the certificate

    • certificateBytes: Uint8Array

      The PFX or ASCII PEM formatted value of the certificate containing both the X.509 certificates and the private key

    • Default value options: ImportCertificateOptions = {}

      The optional parameters

    Returns Promise<KeyVaultCertificateWithPolicy>

listDeletedCertificates

  • Retrieves the certificates in the current vault which are in a deleted state and ready for recovery or purging. This operation includes deletion-specific information. This operation requires the certificates/get/list permission. This operation can only be enabled on soft-delete enabled vaults.

    Example usage:

    const client = new CertificateClient(url, credentials);
    for await (const deletedCertificate of client.listDeletedCertificates()) {
      console.log(deletedCertificate);
    }
    for await (const page of client.listDeletedCertificates().byPage()) {
      for (const deletedCertificate of page) {
        console.log(deletedCertificate);
      }
    }

    Lists deleted certificates

    Parameters

    Returns PagedAsyncIterableIterator<DeletedCertificate>

listPropertiesOfCertificateVersions

  • Returns the versions of a certificate in the specified key vault. This operation requires the certificates/list permission.

    Example usage:

    const client = new CertificateClient(url, credentials);
    for await (const certificateProperties of client.listPropertiesOfCertificateVersions("MyCertificate")) {
      console.log(certificateProperties.version!);
    }

    List the versions of a certificate.

    Parameters

    Returns PagedAsyncIterableIterator<CertificateProperties>

listPropertiesOfCertificates

  • Iterates the latest version of all certificates in the vault. The full certificate identifier and attributes are provided in the response. No values are returned for the certificates. This operations requires the certificates/list permission.

    Example usage:

    const client = new CertificateClient(url, credentials);
    // All in one call
    for await (const certificateProperties of client.listPropertiesOfCertificates()) {
      console.log(certificateProperties);
    }
    // By pages
    for await (const page of client.listPropertiesOfCertificates().byPage()) {
      for (const certificateProperties of page) {
        console.log(certificateProperties);
      }
    }

    List all versions of the specified certificate.

    Parameters

    Returns PagedAsyncIterableIterator<CertificateProperties>

listPropertiesOfIssuers

  • Returns the set of certificate issuer resources in the specified key vault. This operation requires the certificates/manageissuers/getissuers permission.

    Example usage:

    const client = new CertificateClient(url, credentials);
    await client.createIssuer("IssuerName", "Test");
    // All in one call
    for await (const issuerProperties of client.listPropertiesOfIssuers()) {
      console.log(issuerProperties);
    }
    // By pages
    for await (const page of client.listPropertiesOfIssuers().byPage()) {
      for (const issuerProperties of page) {
        console.log(issuerProperties);
      }
    }

    List the certificate issuers.

    Parameters

    Returns PagedAsyncIterableIterator<IssuerProperties>

mergeCertificate

  • Performs the merging of a certificate or certificate chain with a key pair currently available in the service. This operation requires the certificates/create permission.

    Example usage:

    const client = new CertificateClient(url, credentials);
    await client.beginCreateCertificate("MyCertificate", {
      issuerName: "Unknown",
      subject: "cn=MyCert"
    });
    const poller = await client.getCertificateOperation("MyCertificate");
    const { csr } = poller.getOperationState().certificateOperation!;
    const base64Csr = Buffer.from(csr!).toString("base64");
    const wrappedCsr = ["-----BEGIN CERTIFICATE REQUEST-----", base64Csr, "-----END CERTIFICATE REQUEST-----"].join("\n");
    
    const fs = require("fs");
    fs.writeFileSync("test.csr", wrappedCsr);
    
    // Certificate available locally made using:
    //   openssl genrsa -out ca.key 2048
    //   openssl req -new -x509 -key ca.key -out ca.crt
    // You can read more about how to create a fake certificate authority here: https://gist.github.com/Soarez/9688998
    
    const childProcess = require("child_process");
    childProcess.execSync("openssl x509 -req -in test.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out test.crt");
    const base64Crt = fs.readFileSync("test.crt").toString().split("\n").slice(1, -1).join("");
    
    await client.mergeCertificate("MyCertificate", [Buffer.from(base64Crt)]);

    Merges a signed certificate request into a pending certificate

    Parameters

    • certificateName: string

      The name of the certificate

    • x509Certificates: Uint8Array[]

      The certificate(s) to merge

    • Default value options: MergeCertificateOptions = {}

      The optional parameters

    Returns Promise<KeyVaultCertificateWithPolicy>

purgeDeletedCertificate

  • Performs an irreversible deletion of the specified certificate, without possibility for recovery. The operation is not available if the recovery level does not specify 'Purgeable'. This operation requires the certificate/purge permission.

    Example usage:

    const client = new CertificateClient(url, credentials);
    const deletePoller = await client.beginDeleteCertificate("MyCertificate");
    await deletePoller.pollUntilDone();
    // Deleting a certificate takes time, make sure to wait before purging it
    client.purgeDeletedCertificate("MyCertificate");

    Gets a deleted certificate

    Parameters

    • certificateName: string

      The name of the deleted certificate to purge

    • Default value options: PurgeDeletedCertificateOptions = {}

      The optional parameters

    Returns Promise<null>

restoreCertificateBackup

  • Restores a backed up certificate, and all its versions, to a vault. This operation requires the certificates/restore permission.

    Example usage:

    const client = new CertificateClient(url, credentials);
    await client.beginCreateCertificate("MyCertificate", {
      issuerName: "Self",
      subject: "cn=MyCert"
    });
    const backup = await client.backupCertificate("MyCertificate");
    const poller = await client.beginDeleteCertificate("MyCertificate");
    await poller.pollUntilDone();
    // Some time is required before we're able to restore the certificate
    await client.restoreCertificateBackup(backup!);

    Restores a certificate from a backup

    Parameters

    Returns Promise<KeyVaultCertificateWithPolicy>

setContacts

  • Sets the certificate contacts for the key vault. This operation requires the certificates/managecontacts permission.

    Example usage:

    let client = new CertificateClient(url, credentials);
    await client.setContacts([{
      email: "b@b.com",
      name: "b",
      phone: "222222222222"
    }]);

    Sets the certificate contacts.

    Parameters

    Returns Promise<CertificateContact[] | undefined>

updateCertificatePolicy

updateCertificateProperties

  • Applies the specified update on the given certificate; the only elements updated are the certificate's attributes. This operation requires the certificates/update permission.

    Example usage:

    const client = new CertificateClient(url, credentials);
    await client.beginCreateCertificate("MyCertificate", {
      issuerName: "Self",
      subject: "cn=MyCert"
    });
    await client.updateCertificateProperties("MyCertificate", "", {
      tags: {
        customTag: "value"
      }
    });

    Updates a certificate

    Parameters

    • certificateName: string

      The name of the certificate

    • version: string

      The version of the certificate to update

    • Default value options: UpdateCertificatePropertiesOptions = {}

      The options, including what to update

    Returns Promise<KeyVaultCertificate>

updateIssuer

  • The updateIssuer operation performs an update on the specified certificate issuer entity. This operation requires the certificates/setissuers permission.

    Example usage:

    const client = new CertificateClient(url, credentials);
    await client.createIssuer("IssuerName", "Test");
    await client.updateIssuer("IssuerName", {
      provider: "Provider2"
    });

    Updates the specified certificate issuer.

    Parameters

    • issuerName: string

      The name of the issuer.

    • Default value options: UpdateIssuerOptions = {}

      The optional parameters

    Returns Promise<CertificateIssuer>

Generated using TypeDoc