Skip to content

3. Middleware

leonardo Rico edited this page Jan 21, 2018 · 4 revisions

The middleware is in: /src/auth/services/mw.js

Params

  • req: request
  • authOrSecDef: authOrSecDef
  • token: Token from header Authorization
  • cb: callback

Lines of interest

x-security-scopes

Obtain the required roles from a Router

let requiredRoles = req.swagger.operation["x-security-scopes"];
// -> ['admin','user']

Verify Token

Example of extracting token , see session

// decode token, this includes the dataToken
let session = await r.verify(token);

// decode token, this includes the dataToken and dataSession stored in redis
let session = await r.verify(token, true); 

Verify Roles

Role Comparison, see role-calc

// Verify Roles
has(requiredRoles, _user.roles)
Clone this wiki locally