
Security News
Meet Socket at Black Hat Europe and BSides London 2025
Socket is heading to London! Stop by our booth or schedule a meeting to see what we've been working on.
用于考拉用户登陆校验和简单的权限控制
只适配 Koa2
##Getting Start
const auth = require('klg-auth')
app.use(auth.validate({
errHandle: async function (ctx) {
console.log('授权错误')
// 检测到用户没有登陆时会触发此 handle
// 跳转到SSO的登陆页面或者 返回url给前端跳转
ctx.body = {
code: 1,
message: '授权错误',
url: 'http://'
}
ctx.status = 200
},
cookieDomain: 'localhost' // 更新cookie domain
cookieMaxAge: 30 * 60 * 1000 // 更新cookie时间(30分钟)
}))
import { allow } from 'klg-auth'
router.get('/user/:username', allow('管理员', '开发'), UserController.getUserByName)
allow('管理员', '开发') 表示此 url 只允许 管理员 和 开发 角色访问 非以上角色访问会默认返回(后面会开放自定义处理函数): 200
{ code: 1, message: '该用户没有权限执行此操作' }
ban('实习') 表示此 url 不允许 实习 角色访问 非以上角色访问会默认返回:200
{ code: 1, message: '该用户没有权限执行此操作' }
FAQs
We found that klg-auth demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

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.

Security News
Socket is heading to London! Stop by our booth or schedule a meeting to see what we've been working on.

Security News
OWASP’s 2025 Top 10 introduces Software Supply Chain Failures as a new category, reflecting rising concern over dependency and build system risks.

Research
/Security News
Socket researchers discovered nine malicious NuGet packages that use time-delayed payloads to crash applications and corrupt industrial control systems.