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

  • new CertificateClient(vaultUrl: string, credential: TokenCredential, pipelineOptions?: PipelineOptions): CertificateClient
  • Creates an instance of CertificateClient.

    memberof

    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: PipelineOptions = {}

    Returns CertificateClient

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.createCertificate("MyCertificate", {
      issuerName: "Self",
      subjectName: "cn=MyCert"
    });
    const backup = await client.backupCertificate("MyCertificate");
    summary

    Generates a backup of a certificate

    Parameters

    Returns Promise<BackupCertificateResult>

cancelCertificateOperation

  • Updates a certificate creation operation that is already in progress. This operation requires the certificates/update permission.

    Example usage:

    const client = new CertificateClient(url, credentials);
    await client.createCertificate("MyCertificate", {
      issuerName: "Self",
      subjectName: "cn=MyCert"
    });
    await client.cancelCertificateOperation("MyCertificate");
    summary

    Cancels a certificate's operation

    Parameters

    Returns Promise<CertificateOperation>

createCertificate

  • Creates a new certificate. If this is the first version, the certificate resource is created. This operation requires the certificates/create permission.

    Example usage:

    const client = new CertificateClient(url, credentials);
    await client.createCertificate("MyCertificate", {
      issuerName: "Self",
      subjectName: "cn=MyCert"
    });
    summary

    Creates a certificate

    Parameters

    Returns Promise<KeyVaultCertificate>

deleteCertificate

  • The DELETE operation applies to any certificate stored in Azure Key Vault. DELETE cannot be applied to an individual version of a certificate. This operation requires the certificates/delete permission.

    Example usage:

    const client = new CertificateClient(url, credentials);
    await client.createCertificate("MyCertificate", {
      issuerName: "Self",
      subjectName: "cn=MyCert"
    });
    await client.deleteCertificate("MyCertificate");
    summary

    Deletes a certificate from a specified key vault.

    Parameters

    Returns Promise<DeletedCertificate>

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.createCertificate("MyCertificate", {
      issuerName: "Self",
      subjectName: "cn=MyCert"
    });
    await client.deleteCertificateOperation("MyCertificate");
    await client.getCertificateOperation("MyCertificate"); // Throws error: Pending certificate not found: "MyCertificate"
    summary

    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([{
      emailAddress: "b@b.com",
      name: "b",
      phone: "222222222222"
    }]);
    await client.deleteContacts();
    summary

    Deletes all of the certificate contacts

    Parameters

    Returns Promise<CertificateContacts>

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.setIssuer("IssuerName", "Provider");
    await client.deleteIssuer("IssuerName");
    summary

    Deletes the specified certificate issuer.

    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);
    await client.createCertificate("MyCertificate", {
      issuerName: "Self",
      subjectName: "cn=MyCert"
    });
    const certificate = await client.getCertificate("MyCertificate");
    console.log(certificate);
    summary

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

    Parameters

    Returns Promise<KeyVaultCertificate>

getCertificateOperation

  • Gets the creation operation associated with a specified certificate. This operation requires the certificates/get permission.

    Example usage:

    const client = new CertificateClient(url, credentials);
    await client.createCertificate("MyCertificate", {
      issuerName: "Self",
      subjectName: "cn=MyCert"
    });
    const operation = await client.getCertificateOperation("MyCertificate");
    console.log(operation);
    summary

    Gets a certificate's operation

    Parameters

    Returns Promise<CertificateOperation>

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.createCertificate("MyCertificate", {
      issuerName: "Self",
      subjectName: "cn=MyCert"
    });
    const policy = await client.getCertificatePolicy("MyCertificate");
    console.log(policy);
    summary

    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);
    await client.createCertificate("MyCertificate", {
      issuerName: "Self",
      subjectName: "cn=MyCert"
    });
    const certificateWithPolicy = await client.getCertificate("MyCertificate");
    const certificate = await client.getCertificateVersion("MyCertificate", certificateWithPolicy.properties.version!);
    console.log(certificate);
    summary

    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([{
      emailAddress: "b@b.com",
      name: "b",
      phone: "222222222222"
    }]);
    const getResponse = await client.getContacts();
    console.log(getResponse.contactList!);
    summary

    Sets the certificate contacts.

    Parameters

    Returns Promise<CertificateContacts>

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);
    client.getDeletedCertificate("MyDeletedCertificate");
    summary

    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.setIssuer("IssuerName", "Provider");
    const certificateIssuer = await client.getIssuer("IssuerName");
    console.log(certificateIssuer);
    summary

    Gets he specified certificate issuer.

    Parameters

    • issuerName: string

      The name of the issuer.

    • Default value options: GetIssuerOptions = {}

    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);
    const certificateSecret = await secretClient.getSecret("MyCertificate");
    const base64EncodedCertificate = certificateSecret.value!;
    await client.importCertificate("MyCertificate", base64EncodedCertificate);
    summary

    Imports a certificate from a certificate's secret value

    Parameters

    • certificateName: string

      The name of the certificate

    • base64EncodedCertificate: string

      The base64 encoded certificate to import

    • Default value options: ImportCertificateOptions = {}

    Returns Promise<KeyVaultCertificate>

listCertificateVersions

  • 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 item of client.listCertificateVersions("MyCertificate")) {
      console.log(item.properties.version!);
    }
    summary

    List the versions of a certificate.

    Parameters

    Returns PagedAsyncIterableIterator<KeyVaultCertificate, KeyVaultCertificate[]>

listCertificates

  • 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 certificate of client.listCertificates()) {
      console.log(certificate);
    }
    // By pages
    for await (const page of client.listCertificates().byPage()) {
      for (const certificate of page) {
        console.log(certificate);
      }
    }
    summary

    List all versions of the specified certificate.

    Parameters

    Returns PagedAsyncIterableIterator<KeyVaultCertificate, KeyVaultCertificate[]>

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 certificate of client.listDeletedCertificates()) {
      console.log(certificate);
    }
    for await (const page of client.listDeletedCertificates().byPage()) {
      for (const certificate of page) {
        console.log(certificate);
      }
    }
    summary

    Lists deleted certificates

    Parameters

    Returns PagedAsyncIterableIterator<DeletedCertificate, DeletedCertificate[]>

listIssuers

  • 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.setIssuer("IssuerName", "Provider");
    // All in one call
    for await (const issuer of client.listIssuers()) {
      console.log(issuer);
    }
    // By pages
    for await (const page of client.listIssuers().byPage()) {
      for (const issuer of page) {
        console.log(issuer);
      }
    }
    summary

    List the certificate issuers.

    Parameters

    Returns PagedAsyncIterableIterator<CertificateIssuer, CertificateIssuer[]>

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.createCertificate("MyCertificate", {
      issuerName: "Unknown",
      subjectName: "cn=MyCert"
    });
    const { csr } = await client.getCertificateOperation(certificateName);
    const base64Csr = Buffer.from(csr!).toString("base64");
    const wrappedCsr = ["-----BEGIN CERTIFICATE REQUEST-----", base64Csr, "-----END CERTIFICATE REQUEST-----"].join("\n");
    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
    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(certificateName, [Buffer.from(base64Crt)]);
    summary

    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 = {}

    Returns Promise<KeyVaultCertificate>

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);
    await client.deleteCertificate("MyCertificate");
    // Deleting a certificate takes time, make sure to wait before purging it
    client.purgeDeletedCertificate("MyCertificate");
    summary

    Gets a deleted certificate

    Parameters

    Returns Promise<null>

recoverDeletedCertificate

  • Recovers the deleted certificate in the specified vault. This operation can only be performed on a soft-delete enabled vault. This operation requires the certificate/recover permission.

    Example usage:

    const client = new CertificateClient(url, credentials);
    await client.deleteCertificate("MyCertificate");
    // Deleting a certificate takes time, make sure to wait before recovering it
    await client.recoverDeletedCertificate("MyCertificate");
    summary

    Recovers a deleted cerificate

    Parameters

    Returns Promise<KeyVaultCertificate>

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.createCertificate("MyCertificate", {
      issuerName: "Self",
      subjectName: "cn=MyCert"
    });
    const backup = await client.backupCertificate("MyCertificate");
    await client.deleteCertificate("MyCertificate");
    // Some time is required before we're able to restore the certificate
    await client.restoreCertificateBackup(backup.value!);
    summary

    Restores a certificate from a backup

    Parameters

    Returns Promise<KeyVaultCertificate>

setContacts

  • setContacts(contacts: Contact[], options?: SetContactsOptions): Promise<CertificateContacts>
  • 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([{
      emailAddress: "b@b.com",
      name: "b",
      phone: "222222222222"
    }]);
    summary

    Sets the certificate contacts.

    Parameters

    Returns Promise<CertificateContacts>

setIssuer

  • The setIssuer 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.setIssuer("IssuerName", "Provider");
    summary

    Sets the specified certificate issuer.

    Parameters

    • issuerName: string

      The name of the issuer.

    • provider: string

      The issuer provider.

    • Default value options: SetIssuerOptions = {}

    Returns Promise<CertificateIssuer>

updateCertificate

  • 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.createCertificate("MyCertificate", {
      issuerName: "Self",
      subjectName: "cn=MyCert"
    });
    await client.updateCertificate("MyCertificate", "", {
      tags: {
        customTag: "value"
      }
    });
    summary

    Updates a certificate

    Parameters

    • certificateName: string

      The name of the ceritificate

    • version: string

      The version of the certificate to update

    • Default value options: UpdateCertificateOptions = {}

      The options, including what to update

    Returns Promise<KeyVaultCertificate>

updateCertificatePolicy

  • Set specified members in the certificate policy. Leave others as null. This operation requires the certificates/update permission.

    summary

    Gets a certificate's policy

    Parameters

    Returns Promise<CertificatePolicy>

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.setIssuer("IssuerName", "Provider");
    await client.updateIssuer("IssuerName", {
      provider: "Provider2"
    });
    summary

    Updates the specified certificate issuer.

    Parameters

    Returns Promise<CertificateIssuer>

Generated using TypeDoc