Product
Socket Now Supports uv.lock Files
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
@onfido/api
Advanced tools
The official Node.js library for integrating with the Onfido API.
Documentation can be found at https://documentation.onfido.com.
This library is only for use on the backend, as it uses Onfido API tokens which must be kept secret. If you do need to collect applicant data in the frontend of your application, we recommend that you use the Onfido SDKs: iOS, Android, Web, and React Native.
This version uses Onfido API v3.6. Refer to our API versioning guide for details of which client library versions use which versions of the API.
npm install @onfido/api
yarn add @onfido/api
Require the package:
const {
DefaultApi,
Configuration,
WebhookEventVerifier
} = require("@onfido/api");
const { isAxiosError } = require("axios");
For TypeScript users, types are available as well:
import {
DefaultApi,
Configuration,
Region,
WebhookEventVerifier
} from "@onfido/api";
import { isAxiosError } from "axios";
Configure with your API token and region:
const onfido = new DefaultApi(
new Configuration({
apiToken: process.env.ONFIDO_API_TOKEN,
region: Region.EU, // Supports Region.EU, Region.US and Region.CA
baseOptions: { timeout: 60_000 } // Additional Axios options (timeout, etc.)
})
);
NB: by default, timeout is set to 30 seconds.
Using async
/await
(in an async function
):
(async () => {
try {
const applicant = await onfido.createApplicant({
first_name: "Jane",
last_name: "Doe",
location: {
ip_address: "127.0.0.1",
country_of_residence: "GBR"
}
});
// ...
} catch (error) {
if (isAxiosError(error)) {
console.log(`status code: ${error.response?.status}`);
const error_details = error.response?.data.error;
// An error response was received from the Onfido API, extra info is available.
if (error_details) {
console.log(error_details.message);
console.log(error_details.type);
} else {
// No response was received for some reason e.g. a network error.
console.log(error.message);
}
} else {
console.log(error.message);
}
}
})();
Please find more information regarding Axios errors in library documentation.
Using promises:
onfido
.createApplicant({
first_name: "Jane",
last_name: "Doe",
location: {
ip_address: "127.0.0.1",
country_of_residence: "GBR"
}
})
.then(applicant =>
onfido.createCheck({
applicant_id: applicant.data.id,
report_names: ["identity_enhanced"]
})
)
.then(check =>
// Handle successfully created check.
)
.catch(error => {
// Handle error.
});
File downloads, for example onfido.downloadDocument(documentId, {responseType: 'arraybuffer'})
, will return an instance of a specific object for this endpoint.
These objects will have a content type, e.g. image/png
.
download.headers["content-type"];
Call slice()
to get a Blob
of the download:
const blob = download.data.slice();
For some common types of streams, like instances of fs.ReadStream
, you can provide the stream directly:
onfido.uploadDocument(
"passport",
"<APPLICANT_ID>",
fs.createReadStream("path/to/passport.png")
);
Webhook events payload needs to be verified before it can be accessed. Library allows to easily decode the payload and verify its signature before returning it as an object for user convenience:
(async () => {
try {
const token = process.env.ONFIDO_WEBHOOK_SECRET_TOKEN;
const verifier = new WebhookEventVerifier(token);
const signature = "a0...760e";
const event = verifier.readPayload(`{"payload":{"r...3"}}`, signature);
} catch (e) {
if (e instanceof OnfidoInvalidSignatureError) {
// Invalid webhook signature
}
}
})();
Except for accessing Task object's outputs, retain from using the square bracket syntax (i.e. []
) to access not defined properties to avoid breaking changes when these fields will appear.
This library is automatically generated using OpenAPI Generator (version: 7.6.0); therefore all the contributions, except tests files, should target Onfido OpenAPI specification repository instead of this repository.
For contributions to the tests instead, please follow the steps below:
git checkout -b my-new-feature
)git commit -am 'Add some feature'
)git push origin my-new-feature
)Semantic Versioning policy is used for library versioning, following guidelines and limitations below:
More documentation and code examples can be found at https://documentation.onfido.com.
Should you encounter any technical issues during integration, please contact Onfido's Customer Support team via the Customer Experience Portal which also includes support documentation.
v3.1.0 24th June 2024
FAQs
Node.js library for the Onfido API
The npm package @onfido/api receives a total of 12,258 weekly downloads. As such, @onfido/api popularity was classified as popular.
We found that @onfido/api demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
Research
Security News
Socket researchers have discovered multiple malicious npm packages targeting Solana private keys, abusing Gmail to exfiltrate the data and drain Solana wallets.
Security News
PEP 770 proposes adding SBOM support to Python packages to improve transparency and catch hidden non-Python dependencies that security tools often miss.