@nocobase/plugin-auth
Advanced tools
Comparing version 0.17.0-alpha.4 to 0.17.0-alpha.5
module.exports = { | ||
"@nocobase/client": "0.17.0-alpha.4", | ||
"@nocobase/client": "0.17.0-alpha.5", | ||
"react": "18.2.0", | ||
"react-router-dom": "6.14.1", | ||
"@nocobase/auth": "0.17.0-alpha.4", | ||
"@nocobase/database": "0.17.0-alpha.4", | ||
"@nocobase/server": "0.17.0-alpha.4", | ||
"@nocobase/auth": "0.17.0-alpha.5", | ||
"@nocobase/database": "0.17.0-alpha.5", | ||
"@nocobase/server": "0.17.0-alpha.5", | ||
"@nocobase/cache": "0.17.0-alpha.5", | ||
"antd": "5.8.6", | ||
@@ -13,3 +14,3 @@ "@formily/react": "2.2.27", | ||
"@ant-design/icons": "5.1.4", | ||
"@nocobase/actions": "0.17.0-alpha.4" | ||
"@nocobase/actions": "0.17.0-alpha.5" | ||
}; |
@@ -1,1 +0,1 @@ | ||
{"name":"cron","description":"Cron jobs for your node","version":"2.3.1","author":"Nick Campbell <nicholas.j.campbell@gmail.com> (https://github.com/ncb000gt)","bugs":{"url":"https://github.com/kelektiv/node-cron/issues"},"repository":{"type":"git","url":"https://github.com/kelektiv/node-cron.git"},"main":"lib/cron","scripts":{"lint":"eslint {lib,tests}/*.js","test":"jest --coverage","test:watch":"jest --watch --coverage"},"dependencies":{"luxon":"^3.2.1"},"devDependencies":{"chai":"~4.2.x","eslint":"~8.36.x","eslint-config-prettier":"^8.7.x","eslint-config-standard":"~17.0.x","eslint-plugin-import":"~2.27.x","eslint-plugin-jest":"~27.2.x","eslint-plugin-n":"~15.6.x","eslint-plugin-prettier":"~4.2.x","eslint-plugin-promise":"~6.1.x","jest":"~29.5.x","prettier":"~2.8.x","sinon":"^15.0.x"},"keywords":["cron","node cron","node-cron","schedule","scheduler","cronjob","cron job"],"license":"MIT","contributors":["Brandon der Blätter <https://interlucid.com/contact/> (https://github.com/intcreator)","Romain Beauxis <toots@rastageeks.org> (https://github.com/toots)","James Padolsey <> (https://github.com/jamespadolsey)","Finn Herpich <fh@three-heads.de> (https://github.com/ErrorProne)","Clifton Cunningham <clifton.cunningham@gmail.com> (https://github.com/cliftonc)","Eric Abouaf <eric.abouaf@gmail.com> (https://github.com/neyric)","humanchimp <morphcham@gmail.com> (https://github.com/humanchimp)","Craig Condon <craig@spiceapps.com> (https://github.com/spiceapps)","Dan Bear <daniel@hulu.com> (https://github.com/danhbear)","Vadim Baryshev <vadimbaryshev@gmail.com> (https://github.com/baryshev)","Leandro Ferrari <lfthomaz@gmail.com> (https://github.com/lfthomaz)","Gregg Zigler <greggzigler@gmail.com> (https://github.com/greggzigler)","Jordan Abderrachid <jabderrachid@gmail.com> (https://github.com/jordanabderrachid)","Masakazu Matsushita <matsukaz@gmail.com> (matsukaz)","Christopher Lunt <me@kirisu.co.uk> (https://github.com/kirisu)"],"jest":{"collectCoverage":true,"collectCoverageFrom":["lib/*.js"],"coverageThreshold":{"global":{"statements":80,"branches":80,"functions":70,"lines":80}}},"files":["lib","CHANGELOG.md","LICENSE","README.md"],"_lastModified":"2023-12-12T06:29:12.506Z"} | ||
{"name":"cron","description":"Cron jobs for your node","version":"2.3.1","author":"Nick Campbell <nicholas.j.campbell@gmail.com> (https://github.com/ncb000gt)","bugs":{"url":"https://github.com/kelektiv/node-cron/issues"},"repository":{"type":"git","url":"https://github.com/kelektiv/node-cron.git"},"main":"lib/cron","scripts":{"lint":"eslint {lib,tests}/*.js","test":"jest --coverage","test:watch":"jest --watch --coverage"},"dependencies":{"luxon":"^3.2.1"},"devDependencies":{"chai":"~4.2.x","eslint":"~8.36.x","eslint-config-prettier":"^8.7.x","eslint-config-standard":"~17.0.x","eslint-plugin-import":"~2.27.x","eslint-plugin-jest":"~27.2.x","eslint-plugin-n":"~15.6.x","eslint-plugin-prettier":"~4.2.x","eslint-plugin-promise":"~6.1.x","jest":"~29.5.x","prettier":"~2.8.x","sinon":"^15.0.x"},"keywords":["cron","node cron","node-cron","schedule","scheduler","cronjob","cron job"],"license":"MIT","contributors":["Brandon der Blätter <https://interlucid.com/contact/> (https://github.com/intcreator)","Romain Beauxis <toots@rastageeks.org> (https://github.com/toots)","James Padolsey <> (https://github.com/jamespadolsey)","Finn Herpich <fh@three-heads.de> (https://github.com/ErrorProne)","Clifton Cunningham <clifton.cunningham@gmail.com> (https://github.com/cliftonc)","Eric Abouaf <eric.abouaf@gmail.com> (https://github.com/neyric)","humanchimp <morphcham@gmail.com> (https://github.com/humanchimp)","Craig Condon <craig@spiceapps.com> (https://github.com/spiceapps)","Dan Bear <daniel@hulu.com> (https://github.com/danhbear)","Vadim Baryshev <vadimbaryshev@gmail.com> (https://github.com/baryshev)","Leandro Ferrari <lfthomaz@gmail.com> (https://github.com/lfthomaz)","Gregg Zigler <greggzigler@gmail.com> (https://github.com/greggzigler)","Jordan Abderrachid <jabderrachid@gmail.com> (https://github.com/jordanabderrachid)","Masakazu Matsushita <matsukaz@gmail.com> (matsukaz)","Christopher Lunt <me@kirisu.co.uk> (https://github.com/kirisu)"],"jest":{"collectCoverage":true,"collectCoverageFrom":["lib/*.js"],"coverageThreshold":{"global":{"statements":80,"branches":80,"functions":70,"lines":80}}},"files":["lib","CHANGELOG.md","LICENSE","README.md"],"_lastModified":"2023-12-12T15:14:36.703Z"} |
import { InstallOptions, Plugin } from '@nocobase/server'; | ||
import { Cache } from '@nocobase/cache'; | ||
export declare class AuthPlugin extends Plugin { | ||
cache: Cache; | ||
afterAdd(): void; | ||
@@ -4,0 +6,0 @@ beforeLoad(): Promise<void>; |
@@ -43,3 +43,5 @@ var __create = Object.create; | ||
var import_token_blacklist = require("./token-blacklist"); | ||
var import_storer = require("./storer"); | ||
class AuthPlugin extends import_server.Plugin { | ||
cache; | ||
afterAdd() { | ||
@@ -63,10 +65,12 @@ } | ||
}); | ||
this.app.authManager.setStorer({ | ||
get: async (name) => { | ||
const repo = this.db.getRepository("authenticators"); | ||
const authenticators = await repo.find({ filter: { enabled: true } }); | ||
const authenticator = authenticators.find((authenticator2) => authenticator2.name === name); | ||
return authenticator || authenticators[0]; | ||
} | ||
this.cache = await this.app.cacheManager.createCache({ | ||
name: "auth", | ||
prefix: "auth", | ||
store: "memory" | ||
}); | ||
const storer = new import_storer.Storer({ | ||
db: this.db, | ||
cache: this.cache | ||
}); | ||
this.app.authManager.setStorer(storer); | ||
if (!this.app.authManager.jwt.blacklist) { | ||
@@ -95,2 +99,10 @@ this.app.authManager.setTokenBlacklistService(new import_token_blacklist.TokenBlacklistService(this)); | ||
}); | ||
this.app.db.on("users.afterSave", async (user) => { | ||
const cache = this.app.cache; | ||
await cache.set(`auth:${user.id}`, user.toJSON()); | ||
}); | ||
this.app.db.on("users.afterDestroy", async (user) => { | ||
const cache = this.app.cache; | ||
await cache.del(`auth:${user.id}`); | ||
}); | ||
} | ||
@@ -97,0 +109,0 @@ async install(options) { |
@@ -5,2 +5,3 @@ import { ITokenBlacklistService } from '@nocobase/auth'; | ||
import AuthPlugin from './plugin'; | ||
import { BloomFilter } from '@nocobase/cache'; | ||
export declare class TokenBlacklistService implements ITokenBlacklistService { | ||
@@ -10,2 +11,4 @@ protected plugin: AuthPlugin; | ||
cronJob: CronJob; | ||
bloomFilter: BloomFilter; | ||
cacheKey: string; | ||
constructor(plugin: AuthPlugin); | ||
@@ -12,0 +15,0 @@ get app(): import("@nocobase/server").default<import("@nocobase/server").DefaultState, import("@nocobase/server").DefaultContext>; |
@@ -27,5 +27,19 @@ var __defProp = Object.defineProperty; | ||
this.repo = plugin.db.getRepository("tokenBlacklist"); | ||
plugin.app.on("beforeStart", async () => { | ||
try { | ||
this.bloomFilter = await plugin.app.cacheManager.createBloomFilter(); | ||
await this.bloomFilter.reserve(this.cacheKey, 1e-3, 1e6); | ||
const data = await this.repo.find({ fields: ["token"], raw: true }); | ||
const tokens = data.map((item) => item.token); | ||
await this.bloomFilter.mAdd(this.cacheKey, tokens); | ||
} catch (error) { | ||
plugin.app.logger.error("token-blacklist: create bloom filter failed", error); | ||
this.bloomFilter = null; | ||
} | ||
}); | ||
} | ||
repo; | ||
cronJob; | ||
bloomFilter; | ||
cacheKey = "token-black-list"; | ||
get app() { | ||
@@ -35,2 +49,8 @@ return this.plugin.app; | ||
async has(token) { | ||
if (this.bloomFilter) { | ||
const exists = await this.bloomFilter.exists(this.cacheKey, token); | ||
if (!exists) { | ||
return false; | ||
} | ||
} | ||
return !!await this.repo.findOne({ | ||
@@ -44,6 +64,10 @@ filter: { | ||
await this.deleteExpiredTokens(); | ||
const { token } = values; | ||
if (this.bloomFilter) { | ||
await this.bloomFilter.add(this.cacheKey, token); | ||
} | ||
return this.repo.model.findOrCreate({ | ||
defaults: values, | ||
where: { | ||
token: values.token | ||
token | ||
} | ||
@@ -50,0 +74,0 @@ }); |
{ | ||
"name": "@nocobase/plugin-auth", | ||
"version": "0.17.0-alpha.4", | ||
"version": "0.17.0-alpha.5", | ||
"main": "./dist/server/index.js", | ||
@@ -27,3 +27,3 @@ "devDependencies": { | ||
"description.zh-CN": "提供基础认证功能和扩展认证器管理功能", | ||
"gitHead": "663b03a3799a70ba1a2bc6a0d686e679331a50ad" | ||
"gitHead": "80ae6768a0f4108afa8ac342463627ef3960663f" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
248066
70
4211