@pubinfo/module-auth 2.0.0-beta.31 → 2.0.0-beta.33
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 +31 -31
- package/dist/index.js +128 -166
- package/dist/interface-CSPrYibH.d.ts +56 -0
- package/dist/providers/4A.d.ts +5 -4
- package/dist/providers/4A.js +23 -20
- package/dist/providers/credentials.d.ts +5 -5
- package/dist/providers/credentials.js +14 -11
- package/dist/providers/ding-zj.d.ts +10 -10
- package/dist/providers/ding-zj.js +56 -57
- package/package.json +5 -6
- package/dist/interface-XUOeLcLn.d.ts +0 -55
package/dist/index.d.ts
CHANGED
|
@@ -1,38 +1,38 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
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
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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
|
-
|
|
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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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
|
-
|
|
33
|
+
//#endregion
|
|
34
|
+
//#region src/core.ts
|
|
35
|
+
/**
|
|
36
|
+
* 初始化
|
|
37
|
+
*/
|
|
44
38
|
function createAuth(config = {}) {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
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
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
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
|
-
|
|
98
|
+
//#endregion
|
|
99
|
+
//#region src/index.ts
|
|
128
100
|
function withModule(auth, options = {}) {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
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
|
-
|
|
174
|
-
|
|
175
|
-
|
|
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 };
|
package/dist/providers/4A.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
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 };
|
package/dist/providers/4A.js
CHANGED
|
@@ -1,22 +1,25 @@
|
|
|
1
|
-
|
|
1
|
+
//#region src/providers/4A.ts
|
|
2
|
+
/**
|
|
3
|
+
* 4A登录
|
|
4
|
+
*/
|
|
2
5
|
function FourA(options) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
-
|
|
21
|
-
|
|
22
|
-
};
|
|
23
|
+
|
|
24
|
+
//#endregion
|
|
25
|
+
export { FourA as default };
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import {
|
|
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
|
-
|
|
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
|
-
|
|
1
|
+
//#region src/providers/credentials.ts
|
|
2
|
+
/**
|
|
3
|
+
* 凭证登录
|
|
4
|
+
*/
|
|
2
5
|
function Credentials(options) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
const { authorize } = options;
|
|
7
|
+
return {
|
|
8
|
+
id: "credentials",
|
|
9
|
+
name: "凭证登录",
|
|
10
|
+
type: "custom",
|
|
11
|
+
authorization: authorize
|
|
12
|
+
};
|
|
10
13
|
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
};
|
|
14
|
+
|
|
15
|
+
//#endregion
|
|
16
|
+
export { Credentials as default };
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import {
|
|
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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
|
|
1
|
+
//#region src/providers/ding-zj.ts
|
|
2
|
+
/**
|
|
3
|
+
* 浙政钉扫码登录
|
|
4
|
+
*/
|
|
2
5
|
function DingZJ(options) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
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
|
-
|
|
58
|
-
|
|
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.
|
|
4
|
+
"version": "2.0.0-beta.33",
|
|
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.
|
|
23
|
+
"pubinfo": "2.0.0-beta.33"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"
|
|
27
|
-
"pubinfo": "2.0.0-beta.31"
|
|
26
|
+
"pubinfo": "2.0.0-beta.33"
|
|
28
27
|
},
|
|
29
28
|
"scripts": {
|
|
30
|
-
"dev": "
|
|
31
|
-
"build": "
|
|
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 };
|