Setup

Connect your application or service with DFend.

Using our API and/or partner connections, you will:

  • Create an Identity for each user of your application or service.

  • Configure a data source to send us Signals.

    • A data source can be your application or service, or partner integration.

  • Configure a webhook to handle Events. When we detect suspicious behavior or handle user responses, we will send Events to your webhook.

Identities can be created on the fly if you include secondary Identifiers in a Signal. We will only trust this data if it is sent from a server environment using your secret API key.

Connections

You can leverage our integration with Google Workspace to protect your internal team. Upon setup, DFend will ingest and analyze signals from Google Workspace audit logs.

Found in Dashboard under Setup > Connections.

Quick Start

Node.js

Set up a webhook

For example, at yourdomain.com using Express, accepting the POST method. You would additionally need to configure this to accept HTTPS requests. We recommend using a cloud function that provides this for you automatically.

import express from 'express';
import cors from 'cors';

const app = express();
app.use(cors());
app.use(express.json());

app.post('/', (req, res) => {
  const { event } = req.body;
  console.log('Event received from DFend:', event);
  // TODO: Switch on `event.type` and handle the event.
  res.status(200).json({ message: 'ok' });
});

app.listen(process.env.PORT, () =>
  console.log(`DFend webhook listening on port ${process.env.PORT}!`),
);

Add the URL and method of your webhook in Dashboard under Setup > Routing.

Try the DFend API

Server code

The following example uses the DFend Boilerplate for Node.js.

// Import the DFend Boilerplate for Node.js.
import { identity, signal } from 'dfend.js';

try {
  // Create an Identity.
  const { id, created, merged } = await identity.post({
    userId: 'PU4ME2B68N8K6xz0Ku0BQ',
    name: 'Jane Doe',
    email: 'jane@yourdomain.com',
    phone: '+15435551234',
    merge: true,
    metadata: {
      test: true
    }
  });
  console.log('[DFend] identity created:', id);
  // You can now send signals to DFend with the Identity ID or user ID.
} catch (e) {
  console.error(e);
}

Client code (web browser)

<!DOCTYPE html>
<html>
  <head>
    <title>DFend Test</title>
    <script src="https://js.dfend.app/sdk/v0/client.js"></script>
    <script>
      const dfend = DFend('<Publishable API Key>');
      const userId = 'PU4ME2B68N8K6xz0Ku0BQ';
      (async () => {
        const data = await dfend.push({
          type: 'PageLoad',
          identifiers: {
            userId
          }
        });
        // View in the browser console.
        console.log('[DFend] signal push response:', data);
      })();
    </script>
  </head>
  <body>
  </body>
</html>

Last updated