Security News
CISA Brings KEV Data to GitHub
CISA's KEV data is now on GitHub, offering easier access, API integration, commit history tracking, and automated updates for security teams and researchers.
This is the Javascript client for interacting with the PDK auth and panel APIs.
This may be helpful as a guide even if you don't use Javascript. The APIs use a REST style HTTP JSON interface that is simple to use from nearly any lanugage with an intelligent HTTP library.
NB: This client is still in beta and the interface may change in the future. Once 1.0 is pushed we will begin supporting a stable semver API.
The client build targets node >= 8 in order to support async/await functionality.
There are plans to create a browser compatible build of the client. In this case the Promise async interface would be used unless the host application is being transpiled.
The src/
directory contains the client library. In src/examples/
find examples for using the API for various tasks.
Most of the operations with this client involve network or disk operations.
Async operations are simply handled by using the javacript await
keyword.
import { authenticate } from 'pdk';
const tokenset = await authenticate(client_id, client_secret);
Once calling authenticate
to get an authentication context, use makesession
to create a session with the auth API.
This session will automatically manage the authentication token lifetime, using a refresh token if available, otherwise it runs the browser authentication flow again.
See the auth API documentation for operations and data types available here.
import { authenticate, makeSession } from 'pdk';
try {
const session = await makeSession(await authenticate(client_id, client_secret));
} catch(err) {
console.log(`Error authenticating: ${err.msg}`);
}
This session
function is a thin facade around got that allows easily making authenticated requests, options are passed on to got.
// `mine` is the ID for the authenticated user's default organization
let response = await session('ous/mine');
The response
is a Javascript object representing the response body documented in the API docs.
Once an authenticated session is established with the auth API, it can be used to create an authenticated session to a specific panel.
This session will automatically manage the panel authentication token lifetime.
See the panel API documentation for operations and data types available here.
Note: The term panel in the documentation is synonymous with the PDK cloud node hardware.
import { authenticate, makeSession, makePanelSession } from 'pdk';
// Authenticate and create a session with the auth API
const session = await makeSession(await authenticate(client_id, client_secret));
// Get a panel document from the auth API
const panel = await session('panels/1070BBB');
// Create an authenticated session with the panel
const panelsession = await makePanelSession(session, panel);
// Retrieve an entity from the panel API
const me = await panelsession('people/123');
The panel API supports a real-time socket.io event and command stream. This stream allows the reception of events from the system (credential scans, door open/close, etc), and injection of commands (door open/close, enable DND, etc) into the system.
See the Stream Oriented API section of the panel API documentation for information on available events and commands.
import { randomBytes } from 'crypto';
const stream = panelsession.createEventStream();
// Print events to the console as they come in
stream.on('liveEvent', event => console.log(`Event: ${JSON.stringify(event)}`));
// Send a door open/close command to door #6
const id = randomBytes(64).toString('hex'); // Random msg ID
stream.emit('command', {
topic: 'door.try.open',
body: { doorId: 6 },
id
});
Applications that support the client credentials authentication flow can use the authenticateclient
, in the same way as the authenticate
method.
import { authenticateclient, makesession } from 'pdk';
// Authenticate and create a session with the auth API
const session = await makesession(await authenticateclient(client_id, client_secret));
const tokenset = function authenticate ( // This launches a user's browser and retrieves an authentication token clientId: The oAuth client id issued for use, clientSecret: The oAuth client secret issued, issuer (optional): The OpenID Connect provider to auth against, );
const session = function makesession (
// This creates a session that allows making requests to the API endpoints
tokenSet: The token_id
from the tokenset retrieved from authenticate
,
};
If you want to use the client without messing with the guts, just add this module as an npm dependency and import pdk from 'pdk';
(or const pdk = require('pdk');
if you're not using ES6 modules).
This project uses babel to translate a couple features that haven't hitten node yet, mainly async
/await
and ES6 modules.
If changes are made to src/
then npm run build
needs to be run to create the output in lib/
that can be run by node.
FAQs
ProdataKey pdk.io API Client Library for Javascript
We found that pdk-client demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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.
Security News
CISA's KEV data is now on GitHub, offering easier access, API integration, commit history tracking, and automated updates for security teams and researchers.
Security News
Opengrep forks Semgrep to preserve open source SAST in response to controversial licensing changes.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.