mirror of
https://github.com/certd/certd.git
synced 2026-04-23 19:57:27 +08:00
perf: 授权配置支持加密
原本已经添加的授权配置,再次编辑保存即变成加密配置
This commit is contained in:
@@ -1,21 +1,31 @@
|
||||
import { Config, Inject, MidwayWebRouterService, Provide } from '@midwayjs/core';
|
||||
import { Init, Inject, MidwayWebRouterService, Provide, Scope, ScopeEnum } from '@midwayjs/core';
|
||||
import { IMidwayKoaContext, IWebMiddleware, NextFunction } from '@midwayjs/koa';
|
||||
import jwt from 'jsonwebtoken';
|
||||
import { Constants } from '../basic/constants.js';
|
||||
import { logger } from '../utils/logger.js';
|
||||
import { AuthService } from '../modules/authority/service/auth-service.js';
|
||||
import { SysSettingsService } from '../modules/system/service/sys-settings-service.js';
|
||||
import { SysPrivateSettings } from '../modules/system/service/models.js';
|
||||
|
||||
/**
|
||||
* 权限校验
|
||||
*/
|
||||
@Provide()
|
||||
@Scope(ScopeEnum.Singleton)
|
||||
export class AuthorityMiddleware implements IWebMiddleware {
|
||||
@Config('auth.jwt.secret')
|
||||
private secret: string;
|
||||
@Inject()
|
||||
webRouterService: MidwayWebRouterService;
|
||||
@Inject()
|
||||
authService: AuthService;
|
||||
@Inject()
|
||||
sysSettingsService: SysSettingsService;
|
||||
|
||||
secret: string;
|
||||
@Init()
|
||||
async init() {
|
||||
const setting: SysPrivateSettings = await this.sysSettingsService.getSetting(SysPrivateSettings);
|
||||
this.secret = setting.jwtKey;
|
||||
}
|
||||
|
||||
resolve() {
|
||||
return async (ctx: IMidwayKoaContext, next: NextFunction) => {
|
||||
|
||||
Reference in New Issue
Block a user