Pular para o conteúdo principal

REST API

CloudHub's API has eight operations. The client libraries wrap them, but any HTTP client can call them directly; this page documents the wire format. The same API is described interactively, as OpenAPI, at cloudhub.lacunasoftware.com/swagger.

Conventions​

  • Base URL: https://cloudhub.lacunasoftware.com.
  • Authentication: every operation requires your API key in the X-Api-Key header. A request without it, or with an unknown key, gets HTTP 401 with an empty body.
  • JSON: request and response bodies are JSON, with camelCase property names.
  • Binary values (hashes, certificates, signatures) travel as base64 strings. The certificate and sign-hash operations return a bare JSON string, such as "MIIH…".
  • Enumerations travel as strings, such as "SingleSignature" or "CPF". The numeric values the 1.x clients send (1 for SingleSignature) are still accepted.
  • Timeouts: signing waits on the provider. Allow up to two minutes for sign-hash.
OperationPurpose
POST /api/sessionsCreate a session at every provider that holds a certificate for the signer
POST /api/sessions/services/{name}Create a session at one provider
GET /api/sessions/servicesDiscover providers without creating a session
GET /api/sessions/services/{name}/availabilityAsk one provider whether it holds a certificate
GET /api/sessions/certificateRead the session's certificate
GET /api/v2/sessions/certificateRead the session's certificate, with its alias and provider
POST /api/sessions/sign-hashSign a hash with the session's certificate
GET /api/sessions/custom-stateRead back the customState given when the session was created

Sessions​

POST /api/sessions​

Creates a session. With an identifier, CloudHub runs discovery and returns only the providers that hold a certificate for it; without one, it returns every provider.

Body fieldTypeRequiredDescription
redirectUristringYesAbsolute URI CloudHub sends the user back to, with session appended. Must be registered for your key.
identifierstringNoThe signer's CPF or CNPJ, digits only.
identifierTypeCPF or CNPJNoHow to read identifier. When omitted, more than 11 digits means a CNPJ.
typesession typeNoWhat the user authorizes. Defaults to SingleSignature.
lifetimeInSecondsintegerNoThe session lifetime to ask the provider for. The provider may grant less.
customStatestringNoYour own data, kept with the session and returned by GET /api/sessions/custom-state.
discoverbooleanNoWhether to run discovery. Defaults to true when identifier is given. false returns every provider and passes identifier to each as a login hint. true requires identifier.
curl https://cloudhub.lacunasoftware.com/api/sessions \
-H "X-Api-Key: $CLOUDHUB_API_KEY" \
-H "Content-Type: application/json" \
-d '{"identifier": "12345678909", "redirectUri": "https://app.example.com/sign/complete", "type": "SingleSignature"}'

The response is a SessionModel:

{
"services": [
{
"serviceInfo": {
"serviceName": "BirdID",
"provider": "SOLUTI",
"endpoint": "https://api.birdid.com.br/",
"badgeUrl": "https://cdn.lacunasoftware.com/img/psc/birdid.png"
},
"authUrl": "https://api.birdid.com.br/oauth/authorize?client_id=…"
}
]
}

Errors: InvalidRedirectUri, UnauthorizedRedirectUri, IdentifierRequiredToDiscover; HTTP 400 when redirectUri is missing.

POST /api/sessions/services/{name}​

Creates a session at one provider, without discovery. Use it when the user has already chosen the provider. name is a serviceName as CloudHub returns it, such as BirdID.

The body takes the same fields as POST /api/sessions except identifierType. identifier, when given, is passed to the provider as a login hint; discover is ignored.

The response is a single TrustServiceAuthParametersModel: serviceInfo and authUrl.

Errors: ServiceNotFound (with details.name), InvalidRedirectUri, UnauthorizedRedirectUri.

Discovery​

GET /api/sessions/services​

Runs discovery without creating a session, and returns the providers that hold a certificate for the identifier as a list of TrustServiceInfoModel. There is no authUrl in this response.

Query parameterRequiredDescription
identifierYesThe CPF or CNPJ, digits only.
identifierTypeNoCPF (default) or CNPJ.
curl "https://cloudhub.lacunasoftware.com/api/sessions/services?identifier=12345678909" \
-H "X-Api-Key: $CLOUDHUB_API_KEY"

A provider that fails to answer is left out of the list.

GET /api/sessions/services/{name}/availability​

Asks one provider whether it holds a certificate for the identifier. Takes the same query parameters as GET /api/sessions/services.

{
"discoveryAvailable": true,
"certificateFound": true
}

discoveryAvailable is false when the provider could not answer; certificateFound is then null.

Errors: ServiceNotFound (with details.name).

Using a session​

These operations take the session value your redirect URI received. They fail with SessionInvalidOrAlreadyUsed when CloudHub doesn't know the session or the provider no longer accepts it. The certificate and sign-hash operations also fail with SessionExpired once the session's lifetime is over.

GET /api/sessions/certificate​

Returns the session's certificate, DER-encoded and then base64-encoded, as a JSON string. When the provider holds several certificates for the user, CloudHub picks the one that is currently valid and most recently issued.

curl "https://cloudhub.lacunasoftware.com/api/sessions/certificate?session=9f2c…e81a" \
-H "X-Api-Key: $CLOUDHUB_API_KEY"
"MIIHGjCCBQKgAwIBAgI…"

GET /api/v2/sessions/certificate​

Returns the same certificate as a CertificateModel, with its alias and the provider's service name:

{
"content": "MIIHGjCCBQKgAwIBAgI…",
"alias": "a5f1…",
"serviceName": "BirdID"
}

Pass alias to sign-hash as certificateAlias to sign with exactly this certificate.

POST /api/sessions/sign-hash​

Signs a hash with the user's key and returns the signature value, base64-encoded, as a JSON string.

Body fieldTypeRequiredDescription
sessionstringYesThe session value.
hashstringYesThe hash to sign, base64-encoded.
digestAlgorithmOidstringOne of these twoThe OID of the hash's digest algorithm, such as 2.16.840.1.101.3.4.2.1 for SHA-256. Takes precedence over digestAlgorithm.
digestAlgorithmstringOne of these twoThe algorithm's name, such as SHA-256.
certificateAliasstringNoThe certificate to sign with, from GET /api/v2/sessions/certificate. Defaults to the certificate GET /api/sessions/certificate returns.
curl https://cloudhub.lacunasoftware.com/api/sessions/sign-hash \
-H "X-Api-Key: $CLOUDHUB_API_KEY" \
-H "Content-Type: application/json" \
-d '{"session": "9f2c…e81a", "hash": "n4bQgYhMfWWaL+qgxVrQFaO/TxsrC4Is0V1sFbDwCgg=", "digestAlgorithmOid": "2.16.840.1.101.3.4.2.1"}'
"Qy1kZ3N0b3JlIHNpZ25hdHVyZSB2YWx1ZS4uLg…"

Errors: DigestAlgorithmNameOrOidIsRequired, InvalidDigestAlgorithm, SessionExpired, SessionInvalidOrAlreadyUsed.

GET /api/sessions/custom-state​

Returns the customState given when the session was created, as a JSON string, or null when there was none. The session query parameter is required.

Errors: SessionInvalidOrAlreadyUsed.

Models​

SessionModel​

FieldTypeDescription
servicesTrustServiceAuthParametersModel[]One entry per provider. Empty when none holds a certificate for the identifier.

TrustServiceAuthParametersModel​

FieldTypeDescription
serviceInfoTrustServiceInfoModelThe provider.
authUrlstringWhere to send the user to authorize at this provider.

TrustServiceInfoModel​

FieldTypeDescription
serviceNamestringThe provider's name in CloudHub, such as BirdID. It goes in the path of the single-provider operations.
providerstringThe company that operates the service, such as SOLUTI.
endpointstringThe provider's API address.
badgeUrlstringThe provider's logo. May be null.

CertificateModel​

FieldTypeDescription
contentstringThe certificate, DER-encoded, then base64-encoded.
aliasstringThe certificate's identifier at the provider.
serviceNamestringThe provider the certificate came from.

GetServiceAvailabilityResponse​

FieldTypeDescription
discoveryAvailablebooleanWhether the provider answered.
certificateFoundboolean or nullWhether it holds a certificate for the identifier. Null when it did not answer.

TrustServiceSessionTypes​

SingleSignature, MultiSignature, SignatureSession, AuthenticationSession. See Session types.

IdentifierTypes​

CPF, CNPJ.

Errors​

HTTP statusBodyMeaning
400A validation problem, listing the fieldsA required field is missing or malformed, such as redirectUri.
401EmptyThe X-Api-Key header is missing or the key is unknown.
422{ "code", "message", "details" }CloudHub refused the request. code is one of the codes below.
500A JSON string with a short code, such as "4F1A2B"An unexpected failure, often at the provider. Quote the code to Lacuna support.
{
"code": "UnauthorizedRedirectUri",
"message": "Unauthorized redirect URI",
"details": {
"redirectUri": "https://app.example.com/sign/complete"
}
}
CodeMeaningWhat to do
InvalidRedirectUriredirectUri is not an absolute URI.Send a full URI, with scheme and host.
UnauthorizedRedirectUriredirectUri is not registered for your key. details.redirectUri shows it.Ask Lacuna support to register it. See Redirect URIs.
IdentifierRequiredToDiscoverdiscover is true but there is no identifier.Send the identifier, or drop discover.
ServiceNotFoundNo provider has that name. details.name shows it.Use a serviceName CloudHub returned.
DigestAlgorithmNameOrOidIsRequiredsign-hash has neither digestAlgorithm nor digestAlgorithmOid.Send one of them.
InvalidDigestAlgorithmThe digest algorithm name or OID is not recognized.Send the OID your signature library reports.
SessionInvalidOrAlreadyUsedCloudHub doesn't know the session, or the provider no longer accepts it, for example because it was already used.Create a new session.
SessionExpiredThe session's lifetime is over. It can happen on the first use, when the user took long to authorize.Create a new session and send the user to the provider again.
View as Markdown