credify-nodejs
v0.8.1
Published
Credify Node.js SDK
Downloads
8
Readme
Credify NodeJS
How to install
# yarn
$ yarn add credify-nodejs
# npm
$ npm install credify-nodejs
How to use
Initialization
const { Credify } = require("credify-nodejs");
const signingPrivateKey = "";
const apiKey = "";
const config = {
mode: "sandbox"
}
const credify = await Credify.create(signingPrivateKey, apiKey, config);
Auth - token introspection
This function validates an access token passed from Credify. You need to pass the token and a specific scope to test its validity.
const token = "eyJhbGciOiJSUzI1NiIsImtpZCI6InB1YmxpYzo4ZDA1NjJmNS0zMjI0LTQ1OGYtODBkZS01YjczNTdkMWUwMjIiLCJ0eXAiOiJKV1QifQ.eyJhdWQiOltdLCJjbGllbnRfaWQiOiI4ZjUzMGRmNi05OGFhLTQ4NDktYmNhZi1kNjI3MDU0MzUyNjYiLCJleHAiOjE2MTcxOTA4MDUsImV4dCI6eyJlY29zeXN0ZW1faWQiOiI2MmZjNTcyNC0zNzUxLTQ3OTctYmU3OS02MDU2MzVmYTZjOTMifSwiaWF0IjoxNjE2NTg2MDA1LCJpc3MiOiJodHRwczovL2Rldi1vaWRjLWNvcmUuY3JlZGlmeS5vbmUvIiwianRpIjoiNzM5ZjY0MTQtY2I1MS00YmM5LTg5NzUtYjQ3Nzc0MWNiODBjIiwibmJmIjoxNjE2NTg2MDA1LCJzY3AiOlsib3JnYW5pemF0aW9uIiwib2lkY19jbGllbnQiLCJjbGFpbV9wcm92aWRlciJdLCJzdWIiOiI4ZjUzMGRmNi05OGFhLTQ4NDktYmNhZi1kNjI3MDU0MzUyNjYifQ.PODoedbtpiZ2Uwe5XNRbQTdMY6C4cSQVXqxlt0yaLJqNkjo6dYLPp6GvcbJmCfMCJAkTXK13_Il7Ojl4jkY9K2fJwsqdTpsKbw5A4HPl4snhBMBkUGBMud2DmAYRo7N_DLUX0YEAaQ91OKxlM7ddAcANbkx8M9MTgXNxN3UDBZKL8KaGiN7Szm1gKXqaaRxM0_pl96xxktpsbLO5uYKIlpzPp_4h5N-TAkChK9BLnXUjQRccphmtMFeUTf9br7kVyFKgewDWsyF_UAv7gegf7qY4TPYJb3WNmllnrVGglhSVug2xCczn90a_EyLscG2b7KwHobRrgxowtb-jcHfHuu7OHQG6LU75YyoXiiNzg6qVh4VDQJpiC3Z7rkQQaL9_JHXtq5sHPh7Y7TmozeIQhvaG93vXJXePEfGyqS2wXs_XYlSAtjZJ3ALo7qdbfbWO94EUyPg_hGIU3t3LYn1r8VUbVTNpjkfYbQnfnoZMBhuZ2lPcyNuXtdO73470RX2vKbU_eKo_jEPIVScOtnYlGOLnLyymTLVKgd_PrKckOycjqB-2yQ0o4fX3puSNvpHw4mrcPDOb0G7g35JL2tDyRCU7Arh22VEE6XclkPkQbbdvRImxXplH9grBhxN4t7DVM-LtYDNMW_RJWlOKcdDQJQgNbHPJCsZBby2FUp84Pvw";
const scope = "organization";
credify.auth.introspectToken(token, scope).then((isValid) => console.log(isValid));
Create a new account
This function generates a new user with a provided profile and password on the Credify system. The output is a new user's ID.
const profile = {
name: {
first_name: "John",
last_name: "Kane"
},
emails: [
{
email: "[email protected]"
}
],
phones: [
{
phone_number: "38123456789",
country_code: "+84"
}
]
};
const password = "Aa12345678!";
credify.entity.create(profile, password).then((id) => {
console.log(id);
});
Push a custom claim
This records claim tokens into a blockchain. The claim tokens will be generated out of provided claim values.
const organizationId = "";
const entityId = "";
const claims = {
"your-scope-name-1": {
"your-claim-name-1": "this-entity-claim-value",
"your-claim-name-2": "this-entity-claim-value",
},
"your-scope-name-2": {
"your-claim-name-3": "this-entity-claim-value",
"your-claim-name-4": "this-entity-claim-value",
}
}
credify.claims.push(organizationId, entityId, claims).then((res) => {
console.log(res);
});
Encrypt claims
This encrypts claim values with a passed encryption public key.
const claims = {
"your-scope-name-1": {
"your-claim-name-1": "this-entity-claim-value",
"your-claim-name-2": "this-entity-claim-value",
},
"your-scope-name-2": {
"your-claim-name-3": "this-entity-claim-value",
"your-claim-name-4": "this-entity-claim-value",
}
}
const encryptionPublicKey = "";
credify.claims.encrypt(claims, encryptionPublicKey).then((res) => {
console.log(res);
});
Get offers
This retrieves filtered offers list.
credify.offer.getList("123").then((res) => {
console.log(res);
});
Kicks off OIDC
This generates an ephemeral encryption key to secure an OIDC flow.
const organizationId = "";
const redirectUrl = "";
const scopes = ["openid", "phone", "email"];
const options = {
userId: "",
offerCode: "",
}
credify.oidc.initiateOIDC(organizationId, redirectUrl, scopes, options).then((res) => {
console.log(`OIDC URL >>> ${res.oidcUrl}`);
console.log(`Private key >>> ${res.privateKey}`);
});
GET userinfo
This manages OpenID Connect userinfo API. This needs an ephemeral private key that is generated in the above step, and returns decrypted user information. Note that private key
needs to be base64 URL encoded string value.
const accessToken = "";
const privateKeyInBase64Url = "";
credify.oidc.userinfo(accessToken, privateKeyInBase64Url).then((userinfo) => {
console.log(userinfo);
});