@pubinfo/module-auth 2.0.0-beta.31 → 2.0.0-beta.32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,38 +1,38 @@
1
- import { ModuleOptions } from 'pubinfo';
2
- import { A as AuthConfig, T as ThirdParty, R as Recordable, a as AuthOptions } from './interface-XUOeLcLn.js';
3
- export { d as Authorization, F as Fn, b as FnApi, c as ProviderConfig, P as ProviderUserConfig } from './interface-XUOeLcLn.js';
4
- import 'vue-router';
1
+ import { AuthConfig, AuthOptions, Authorization, Fn, FnApi, ProviderConfig, ProviderUserConfig, Recordable, ThirdParty } from "./interface-CSPrYibH.js";
2
+ import { ModuleOptions } from "pubinfo";
5
3
 
4
+ //#region src/core.d.ts
6
5
  /**
7
6
  * 初始化
8
7
  */
9
8
  declare function createAuth(config?: AuthConfig): {
10
- /**
11
- * 前往登录
12
- * @param id 唯一值
13
- * @param options 登录时需要传递的参数
14
- */
15
- signIn(id: ThirdParty, options?: Recordable): Promise<any>;
16
- /**
17
- * 生成二维码
18
- * @param id 第三方的唯一值
19
- * @param options 生成二维码需要传递的参数
20
- * @param options.id `getElementById`中指定的`id`
21
- */
22
- renderQRCode(id: ThirdParty, options: {
23
- id: string;
24
- } & Recordable): void;
25
- /**
26
- * 认证
27
- * @param id 第三方的唯一值
28
- */
29
- authentication(id: ThirdParty): Promise<any>;
30
- /**
31
- * 重定向至统一登录页
32
- */
33
- redirect(): void;
9
+ /**
10
+ * 前往登录
11
+ * @param id 唯一值
12
+ * @param options 登录时需要传递的参数
13
+ */
14
+ signIn(id: ThirdParty, options?: Recordable): Promise<any>;
15
+ /**
16
+ * 生成二维码
17
+ * @param id 第三方的唯一值
18
+ * @param options 生成二维码需要传递的参数
19
+ * @param options.id `getElementById`中指定的`id`
20
+ */
21
+ renderQRCode(id: ThirdParty, options: {
22
+ id: string;
23
+ } & Recordable): void;
24
+ /**
25
+ * 认证
26
+ * @param id 第三方的唯一值
27
+ */
28
+ authentication(id: ThirdParty): Promise<any>;
29
+ /**
30
+ * 重定向至统一登录页
31
+ */
32
+ redirect(): void;
34
33
  };
35
-
34
+ //#endregion
35
+ //#region src/index.d.ts
36
36
  declare function withModule(auth: ReturnType<typeof createAuth>, options?: AuthOptions): ModuleOptions;
37
-
38
- export { AuthConfig, AuthOptions, Recordable, ThirdParty, createAuth, withModule };
37
+ //#endregion
38
+ export { AuthConfig, AuthOptions, Authorization, Fn, FnApi, ProviderConfig, ProviderUserConfig, Recordable, ThirdParty, createAuth, withModule };
package/dist/index.js CHANGED
@@ -1,176 +1,138 @@
1
- // src/index.ts
2
- import { cleanup } from "pubinfo";
3
-
4
- // src/pages/auth.ts
5
- import { useUserStore } from "pubinfo";
1
+ import { cleanup, useUserStore } from "pubinfo";
6
2
  import { defineComponent, h, onMounted, ref } from "vue";
7
- var PageAuth = defineComponent({
8
- props: {
9
- type: String,
10
- redirectTo: Function,
11
- authentication: Function
12
- },
13
- setup(props) {
14
- const userStore = useUserStore();
15
- const message = ref("\u6388\u6743\u767B\u5F55\u4E2D...");
16
- onMounted(async () => {
17
- const res = await props.authentication?.(props.type);
18
- if (res?.success) {
19
- userStore.setToken(res?.data?.accessToken, res?.data?.refreshToken);
20
- props?.redirectTo?.();
21
- } else {
22
- message.value = res?.msg ?? res?.message;
23
- }
24
- });
25
- return () => {
26
- return h(
27
- "div",
28
- {
29
- style: {
30
- display: "flex",
31
- justifyContent: "center",
32
- alignItems: "center",
33
- width: "100vw",
34
- height: "100vh"
35
- }
36
- },
37
- message.value
38
- );
39
- };
40
- }
3
+
4
+ //#region src/pages/auth.ts
5
+ const PageAuth = defineComponent({
6
+ props: {
7
+ type: String,
8
+ redirectTo: Function,
9
+ authentication: Function
10
+ },
11
+ setup(props) {
12
+ const userStore = useUserStore();
13
+ const message = ref("授权登录中...");
14
+ onMounted(async () => {
15
+ const res = await props.authentication?.(props.type);
16
+ if (res?.success) {
17
+ userStore.setToken(res?.data?.accessToken, res?.data?.refreshToken);
18
+ props?.redirectTo?.();
19
+ } else message.value = res?.msg ?? res?.message;
20
+ });
21
+ return () => {
22
+ return h("div", { style: {
23
+ display: "flex",
24
+ justifyContent: "center",
25
+ alignItems: "center",
26
+ width: "100vw",
27
+ height: "100vh"
28
+ } }, message.value);
29
+ };
30
+ }
41
31
  });
42
32
 
43
- // src/core.ts
33
+ //#endregion
34
+ //#region src/core.ts
35
+ /**
36
+ * 初始化
37
+ */
44
38
  function createAuth(config = {}) {
45
- const {
46
- baseURL = "",
47
- providers = []
48
- } = config;
49
- function getProvider(id) {
50
- const provider = id ? providers.find((provider2) => provider2.id === id) : providers[0];
51
- if (!provider) {
52
- throw new Error(`Provider '${id}' is not found.`);
53
- }
54
- return provider;
55
- }
56
- return {
57
- /**
58
- * 前往登录
59
- * @param id 唯一值
60
- * @param options 登录时需要传递的参数
61
- */
62
- async signIn(id, options) {
63
- const provider = getProvider(id);
64
- const { type, authorization } = provider;
65
- if (typeof authorization === "function") {
66
- return await authorization(options);
67
- }
68
- if (type === "oauth" || type === "custom") {
69
- const url = createUrl(provider);
70
- window.location.replace(url);
71
- }
72
- },
73
- /**
74
- * 生成二维码
75
- * @param id 第三方的唯一值
76
- * @param options 生成二维码需要传递的参数
77
- * @param options.id `getElementById`中指定的`id`
78
- */
79
- renderQRCode(id, options) {
80
- const provider = getProvider(id);
81
- const { type, initQRCode } = provider;
82
- if (type === "oauth" || type === "custom") {
83
- const url = createUrl(provider);
84
- initQRCode?.(url, options);
85
- }
86
- },
87
- /**
88
- * 认证
89
- * @param id 第三方的唯一值
90
- */
91
- async authentication(id) {
92
- const provider = getProvider(id);
93
- const { type, callbackUrl } = provider;
94
- const qs = window.location.href.split("?")?.[1] ?? "";
95
- const params = new URLSearchParams(qs);
96
- if (typeof callbackUrl === "function") {
97
- return await callbackUrl(Object.fromEntries(params.entries()), baseURL);
98
- }
99
- if (type === "oauth" || type === "cas" || type === "custom") {
100
- const response = await fetch(`${baseURL}${callbackUrl}?${params.toString()}`);
101
- return await response.json();
102
- }
103
- },
104
- /**
105
- * 重定向至统一登录页
106
- */
107
- redirect() {
108
- const provider = providers.find((provider2) => provider2.type === "cas");
109
- if (!provider) {
110
- return;
111
- }
112
- const url = createUrl(provider);
113
- window.location.replace(url);
114
- }
115
- };
39
+ const { baseURL = "", providers = [] } = config;
40
+ /**
41
+ * 获取指定的 `Provider`
42
+ * @param id
43
+ */
44
+ function getProvider(id) {
45
+ const provider = id ? providers.find((provider$1) => provider$1.id === id) : providers[0];
46
+ if (!provider) throw new Error(`Provider '${id}' is not found.`);
47
+ return provider;
48
+ }
49
+ return {
50
+ async signIn(id, options) {
51
+ const provider = getProvider(id);
52
+ const { type, authorization } = provider;
53
+ if (typeof authorization === "function") return await authorization(options);
54
+ if (type === "oauth" || type === "custom") {
55
+ const url = createUrl(provider);
56
+ window.location.replace(url);
57
+ }
58
+ },
59
+ renderQRCode(id, options) {
60
+ const provider = getProvider(id);
61
+ const { type, initQRCode } = provider;
62
+ if (type === "oauth" || type === "custom") {
63
+ const url = createUrl(provider);
64
+ initQRCode?.(url, options);
65
+ }
66
+ },
67
+ async authentication(id) {
68
+ const provider = getProvider(id);
69
+ const { type, callbackUrl } = provider;
70
+ const qs = window.location.href.split("?")?.[1] ?? "";
71
+ const params = new URLSearchParams(qs);
72
+ if (typeof callbackUrl === "function") return await callbackUrl(Object.fromEntries(params.entries()), baseURL);
73
+ if (type === "oauth" || type === "cas" || type === "custom") {
74
+ const response = await fetch(`${baseURL}${callbackUrl}?${params.toString()}`);
75
+ return await response.json();
76
+ }
77
+ },
78
+ redirect() {
79
+ const provider = providers.find((provider$1) => provider$1.type === "cas");
80
+ if (!provider) return;
81
+ const url = createUrl(provider);
82
+ window.location.replace(url);
83
+ }
84
+ };
116
85
  }
86
+ /**
87
+ * 构建第三方授权登录地址
88
+ * @param provider
89
+ */
117
90
  function createUrl(provider) {
118
- const { authorization } = provider;
119
- if (typeof authorization === "function") {
120
- return "";
121
- }
122
- const url = new URL(authorization?.url ?? "");
123
- const params = new URLSearchParams(authorization?.params ?? {});
124
- return `${url.toString()}?${params.toString()}`;
91
+ const { authorization } = provider;
92
+ if (typeof authorization === "function") return "";
93
+ const url = new URL(authorization?.url ?? "");
94
+ const params = new URLSearchParams(authorization?.params ?? {});
95
+ return `${url.toString()}?${params.toString()}`;
125
96
  }
126
97
 
127
- // src/index.ts
98
+ //#endregion
99
+ //#region src/index.ts
128
100
  function withModule(auth, options = {}) {
129
- const { authentication, redirect } = auth;
130
- const {
131
- redirectTo = "/",
132
- pages = {}
133
- } = options;
134
- const {
135
- signIn = "/login"
136
- } = pages;
137
- return {
138
- name: "pubinfo:auth",
139
- enforce: "pre",
140
- setup(ctx) {
141
- const { router } = ctx;
142
- const ROUTE_AUTH = {
143
- path: "/auth/:type",
144
- name: "Auth",
145
- component: PageAuth,
146
- meta: {
147
- whiteList: true,
148
- title: "\u6388\u6743\u767B\u5F55"
149
- },
150
- props: (route) => ({
151
- type: route.params.type,
152
- redirectTo() {
153
- router.push(redirectTo);
154
- },
155
- authentication
156
- })
157
- };
158
- router.beforeEach((to) => {
159
- if (!router.hasRoute(ROUTE_AUTH.name)) {
160
- router.addRoute(ROUTE_AUTH);
161
- return to.fullPath;
162
- }
163
- if (to.name === ROUTE_AUTH.name) {
164
- cleanup();
165
- }
166
- if (to.path === signIn) {
167
- redirect();
168
- }
169
- });
170
- }
171
- };
101
+ const { authentication, redirect } = auth;
102
+ const { redirectTo = "/", pages = {} } = options;
103
+ const { signIn = "/login" } = pages;
104
+ return {
105
+ name: "pubinfo:auth",
106
+ enforce: "pre",
107
+ setup(ctx) {
108
+ const { router } = ctx;
109
+ const ROUTE_AUTH = {
110
+ path: "/auth/:type",
111
+ name: "Auth",
112
+ component: PageAuth,
113
+ meta: {
114
+ whiteList: true,
115
+ title: "授权登录"
116
+ },
117
+ props: (route) => ({
118
+ type: route.params.type,
119
+ redirectTo() {
120
+ router.push(redirectTo);
121
+ },
122
+ authentication
123
+ })
124
+ };
125
+ router.beforeEach((to) => {
126
+ if (!router.hasRoute(ROUTE_AUTH.name)) {
127
+ router.addRoute(ROUTE_AUTH);
128
+ return to.fullPath;
129
+ }
130
+ if (to.name === ROUTE_AUTH.name) cleanup();
131
+ if (to.path === signIn) redirect();
132
+ });
133
+ }
134
+ };
172
135
  }
173
- export {
174
- createAuth,
175
- withModule
176
- };
136
+
137
+ //#endregion
138
+ export { createAuth, withModule };
@@ -0,0 +1,56 @@
1
+ import { RouteLocationRaw } from "vue-router";
2
+
3
+ //#region src/interface.d.ts
4
+ type Recordable = Record<string, any>;
5
+ type Fn<T = any, K = any> = (params?: Recordable & T) => Promise<K> | K;
6
+ type FnApi<T = any> = (params: Recordable & T, baseURL: string) => Promise<any>;
7
+ interface AuthOptions {
8
+ /** 登录后重定向至 */
9
+ redirectTo?: RouteLocationRaw;
10
+ /** 页面配置 */
11
+ pages?: {
12
+ /** 默认登录页 */
13
+ signIn?: RouteLocationRaw;
14
+ };
15
+ }
16
+ interface AuthConfig {
17
+ /** 接口的baseURL */
18
+ baseURL?: string;
19
+ providers?: ProviderConfig[];
20
+ }
21
+ /** 第三方类型 */
22
+ type ThirdParty = string;
23
+ type ProviderUserConfig = Partial<ProviderConfig>;
24
+ interface ProviderConfig {
25
+ /** 唯一值 */
26
+ id: string;
27
+ /** 名称 */
28
+ name: string;
29
+ /**
30
+ * 协议类型
31
+ * - `oauth` 第三方授权登录
32
+ * - `cas` 统一账号登录
33
+ * - `custom` 自定义
34
+ */
35
+ type: 'oauth' | 'cas' | 'custom';
36
+ /** 授权登录地址 */
37
+ authorization?: Authorization | Fn;
38
+ /** `client_id` */
39
+ clientId?: string;
40
+ /** `redirect_uri` */
41
+ redirectUri?: string;
42
+ /** 授权登录接口 */
43
+ callbackUrl?: string | FnApi;
44
+ /** 初始化二维码 */
45
+ initQRCode?: (url: string, params: {
46
+ id: string;
47
+ } & Recordable) => Promise<void> | void;
48
+ }
49
+ interface Authorization {
50
+ /** 授权登录地址 */
51
+ url: string;
52
+ /** 授权登录参数 */
53
+ params?: Recordable;
54
+ }
55
+ //#endregion
56
+ export { AuthConfig, AuthOptions, Authorization, Fn, FnApi, ProviderConfig, ProviderUserConfig, Recordable, ThirdParty };
@@ -1,9 +1,10 @@
1
- import { P as ProviderUserConfig, c as ProviderConfig } from '../interface-XUOeLcLn.js';
2
- import 'vue-router';
1
+ import { ProviderConfig, ProviderUserConfig } from "../interface-CSPrYibH.js";
2
+
3
+ //#region src/providers/4A.d.ts
3
4
 
4
5
  /**
5
6
  * 4A登录
6
7
  */
7
8
  declare function FourA(options: ProviderUserConfig): ProviderConfig;
8
-
9
- export { FourA as default };
9
+ //#endregion
10
+ export { FourA as default };
@@ -1,22 +1,25 @@
1
- // src/providers/4A.ts
1
+ //#region src/providers/4A.ts
2
+ /**
3
+ * 4A登录
4
+ */
2
5
  function FourA(options) {
3
- const { clientId, redirectUri } = options;
4
- return {
5
- id: "4A",
6
- name: "4A\u767B\u5F55",
7
- type: "oauth",
8
- authorization: {
9
- url: "http://134.108.76.137:7001/index",
10
- params: {
11
- response_type: "code",
12
- client_id: clientId,
13
- redirect_uri: redirectUri
14
- }
15
- },
16
- callbackUrl: "/bs/loginBy4a",
17
- ...options
18
- };
6
+ const { clientId, redirectUri } = options;
7
+ return {
8
+ id: "4A",
9
+ name: "4A登录",
10
+ type: "oauth",
11
+ authorization: {
12
+ url: "http://134.108.76.137:7001/index",
13
+ params: {
14
+ response_type: "code",
15
+ client_id: clientId,
16
+ redirect_uri: redirectUri
17
+ }
18
+ },
19
+ callbackUrl: "/bs/loginBy4a",
20
+ ...options
21
+ };
19
22
  }
20
- export {
21
- FourA as default
22
- };
23
+
24
+ //#endregion
25
+ export { FourA as default };
@@ -1,12 +1,12 @@
1
- import { F as Fn, c as ProviderConfig } from '../interface-XUOeLcLn.js';
2
- import 'vue-router';
1
+ import { Fn, ProviderConfig } from "../interface-CSPrYibH.js";
3
2
 
3
+ //#region src/providers/credentials.d.ts
4
4
  interface CredentialsConfig {
5
- authorize: Fn<any>;
5
+ authorize: Fn<any>;
6
6
  }
7
7
  /**
8
8
  * 凭证登录
9
9
  */
10
10
  declare function Credentials(options: CredentialsConfig): ProviderConfig;
11
-
12
- export { Credentials as default };
11
+ //#endregion
12
+ export { Credentials as default };
@@ -1,13 +1,16 @@
1
- // src/providers/credentials.ts
1
+ //#region src/providers/credentials.ts
2
+ /**
3
+ * 凭证登录
4
+ */
2
5
  function Credentials(options) {
3
- const { authorize } = options;
4
- return {
5
- id: "credentials",
6
- name: "\u51ED\u8BC1\u767B\u5F55",
7
- type: "custom",
8
- authorization: authorize
9
- };
6
+ const { authorize } = options;
7
+ return {
8
+ id: "credentials",
9
+ name: "凭证登录",
10
+ type: "custom",
11
+ authorization: authorize
12
+ };
10
13
  }
11
- export {
12
- Credentials as default
13
- };
14
+
15
+ //#endregion
16
+ export { Credentials as default };
@@ -1,17 +1,17 @@
1
- import { P as ProviderUserConfig, c as ProviderConfig } from '../interface-XUOeLcLn.js';
2
- import 'vue-router';
1
+ import { ProviderConfig, ProviderUserConfig } from "../interface-CSPrYibH.js";
3
2
 
3
+ //#region src/providers/ding-zj.d.ts
4
4
  interface DingZJConfig extends ProviderUserConfig {
5
- /**
6
- * 登录方式
7
- * - `redirect` 跳转浙政钉的扫码页面
8
- * - `embed` 内嵌浙政钉的登录二维码
9
- */
10
- mode: 'redirect' | 'embed';
5
+ /**
6
+ * 登录方式
7
+ * - `redirect` 跳转浙政钉的扫码页面
8
+ * - `embed` 内嵌浙政钉的登录二维码
9
+ */
10
+ mode: 'redirect' | 'embed';
11
11
  }
12
12
  /**
13
13
  * 浙政钉扫码登录
14
14
  */
15
15
  declare function DingZJ(options: DingZJConfig): ProviderConfig;
16
-
17
- export { DingZJ as default };
16
+ //#endregion
17
+ export { DingZJ as default };
@@ -1,59 +1,58 @@
1
- // src/providers/ding-zj.ts
1
+ //#region src/providers/ding-zj.ts
2
+ /**
3
+ * 浙政钉扫码登录
4
+ */
2
5
  function DingZJ(options) {
3
- const { clientId, redirectUri } = options;
4
- const authorization = {
5
- /** 跳转外部页面 */
6
- redirect: {
7
- url: "https://openplatform-pro.ding.zj.gov.cn/oauth2/auth.htm",
8
- params: {
9
- response_type: "code",
10
- client_id: clientId,
11
- redirect_uri: redirectUri,
12
- scope: "get_user_info",
13
- authType: "QRCODE"
14
- }
15
- },
16
- /** 内嵌二维码 */
17
- embed: {
18
- url: "https://login-pro.ding.zj.gov.cn/oauth2/auth.htm",
19
- params: {
20
- response_type: "code",
21
- client_id: clientId,
22
- redirect_uri: redirectUri,
23
- scope: "get_user_info",
24
- authType: "QRCODE",
25
- embedMode: "true"
26
- }
27
- }
28
- };
29
- const initQRCode = (url, options2) => {
30
- const target = document.getElementById(options2.id);
31
- if (!target) {
32
- throw new Error(`\u672A\u627E\u5230id\u4E3A${options2.id}\u7684DOM\u5143\u7D20`);
33
- }
34
- const iframe = document.createElement("iframe");
35
- iframe.src = url;
36
- iframe.width = "200";
37
- iframe.height = "200";
38
- document.appendChild(iframe);
39
- window.addEventListener("message", (e) => {
40
- if (options2.redirectUri) {
41
- const url2 = new URL(options2.redirectUri);
42
- url2.search = new URLSearchParams(e.data).toString();
43
- window.location.href = url2.toString();
44
- }
45
- });
46
- };
47
- return {
48
- id: "ding-zj",
49
- name: "\u6D59\u653F\u9489\u767B\u5F55",
50
- type: "oauth",
51
- authorization: authorization[options.mode],
52
- callbackUrl: "/bs/loginByDingZJ",
53
- initQRCode: options.mode === "embed" ? initQRCode : void 0,
54
- ...options
55
- };
6
+ const { clientId, redirectUri } = options;
7
+ const authorization = {
8
+ redirect: {
9
+ url: "https://openplatform-pro.ding.zj.gov.cn/oauth2/auth.htm",
10
+ params: {
11
+ response_type: "code",
12
+ client_id: clientId,
13
+ redirect_uri: redirectUri,
14
+ scope: "get_user_info",
15
+ authType: "QRCODE"
16
+ }
17
+ },
18
+ embed: {
19
+ url: "https://login-pro.ding.zj.gov.cn/oauth2/auth.htm",
20
+ params: {
21
+ response_type: "code",
22
+ client_id: clientId,
23
+ redirect_uri: redirectUri,
24
+ scope: "get_user_info",
25
+ authType: "QRCODE",
26
+ embedMode: "true"
27
+ }
28
+ }
29
+ };
30
+ const initQRCode = (url, options$1) => {
31
+ const target = document.getElementById(options$1.id);
32
+ if (!target) throw new Error(`未找到id为${options$1.id}的DOM元素`);
33
+ const iframe = document.createElement("iframe");
34
+ iframe.src = url;
35
+ iframe.width = "200";
36
+ iframe.height = "200";
37
+ document.appendChild(iframe);
38
+ window.addEventListener("message", (e) => {
39
+ if (options$1.redirectUri) {
40
+ const url$1 = new URL(options$1.redirectUri);
41
+ url$1.search = new URLSearchParams(e.data).toString();
42
+ window.location.href = url$1.toString();
43
+ }
44
+ });
45
+ };
46
+ return {
47
+ id: "ding-zj",
48
+ name: "浙政钉登录",
49
+ type: "oauth",
50
+ authorization: authorization[options.mode],
51
+ callbackUrl: "/bs/loginByDingZJ",
52
+ initQRCode: options.mode === "embed" ? initQRCode : void 0,
53
+ ...options
54
+ };
56
55
  }
57
- export {
58
- DingZJ as default
59
- };
56
+
57
+ //#endregion
58
+ export { DingZJ as default };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@pubinfo/module-auth",
3
3
  "type": "module",
4
- "version": "2.0.0-beta.31",
4
+ "version": "2.0.0-beta.32",
5
5
  "exports": {
6
6
  ".": {
7
7
  "types": "./dist/index.d.ts",
@@ -20,14 +20,13 @@
20
20
  "src"
21
21
  ],
22
22
  "peerDependencies": {
23
- "pubinfo": "2.0.0-beta.31"
23
+ "pubinfo": "2.0.0-beta.32"
24
24
  },
25
25
  "devDependencies": {
26
- "tsup": "^8.5.0",
27
- "pubinfo": "2.0.0-beta.31"
26
+ "pubinfo": "2.0.0-beta.32"
28
27
  },
29
28
  "scripts": {
30
- "dev": "tsup --watch src",
31
- "build": "tsup"
29
+ "dev": "tsdown --watch src",
30
+ "build": "tsdown"
32
31
  }
33
32
  }
@@ -1,55 +0,0 @@
1
- import { RouteLocationRaw } from 'vue-router';
2
-
3
- type Recordable = Record<string, any>;
4
- type Fn<T = any, K = any> = (params?: Recordable & T) => Promise<K> | K;
5
- type FnApi<T = any> = (params: Recordable & T, baseURL: string) => Promise<any>;
6
- interface AuthOptions {
7
- /** 登录后重定向至 */
8
- redirectTo?: RouteLocationRaw;
9
- /** 页面配置 */
10
- pages?: {
11
- /** 默认登录页 */
12
- signIn?: RouteLocationRaw;
13
- };
14
- }
15
- interface AuthConfig {
16
- /** 接口的baseURL */
17
- baseURL?: string;
18
- providers?: ProviderConfig[];
19
- }
20
- /** 第三方类型 */
21
- type ThirdParty = string;
22
- type ProviderUserConfig = Partial<ProviderConfig>;
23
- interface ProviderConfig {
24
- /** 唯一值 */
25
- id: string;
26
- /** 名称 */
27
- name: string;
28
- /**
29
- * 协议类型
30
- * - `oauth` 第三方授权登录
31
- * - `cas` 统一账号登录
32
- * - `custom` 自定义
33
- */
34
- type: 'oauth' | 'cas' | 'custom';
35
- /** 授权登录地址 */
36
- authorization?: Authorization | Fn;
37
- /** `client_id` */
38
- clientId?: string;
39
- /** `redirect_uri` */
40
- redirectUri?: string;
41
- /** 授权登录接口 */
42
- callbackUrl?: string | FnApi;
43
- /** 初始化二维码 */
44
- initQRCode?: (url: string, params: {
45
- id: string;
46
- } & Recordable) => Promise<void> | void;
47
- }
48
- interface Authorization {
49
- /** 授权登录地址 */
50
- url: string;
51
- /** 授权登录参数 */
52
- params?: Recordable;
53
- }
54
-
55
- export type { AuthConfig as A, Fn as F, ProviderUserConfig as P, Recordable as R, ThirdParty as T, AuthOptions as a, FnApi as b, ProviderConfig as c, Authorization as d };