@usemirrorworld/server.utils
TypeScript icon, indicating that this package has built-in type declarations

1.3.1 • Public • Published

Approval Middleware

This middleware is used to authorize actions executed by users. This prevents external entities from performing actions on behalf of users. The way it works is that the user approves an action, which creates a token that is valid for 60 seconds on the Mirror World SSO.

This token should then be used to authenticate the user's action on the target service.

Installation

yarn add @mirrorworld/approval.middleware

Usage

import myRedisClient from "../path/to/redis"
import { ActionApprovalClient } from "@mirrorworld/approval.middleware"

const secret = process.env.MY_JWT_SECRET
const algorithm = process.env.MY_JWT_ALGORITHM

// 1. Create Action approval client
const approvalClient = new ActionApprovalClient({
  redisClient: myRedisClient,
  jwt: {
    secret: secret,
    algorithm: algorithm
  }
})

// 2. Create middleware instance
const approvalMiddleware = approvalClient.createValidateActionMiddleware("x-authorization-token")

// 3. Add middleware to request
router.post("/v1/transfer", approvalMiddleware, async (req, res, next) => {
  // Execute authorized action transfer
})

Readme

Keywords

Package Sidebar

Install

npm i @usemirrorworld/server.utils

Weekly Downloads

0

Version

1.3.1

License

MIT

Unpacked Size

6.34 kB

Total Files

10

Last publish

Collaborators

  • lile_mw
  • bilal.mirrorworld.fun
  • jozhe