Pular para o conteúdo principal

Integration guide - Amplia

Your system can create certificate orders and issue certificates through Amplia's REST API, while operators manage CAs, templates and orders on the dashboard. This guide covers the API calls; for a one-page summary, see the Amplia quick reference.

Before you start​

You need three values:

  • API key: every request sends your application's API key in the X-Api-Key header, in the form yourapp|xxxx…. To get one, create an application and an API key on the Amplia dashboard.
  • Endpoint: the address of the Amplia instance, prefixed to every relative URL of the API. Lacuna's cloud instance is https://amplia.lacunasoftware.com/, the default in the samples; with an on-premises instance, use the dashboard domain you chose. TODO(docs): no separate sandbox or test endpoint is documented.
  • CA id: the id of the CA that issues the certificates, sent as caId when you create an order. The samples keep it in their configuration next to the API key; the attribute certificate sample uses a second CA, since attribute certificates need a CA set up for them. The samples' comments add that an application can have a default CA, in which case caId can be left out. TODO(docs): where a default CA is set for an application.

The API observes the Accept-Language header (en-US or pt-BR), which also sets the language of the issue links it returns; error messages are not affected by it.

Create an application and an API key​

Your system calls the API as an application of an Amplia subscription, with a role that decides what it can do:

  1. Sign in to the Amplia dashboard and click Applications on the left menu, then Add.
  2. Fill out a name, select the subscription on which the certificates are issued and mark the application's role (see below), then click Create.
  3. Click Keys, then Add. Fill out a description and an expiration, then click Create.
  4. Copy the API key: it cannot be retrieved later.
RoleCreate orders, have Amplia email or text the issue link, revokeGet the issue link or QR code, issue certificatesWebhook settings
WorkerYesYesNo
Registration AgentYesNoNo
Manager, AdminYesYesYes

A system that runs the whole flow needs Worker, the role that Amplia Reg also uses. A Registration Agent application can create orders and send the holder the issue link by email or SMS, but cannot read the link or issue the certificate itself.

Client libraries​

Any HTTP client can call the API, whose OpenAPI description is at https://docs.lacunasoftware.com/openapi/amplia.json. Lacuna publishes client libraries, which the samples use:

LanguagePackageRegistry
.NETLacuna.Amplia.ClientNuGet
Javacom.lacunasoftware.amplia:amplia-clientMaven Central
Node.jsamplia-clientnpm
PHPlacuna/amplia-clientPackagist
Pythonamplia-clientPyPI

The client majors don't follow Amplia's version: every endpoint that the 1.x clients below call is served by Amplia 5.0.1. The .NET client is described below.

The Java (1.2.1), Node.js (1.3.3), PHP (1.3.0) and Python (1.0.0) clients wrap these calls:

OperationNode.js, Java, PHPPythonEndpoint
Create an ordercreateOrdercreate_orderPOST /api/orders/{format}
Get an ordergetOrderget_orderGET /api/v2/orders/{id} (Java: GET /api/orders/{format}/{id})
Get the issue linkgetOrderIssueLinkget_order_issue_linkGET /api/orders/{id}/issue-link
Issue from a CSRissueCertificateissue_certificatePOST /api/v2/certificates
Issue a PKCS #12 fileissuePkcs12Certificate (Node.js only)POST /api/certificates/pkcs12
Revoke a certificaterevokeCertificaterevoke_certificateDELETE /api/certificates/{id}

None of the four sends the issue link by email or SMS or reads its QR code: call those endpoints directly, or use the .NET client (see Other ways to deliver the issue link).

Each sample creates the client from the endpoint and the API key:

const { AmpliaClient } = require("amplia-client");

static getAmpliaClient() {
let CONFIG = Config.getInstance().get('amplia');
let key = CONFIG['apiKey'];
let endpoint = CONFIG['endpoint'];
return new AmpliaClient({
endpoint: endpoint,
apiKey: key
});
}

.NET client​

Lacuna.Amplia.Client 5.0.0 targets .NET Standard 2.0 and is built from the same source as Amplia 5.0.1. Get an IAmpliaService from dependency injection, after services.AddAmplia(...), or from AmpliaServicesFactory.GetService(endpoint, apiKey); the AmpliaClient class still works, but is marked [Obsolete].

using Lacuna.Amplia.Api;
using Lacuna.Amplia.Api.CertificateFormatting;
using Lacuna.Amplia.Api.Orders;
using Lacuna.Amplia.Client;

IAmpliaService amplia = AmpliaServicesFactory.GetService("https://amplia.lacunasoftware.com/", apiKey);

var order = await amplia.CreateOrderAsync(new CreateOrderRequest2<PkiBrazilCertificateParameters> {
CAId = caId,
Kind = CertificateKinds.PublicKey,
ValidityEnd = DateTimeOffset.Now.AddYears(2),
Parameters = new PkiBrazilCertificateParameters {
Name = subjectName,
Cpf = cpf,
PhoneNumber = phoneNumber,
},
});
string issueLink = await amplia.GetOrderIssueLinkAsync(order.Id, returnUrl);

In ASP.NET Core, services.AddAmplia(o => { o.Endpoint = …; o.ApiKey = …; }), or services.AddAmplia().Configure(configuration.GetSection("Amplia")), registers IAmpliaService; AmpliaOptions also has Timeout, Culture (sent as Accept-Language) and DefaultSubscriptionId.

Operation.NET methodEndpoint
Create an orderCreateOrderAsyncPOST /api/orders/{format} (POST /api/v2/orders for the non-generic request)
Get an orderGetOrderAsyncGET /api/v2/orders/{id}
Get the issue linkGetOrderIssueLinkAsyncGET /api/orders/{id}/issue-link
Email or text the issue linkSendIssueEmailAsync, SendIssueSmsAsyncPOST /api/orders/{id}/send-issue-email-request, POST /api/v2/orders/{id}/send-issue-sms-request
Get the QR codeGetOrderIssueQRCodeDataAsync, GetOrderIssueQRCodeImageAsyncGET /api/orders/{id}/issue-qrcode-data, issue-qrcode-image
Issue from a CSRIssueCertificateAsyncPOST /api/v2/certificates
Issue a PKCS #12 fileIssuePkcs12CertificateAsyncPOST /api/certificates/pkcs12
Get a certificateGetCertificateAsyncGET /api/v2/certificates/{id}
Revoke a certificateRevokeCertificateAsyncDELETE /api/certificates/{id}

API errors (422) throw AmpliaException, whose Code is the error code, or OrderLockedException when the code is OrderLocked.

How issuance works​

Every certificate starts with an order on a CA, which holds the holder's data and the certificate's validity. The order is then fulfilled, issuing one certificate, in one of these ways:

Where the key pair is madeHow you issuePage
On the holder's computer, by Amplia's issue pageSend the holder an issue linkIssue on the holder's machine
On your server, or in the user's browser with Web PKISend Amplia a CSRIssue from a CSR
By Amplia, which returns it in a password-protected fileAsk for a PKCS #12 (.pfx)Issue a PKCS #12 file
No key pair: the certificate attests an attribute of the holderIssue without a CSRAttribute certificates

Start with Create certificate orders. Then:

Webhook​

Amplia can notify your system whenever a certificate is issued: the notification body is a WebhookEventModel whose type is OrderCertificateIssued, with the order and, once issued, the certificate.

The webhook belongs to the subscription. A user with the Admin or Manager role sets it on the dashboard, under Settings > Webhook configuration:

  • Enable webhook, the URL that Amplia posts the notification to, and the Authentication type, which decides the header Amplia sends with each notification:

    Authentication typeHeader
    NoAuthNo authentication header
    BearerAuthorization: Bearer <token>
    ApiKeyX-Api-Key: <key>
    CustomAuthorizationHeaderAuthorization: <scheme> <value>
    BasicAuthorization: Basic <value> (see the caution below)
  • The Recent calls tab lists the notifications sent, with the status code and, for failed calls, the response.

Amplia sends a POST with a JSON body and counts any 2xx answer as delivered. The JSON keeps the property names of Amplia's models, in PascalCase (Type, Order, Certificate), with enums as names:

{
"Type": "OrderCertificateIssued",
"Order": { "Id": "…", "Status": "Issued", "CertificateId": "…" },
"Certificate": { "Id": "…" }
}
Basic authentication

With Basic, the dashboard encodes the user name and the password separately and joins them with a colon, base64(user):base64(password), instead of the standard base64(user:password). A standard Basic authentication handler rejects that value, so prefer Bearer, ApiKey or CustomAuthorizationHeader.

TODO(docs): whether and how often Amplia retries a failed notification.

See also​

View as Markdown