瀏覽代碼

update,登录有bug

lrf 1 年之前
父節點
當前提交
4f7e196974
共有 3 個文件被更改,包括 35 次插入7 次删除
  1. 12 1
      src/config/config.local.ts
  2. 1 1
      src/controller/home.controller.ts
  3. 22 5
      src/service/singleSignOn.service.ts

+ 12 - 1
src/config/config.local.ts

@@ -2,16 +2,24 @@ import { MidwayConfig } from '@midwayjs/core';
 const redisHost = '127.0.0.1';
 const redisPwd = '123456';
 const redisDB = 6;
+const coreApiPrefix = '/cxyy/api';
+const loginSign = 'tsFrameDev';
 export default {
   // use for cookie sign key, should change to your own and keep security
   keys: '1715577385578_8567',
   koa: {
     port: 19700,
   },
+  // 项目前缀
+  projectPrefix: {
+    core: coreApiPrefix,
+  },
+  loginSign,
+  // 项目前缀指向
   axios: {
     clients: {
       // key则为路由前缀
-      '/cxyy/api': {
+      coreApiPrefix: {
         baseURL: 'http://127.0.0.1:9700',
       },
       '/test/api': {
@@ -19,8 +27,11 @@ export default {
       },
     },
   },
+  // 权限验证的uri
   authUri: {
+    // 获取路由编码地址
     getRouteCode: '/cxyy/api/token/gerRouterInfo',
+    // 获取角色权限编码地址
     getUserApiCode: '/cxyy/api/token/getUserApiCodes',
   },
   redis: {

+ 1 - 1
src/controller/home.controller.ts

@@ -35,7 +35,7 @@ export class HomeController {
   @All('/**')
   async proxy() {
     // TODO:检查请求是否在白名单
-    const inWhiteList = true;
+    const inWhiteList = this.singleSignOnService.inWhiteList();
     if (!inWhiteList) {
       // 不在白名单上则检查登录
       await this.singleSignOnService.index();

+ 22 - 5
src/service/singleSignOn.service.ts

@@ -1,10 +1,11 @@
 import { Config, Inject, Provide } from '@midwayjs/core';
 import { JwtService } from '@midwayjs/jwt';
 import { Context } from '@midwayjs/koa';
-import { get } from 'lodash';
+import { get, toLower } from 'lodash';
 import { ServiceError, ErrorCode } from '../error/service.error';
 import * as Crypto from 'crypto-js';
 import { RedisService } from '@midwayjs/redis';
+import { ProxyService } from './proxy.service';
 
 @Provide()
 export class SingleSignOnService {
@@ -16,6 +17,12 @@ export class SingleSignOnService {
   private jwtSecret;
   @Config('jwt.expiresIn')
   private jwtExpiresIn;
+  /**核心服务前缀 */
+  @Config('projectPrefix.core')
+  corePrefix: string;
+  @Inject()
+  proxyService: ProxyService;
+
   @Inject()
   private jwtService: JwtService;
   @Inject()
@@ -58,15 +65,25 @@ export class SingleSignOnService {
   inWhiteList(): boolean {
     const whiteList = [
       {
-        uri: '/login',
+        uri: `${this.corePrefix}/login`,
+        method: 'post',
         desc: '登陆接口',
       },
       {
-        uri: '/dict',
+        uri: `${this.corePrefix}/dict`,
+        method: 'get',
         desc: '字典接口',
       },
+      // {
+      //   uri: `${this.corePrefix}/token/tokenView`,
+      //   method: 'get',
+      //   desc: 'token认证',
+      // },
     ];
-
-    return true;
+    const rb = this.proxyService.getRequstBase();
+    const r = whiteList.find(
+      f => f.uri === rb.path && toLower(f.method) === toLower(rb.method)
+    );
+    return r ? true : false;
   }
 }