浏览代码

第三方登录授权

zhangjie 3 年之前
父节点
当前提交
93b244b1f7

+ 7 - 1
src/modules/login/api.js

@@ -37,8 +37,14 @@ export const getSysTime = () => {
   return $postParam("/api/admin/common/get_system_time", {});
 };
 export const loginAuthen = datas => {
-  return $postParam("/api/report/wuda/open/user/authentication/login", datas);
+  return $postParam("/api/report/sso/user/authentication/login", datas);
 };
 export const logoutAuthen = datas => {
+  return $post("/api/report/sso/user/authentication/logout", datas);
+};
+export const loginWdAuthen = datas => {
+  return $postParam("/api/report/wuda/open/user/authentication/login", datas);
+};
+export const logoutWdAuthen = datas => {
   return $get("/api/report/wuda/open/user/authentication/logout", datas);
 };

+ 1 - 11
src/modules/login/router.js

@@ -1,7 +1,6 @@
 import LoginHome from "./views/LoginHome";
 import Login from "./views/Login";
 import LoginAuthen from "./views/LoginAuthen";
-import LogoutAuthen from "./views/LogoutAuthen";
 import SelectSchool from "./views/SelectSchool";
 
 export default {
@@ -18,7 +17,7 @@ export default {
       }
     },
     {
-      path: "/login-authen/:code",
+      path: "/login-authen/:code/:appSource",
       name: "LoginAuthen",
       component: LoginAuthen,
       meta: {
@@ -26,15 +25,6 @@ export default {
         noRequire: true
       }
     },
-    {
-      path: "/logout-authen",
-      name: "LogoutAuthen",
-      component: LogoutAuthen,
-      meta: {
-        title: "第三方退出",
-        noRequire: true
-      }
-    },
     {
       path: "/select-school",
       name: "SelectSchool",

+ 12 - 3
src/modules/login/views/LoginAuthen.vue

@@ -7,13 +7,14 @@
 </template>
 
 <script>
-import { loginAuthen } from "../api";
+import { loginAuthen, loginWdAuthen } from "../api";
 
 export default {
   name: "login-authen",
   data() {
     return {
-      code: this.$route.params.code
+      code: this.$route.params.code,
+      appSource: this.$route.params.appSource
     };
   },
   mounted() {
@@ -28,7 +29,15 @@ export default {
         });
         return;
       }
-      const data = await loginAuthen({ code: this.code });
+      const funcs = {
+        WHU_THIRD: loginWdAuthen,
+        PRINT_THIRD: loginAuthen
+      };
+      const func = funcs[this.appSource] || loginAuthen;
+      const data = await func({
+        code: this.code,
+        appSource: this.appSource
+      });
       if (!data) return;
 
       if (data.orgInfo) this.$ls.set("orgId", data.orgInfo.id);

+ 0 - 19
src/modules/login/views/LogoutAuthen.vue

@@ -1,19 +0,0 @@
-<template>
-  <div class="logout-authen">
-    <h1 class="color-white text-center">
-      <i class="el-icon-loading"></i> 正在退出...
-    </h1>
-  </div>
-</template>
-
-<script>
-export default {
-  name: "logout-authen",
-  data() {
-    return {};
-  },
-  created() {
-    window.location.href = "/api/report/wuda/open/user/authentication/logout";
-  }
-};
-</script>

+ 25 - 0
src/plugins/auth.js

@@ -0,0 +1,25 @@
+import { fetchTime } from "../plugins/syncServerTime";
+import { getAuthorization } from "../plugins/crypto";
+import { PLATFORM, DEVICE_ID } from "../constants/app";
+
+export function getAuthInfo(data) {
+  const timestamp = fetchTime();
+  const authorization = getAuthorization(
+    {
+      token: data.token,
+      timestamp,
+      account: data.sessionId,
+      uri: data.url,
+      method: data.method
+    },
+    "token"
+  );
+
+  return {
+    authorization,
+    time: timestamp,
+    deviceId: DEVICE_ID,
+    platform: PLATFORM,
+    domain: window.location.origin
+  };
+}

+ 33 - 4
src/views/Home.vue

@@ -121,6 +121,8 @@ import localMenus from "@/constants/menus-data";
 import { sysMenu, logout } from "@/modules/login/api";
 import ResetPwd from "../modules/base/components/ResetPwd";
 import { SYS_ADMIN_NAME } from "@/constants/enumerate";
+import { getAuthInfo } from "../plugins/auth";
+import { autoSubmitForm } from "../plugins/utils";
 
 const MENU_ICONS = {
   base: "base",
@@ -133,7 +135,12 @@ export default {
   name: "home",
   components: { ResetPwd },
   data() {
-    const user = this.$ls.get("user", { id: "", realName: "", roleList: [] });
+    const user = this.$ls.get("user", {
+      id: "",
+      realName: "",
+      roleList: [],
+      appSource: ""
+    });
     const IS_SUPER_ADMIN = user.loginName === SYS_ADMIN_NAME;
 
     return {
@@ -147,6 +154,7 @@ export default {
       validRoutes: [],
       username: user.realName,
       userRoles: user.roleList,
+      appSource: user.appSource,
       schoolLogo: this.$ls.get("schoolLogo"),
       schoolName: this.$ls.get("schoolName"),
       userInfo: {
@@ -331,9 +339,30 @@ export default {
         .catch(() => {});
     },
     async logoutAction() {
-      await logout();
-      this.$ls.clear();
-      this.$router.push({ name: "Login" });
+      if (this.appSource === "SYSTEM") {
+        await logout();
+        this.$ls.clear();
+        this.$router.push({ name: "Login" });
+      } else if (this.appSource === "WHU_THIRD") {
+        window.location.href =
+          "/api/report/wuda/open/user/authentication/logout";
+      } else if (this.appSource === "PRINT_THIRD") {
+        const url = "/api/report/sso/user/authentication/logout";
+        const infos = getAuthInfo({
+          sessionId: this.$ls.get("user", { sessionId: "" }).sessionId,
+          token: this.$ls.get("token"),
+          url,
+          method: "post"
+        });
+        autoSubmitForm(url, {
+          ...infos,
+          orgId: this.$ls.get("orgId", ""),
+          schoolId: this.$ls.get("schoolId", ""),
+          userId: this.$ls.get("user", { id: "" }).id
+        });
+      } else {
+        this.$message.error("未知来源");
+      }
     },
     toSelectSchool() {
       if (this.IS_SUPER_ADMIN) this.$router.push({ name: "SelectSchool" });