KNoT Cloud authenticator service JavaScript library.
npm install --save @cesarbr/knot-cloud-sdk-js-authenticator
KNoTCloudAuthenticator
connects to <protocol>://<hostname>:<port> using email and password as credentials. Replace this address with your authenticator instance and the credentials with valid ones.
const KNoTCloudAuthenticator = require("@cesarbr/knot-cloud-sdk-js-authenticator");
const client = new KNoTCloudAuthenticator({
protocol: "https",
hostname: "api.knot.cloud",
port: 443,
});
async function main() {
try {
const user = await client.createUser(
"[email protected]",
"strong-password"
);
console.log(user);
const token = client.createToken("[email protected]", "strong-password");
console.log(token);
} catch (err) {
console.error(err);
}
}
main();
Create a client object that will connect to a KNoT Cloud protocol authenticator instance.
config
Object JSON object with request details.protocol
String (Optional) Either'http'
or'https'
. Default:'https'
.hostname
String KNoT Cloud authenticator instance hostname. Default'api.knot.cloud'
.port
Number (Optional) KNoT Cloud authenticator instance port. Default: 80/443.
const KNoTCloudAuthenticator = require("@cesarbr/knot-cloud-sdk-js-authenticator");
const client = new KNoTCloudAuthenticator({
protocol: "https",
hostname: "api.knot.cloud",
port: 443,
});
Creates a new user.
email
String User email.password
String User password in plain text.
user
Object JSON object containing the created user's credentials.
const KNoTCloudAuthenticator = require("@cesarbr/knot-cloud-sdk-js-authenticator");
const client = new KNoTCloudAuthenticator({
protocol: "https",
hostname: "api.knot.cloud",
port: 443,
});
async function main() {
try {
const user = await client.createUser(
"[email protected]",
"strong-password"
);
} catch (err) {
console.error(err);
}
}
main();
// {
// email: '[email protected]',
// password: 'strong-password',
// }
Generates a new access token for the user.
email
String User email.password
String User password, in plain text.
token
Object JSON object containing the user's new access token.
const KNoTCloudAuthenticator = require("@cesarbr/knot-cloud-sdk-js-authenticator");
const client = new KNoTCloudAuthenticator({
protocol: "https",
hostname: "api.knot.cloud",
port: 443,
});
async function main() {
try {
const token = await client.createToken(
"[email protected]",
"strong-password"
);
console.log(token);
} catch (err) {
console.error(err);
}
}
main();
// {
// token: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1ODcxMjkzNzIsImlhdCI6MTU4NzA5MzM3MiwiaXNzIjoibWFpbmZsdXguYXV0aG4iLCJzdWIiOiJkYWRhdmR2YkBrbm90LmNvbSIsInR5cGUiOjB9._lbRa2fzI_CvEorbEACVAf2UnHvkiCOORY55wCWUGAs'
// }
Generates a new session ID for the user, which will be used to receive thing's data.
token
String User or application token.
session
Object JSON object containing the user's new session ID.id
String user session ID.
const KNoTCloudAuthenticator = require("@cesarbr/knot-cloud-sdk-js-authenticator");
const client = new KNoTCloudAuthenticator({
protocol: "https",
hostname: "api.knot.cloud",
port: 443,
});
async function main() {
try {
const { token } = await client.createToken(
"[email protected]",
"strong-password"
);
const session = await client.createSession(token);
console.log(session);
} catch (err) {
console.error(err);
}
}
main();
// {
// "id": "1t4izjcdHSYxfEZ9DUWMNewtlpR"
// }