New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

koa-authority

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

koa-authority

Koa middleware for the authority module. Support v1 and v2.

  • 1.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

koa-authority

npm version

This module provides a minimalistic verification.

Installation

npm install koa-authority

Use

real example:==> hotchcms

example 1

use koa-router

var koaAuthority = require('koa-authority')
var Router = require('koa-router')

// 将要被校验的路由
var router = new Router()
router.post('/check', function(){})

// koaAuthority 提供更改权限的中间件 (middle)
function authority(routes) {
  reutrn koaAuthority({
    routes: routes,
    useKoaRouter: true,
    middleware: function(ctx, { routes }) {
      return new Promise(function(resolve, reject) {
        if (err) return reject('500')
        if (isAdmin) {
          resolve(routes) // or resolve(true)
        } else {
          resolve([])
        }
      })
    }
  })
}

// 使用
app.use(authority(router))

example 2

whitout koa-router

var koaAuthority = require('koa-authority')

// koaAuthority 提供更改权限的中间件 (middle)
function authority(routes) {
  reutrn koaAuthority({
    routes: routes,
    middleware: function(ctx, { routes }) {
      return new Promise(function(resolve, reject) {
        if (err) return reject('500')
        if (isAdmin) {
          resolve(routes) // or resolve(true)
        } else {
          resolve([])
        }
      })
    }
  })
}

// 使用
app.use(authority([
  {
    path: 'api/user',
    methods: ['POST'],
  },
  {
    path: 'api/content/xxx',
    methods: ['GET','HEAD', ...],
  },
  ...
]))

options

  • routes. koa-router Object or an Array like [{path:'',methods:['GET'...]}...]
  • useKoaRouter. Bollean, default false, use koa-router ?
  • middleware. Function, return a Promise.

Keywords

FAQs

Package last updated on 03 Jul 2018

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc