Admin SDK

Follow this guide to use Admin SDK in your Express-based Node.js server environment for admin operations.

Step 1: Installation

Add the SDK to your Express-based Node.js project:

NPM
Yarn
NPM
npm i --save @fortmatic/admin
Yarn
yarn add @fortmatic/admin

Step 2: Set up Your Fortmatic Auth Instance

If you don't have a Fortmatic app already, you will need to sign up or log into your Fortmatic Dashboard and create an app to get your secret API key.

Once you have a secret API key, you can create a Fortmatic instance.

const { Fortmatic } = require('@fortmatic/admin');
​
const fm = new Fortmatic('SECRET_API_KEY');

Step 3: Apply the Fortmatic Middleware to Your App

In your Express-based Node.js application:

const express = require('express');
const { Fortmatic } = require('@fortmatic/admin');
​
const app = express();
const port = 3101;
​
/* Fortmatic Admin SDK instance */
const fm = new Fortmatic('SECRET_API_KEY');
​
app.use('/apples', fm.middlewares.express);
​
app.listen(port, () => console.log(`Example app listening on port ${port}!`));

The middleware will throw a 401 HTTPRequest error if the provided accessToken in the Authorization header is invalid or expired.

Step 4: Verify User Identity!

See end-to-end authentication experience on how to set up Express middleware and interact with the APIs.

​Express middleware provided by the SDK is a recommended practice that you should be using to protect your routes. Once the Express middleware is applied, you can create something like:

app.get('/user/public_address', (req: any, res: any) => {
/* Ensures the authenticity of the request by validating user's DID token */
const DIDToken = req.headers.authorization.substring(7); // Strips "Bearer "
const userPublicAddress = fm.token.getPublicAddress(DIDToken);
/* Do stuff with userPublicAddress! */
});