@pubinfo/module-auth 2.0.0-beta.14 → 2.0.0-beta.16

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,33 +1,38 @@
1
- import { A as AuthOptions, T as ThirdParty, R as Recordable } from './interface-C_qnbvmk.js';
2
- export { b as AuthConfig, d as Authorization, F as Fn, a as FnApi, c as ProviderConfig, P as ProviderUserConfig } from './interface-C_qnbvmk.js';
3
1
  import { ModuleOptions } from 'pubinfo';
2
+ import { A as AuthConfig, T as ThirdParty, R as Recordable, a as AuthOptions } from './interface-BStwVrS7.js';
3
+ export { d as Authorization, F as Fn, b as FnApi, c as ProviderConfig, P as ProviderUserConfig } from './interface-BStwVrS7.js';
4
4
  import 'vue-router';
5
5
 
6
- declare function createAuth(options?: AuthOptions): {
6
+ /**
7
+ * 初始化
8
+ */
9
+ declare function createAuth(config?: AuthConfig): {
7
10
  /**
8
11
  * 前往登录
9
12
  * @param id 唯一值
10
13
  * @param options 登录时需要传递的参数
11
14
  */
12
- signIn: (id: ThirdParty, options?: Recordable) => Promise<any>;
15
+ signIn(id: ThirdParty, options?: Recordable): Promise<any>;
13
16
  /**
14
17
  * 生成二维码
15
18
  * @param id 第三方的唯一值
16
19
  * @param options 生成二维码需要传递的参数
17
20
  * @param options.id `getElementById`中指定的`id`
18
21
  */
19
- renderQRCode: (id: ThirdParty, options: {
22
+ renderQRCode(id: ThirdParty, options: {
20
23
  id: string;
21
- } & Recordable) => void;
24
+ } & Recordable): void;
22
25
  /**
23
26
  * 认证
24
27
  * @param id 第三方的唯一值
25
28
  */
26
- authentication: (id: ThirdParty) => Promise<any>;
29
+ authentication(id: ThirdParty): Promise<any>;
27
30
  /**
28
- * 模块配置
31
+ * 重定向至统一登录页
29
32
  */
30
- auth: () => ModuleOptions;
33
+ redirect(): void;
31
34
  };
32
35
 
33
- export { AuthOptions, Recordable, ThirdParty, createAuth };
36
+ declare function withModule(auth: ReturnType<typeof createAuth>, options?: AuthOptions): ModuleOptions;
37
+
38
+ export { AuthConfig, AuthOptions, Recordable, ThirdParty, createAuth, withModule };
package/dist/index.js CHANGED
@@ -1,6 +1,45 @@
1
1
  // src/index.ts
2
2
  import { cleanup } from "pubinfo";
3
3
 
4
+ // src/pages/auth.ts
5
+ import { useUserStore } from "pubinfo";
6
+ 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
+ }
41
+ });
42
+
4
43
  // src/core.ts
5
44
  function createAuth(config = {}) {
6
45
  const {
@@ -85,112 +124,47 @@ function createUrl(provider) {
85
124
  return `${url.toString()}?${params.toString()}`;
86
125
  }
87
126
 
88
- // src/pages/auth.ts
89
- import { useUserStore } from "pubinfo";
90
- import { defineComponent, h, onMounted, ref } from "vue";
91
- var Auth = defineComponent({
92
- props: {
93
- type: String,
94
- redirectTo: Function,
95
- authentication: Function
96
- },
97
- setup(props) {
98
- const userStore = useUserStore();
99
- const message = ref("\u6388\u6743\u767B\u5F55\u4E2D...");
100
- onMounted(async () => {
101
- const res = await props.authentication?.(props.type);
102
- if (res?.success) {
103
- userStore.setToken(res?.data?.accessToken, res?.data?.refreshToken);
104
- props?.redirectTo?.();
105
- } else {
106
- message.value = res?.msg ?? res?.message;
107
- }
108
- });
109
- return () => {
110
- return h(
111
- "div",
112
- {
113
- style: {
114
- display: "flex",
115
- justifyContent: "center",
116
- alignItems: "center",
117
- width: "100vw",
118
- height: "100vh"
119
- }
120
- },
121
- message.value
122
- );
123
- };
124
- }
125
- });
126
-
127
127
  // src/index.ts
128
- function createAuth2(options = {}) {
128
+ function withModule(auth, options = {}) {
129
+ const { authentication, redirect } = auth;
129
130
  const { redirectTo } = options;
130
- const { signIn, renderQRCode, authentication, redirect } = createAuth(options);
131
- function auth() {
132
- return {
133
- name: "pubinfo:auth",
134
- enforce: "pre",
135
- setup(ctx) {
136
- const { router } = ctx;
137
- const ROUTE_AUTH = {
138
- path: "/auth/:type",
139
- name: "Auth",
140
- component: Auth,
141
- meta: {
142
- whiteList: true,
143
- title: "\u6388\u6743\u767B\u5F55"
144
- },
145
- props: (route) => ({
146
- type: route.params.type,
147
- redirectTo() {
148
- router.push(redirectTo ?? "/");
149
- },
150
- authentication
151
- })
152
- };
153
- router.beforeEach((to) => {
154
- if (!router.hasRoute(ROUTE_AUTH.name)) {
155
- router.addRoute(ROUTE_AUTH);
156
- return to.fullPath;
157
- }
158
- if (to.name === ROUTE_AUTH.name) {
159
- cleanup();
160
- }
161
- if (to.name === "Login") {
162
- redirect();
163
- }
164
- });
165
- }
166
- };
167
- }
168
- ;
169
131
  return {
170
- /**
171
- * 前往登录
172
- * @param id 唯一值
173
- * @param options 登录时需要传递的参数
174
- */
175
- signIn,
176
- /**
177
- * 生成二维码
178
- * @param id 第三方的唯一值
179
- * @param options 生成二维码需要传递的参数
180
- * @param options.id `getElementById`中指定的`id`
181
- */
182
- renderQRCode,
183
- /**
184
- * 认证
185
- * @param id 第三方的唯一值
186
- */
187
- authentication,
188
- /**
189
- * 模块配置
190
- */
191
- auth
132
+ name: "pubinfo:auth",
133
+ enforce: "pre",
134
+ setup(ctx) {
135
+ const { router } = ctx;
136
+ const ROUTE_AUTH = {
137
+ path: "/auth/:type",
138
+ name: "Auth",
139
+ component: PageAuth,
140
+ meta: {
141
+ whiteList: true,
142
+ title: "\u6388\u6743\u767B\u5F55"
143
+ },
144
+ props: (route) => ({
145
+ type: route.params.type,
146
+ redirectTo() {
147
+ router.push(redirectTo ?? "/");
148
+ },
149
+ authentication
150
+ })
151
+ };
152
+ router.beforeEach((to) => {
153
+ if (!router.hasRoute(ROUTE_AUTH.name)) {
154
+ router.addRoute(ROUTE_AUTH);
155
+ return to.fullPath;
156
+ }
157
+ if (to.name === ROUTE_AUTH.name) {
158
+ cleanup();
159
+ }
160
+ if (to.name === "Login") {
161
+ redirect();
162
+ }
163
+ });
164
+ }
192
165
  };
193
166
  }
194
167
  export {
195
- createAuth2 as createAuth
168
+ createAuth,
169
+ withModule
196
170
  };
@@ -3,7 +3,7 @@ import { RouteLocationRaw } from 'vue-router';
3
3
  type Recordable = Record<string, any>;
4
4
  type Fn<T = any, K = any> = (params?: Recordable & T) => Promise<K> | K;
5
5
  type FnApi<T = any> = (params: Recordable & T, baseURL: string) => Promise<any>;
6
- interface AuthOptions extends AuthConfig {
6
+ interface AuthOptions {
7
7
  /** 登录后重定向至 */
8
8
  redirectTo?: RouteLocationRaw;
9
9
  }
@@ -47,4 +47,4 @@ interface Authorization {
47
47
  params?: Recordable;
48
48
  }
49
49
 
50
- export type { AuthOptions as A, Fn as F, ProviderUserConfig as P, Recordable as R, ThirdParty as T, FnApi as a, AuthConfig as b, ProviderConfig as c, Authorization as d };
50
+ 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 };
@@ -1,4 +1,4 @@
1
- import { P as ProviderUserConfig, c as ProviderConfig } from '../interface-C_qnbvmk.js';
1
+ import { P as ProviderUserConfig, c as ProviderConfig } from '../interface-BStwVrS7.js';
2
2
  import 'vue-router';
3
3
 
4
4
  /**
@@ -1,4 +1,4 @@
1
- import { F as Fn, c as ProviderConfig } from '../interface-C_qnbvmk.js';
1
+ import { F as Fn, c as ProviderConfig } from '../interface-BStwVrS7.js';
2
2
  import 'vue-router';
3
3
 
4
4
  interface CredentialsConfig {
@@ -1,4 +1,4 @@
1
- import { P as ProviderUserConfig, c as ProviderConfig } from '../interface-C_qnbvmk.js';
1
+ import { P as ProviderUserConfig, c as ProviderConfig } from '../interface-BStwVrS7.js';
2
2
  import 'vue-router';
3
3
 
4
4
  interface DingZJConfig extends ProviderUserConfig {
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.14",
4
+ "version": "2.0.0-beta.16",
5
5
  "exports": {
6
6
  ".": {
7
7
  "types": "./dist/index.d.ts",
@@ -20,11 +20,11 @@
20
20
  "src"
21
21
  ],
22
22
  "peerDependencies": {
23
- "pubinfo": "2.0.0-beta.14"
23
+ "pubinfo": "2.0.0-beta.16"
24
24
  },
25
25
  "devDependencies": {
26
26
  "tsup": "^8.4.0",
27
- "pubinfo": "2.0.0-beta.14"
27
+ "pubinfo": "2.0.0-beta.16"
28
28
  },
29
29
  "scripts": {
30
30
  "dev": "tsup --watch src",
package/src/core.ts CHANGED
@@ -2,7 +2,6 @@ import type { AuthConfig, ProviderUserConfig, Recordable, ThirdParty } from './i
2
2
 
3
3
  /**
4
4
  * 初始化
5
- * @param config 初始化配置
6
5
  */
7
6
  export function createAuth(config: AuthConfig = {}) {
8
7
  const {
package/src/index.ts CHANGED
@@ -1,86 +1,57 @@
1
1
  import type { ModuleOptions } from 'pubinfo';
2
2
  import type { RouteRecordRaw } from 'vue-router';
3
+ import type { createAuth } from './core';
3
4
  import type { AuthOptions } from './interface';
4
5
  import { cleanup } from 'pubinfo';
5
- import { createAuth as create } from './core';
6
- import { Auth } from './pages/auth';
6
+ import { PageAuth } from './pages/auth';
7
7
 
8
- export function createAuth(options: AuthOptions = {}) {
8
+ export function withModule(auth: ReturnType<typeof createAuth>, options: AuthOptions = {}): ModuleOptions {
9
+ const { authentication, redirect } = auth;
9
10
  const { redirectTo } = options;
10
- const { signIn, renderQRCode, authentication, redirect } = create(options);
11
11
 
12
- function auth(): ModuleOptions {
13
- return {
14
- name: 'pubinfo:auth',
15
- enforce: 'pre',
16
- setup(ctx) {
17
- const { router } = ctx;
18
-
19
- const ROUTE_AUTH: RouteRecordRaw = {
20
- path: '/auth/:type',
21
- name: 'Auth',
22
- component: Auth,
23
- meta: {
24
- whiteList: true,
25
- title: '授权登录',
12
+ return {
13
+ name: 'pubinfo:auth',
14
+ enforce: 'pre',
15
+ setup(ctx) {
16
+ const { router } = ctx;
17
+
18
+ const ROUTE_AUTH: RouteRecordRaw = {
19
+ path: '/auth/:type',
20
+ name: 'Auth',
21
+ component: PageAuth,
22
+ meta: {
23
+ whiteList: true,
24
+ title: '授权登录',
25
+ },
26
+ props: (route) => ({
27
+ type: route.params.type,
28
+ redirectTo() {
29
+ router.push(redirectTo ?? '/');
26
30
  },
27
- props: (route) => ({
28
- type: route.params.type,
29
- redirectTo() {
30
- router.push(redirectTo ?? '/');
31
- },
32
- authentication,
33
- }),
34
- };
31
+ authentication,
32
+ }),
33
+ };
35
34
 
36
- router.beforeEach(to => {
35
+ router.beforeEach(to => {
37
36
  // 注册静态页面
38
- if (!router.hasRoute(ROUTE_AUTH.name!)) {
39
- router.addRoute(ROUTE_AUTH);
40
- return to.fullPath;
41
- }
42
-
43
- // 前往单点登录前,清空登录状态
44
- if (to.name === ROUTE_AUTH.name) {
45
- cleanup();
46
- }
47
-
48
- // 前往登录前,重定向至统一登录页(若有)
49
- if (to.name === 'Login') {
50
- redirect();
51
- }
52
- });
53
- },
54
- };
55
- };
56
-
57
- return {
58
- /**
59
- * 前往登录
60
- * @param id 唯一值
61
- * @param options 登录时需要传递的参数
62
- */
63
- signIn,
64
-
65
- /**
66
- * 生成二维码
67
- * @param id 第三方的唯一值
68
- * @param options 生成二维码需要传递的参数
69
- * @param options.id `getElementById`中指定的`id`
70
- */
71
- renderQRCode,
72
-
73
- /**
74
- * 认证
75
- * @param id 第三方的唯一值
76
- */
77
- authentication,
78
-
79
- /**
80
- * 模块配置
81
- */
82
- auth,
37
+ if (!router.hasRoute(ROUTE_AUTH.name!)) {
38
+ router.addRoute(ROUTE_AUTH);
39
+ return to.fullPath;
40
+ }
41
+
42
+ // 前往单点登录前,清空登录状态
43
+ if (to.name === ROUTE_AUTH.name) {
44
+ cleanup();
45
+ }
46
+
47
+ // 前往登录前,重定向至统一登录页(若有)
48
+ if (to.name === 'Login') {
49
+ redirect();
50
+ }
51
+ });
52
+ },
83
53
  };
84
54
  }
85
55
 
56
+ export * from './core';
86
57
  export * from './interface';
package/src/interface.ts CHANGED
@@ -4,7 +4,7 @@ export type Recordable = Record<string, any>;
4
4
  export type Fn<T = any, K = any> = (params?: Recordable & T) => Promise<K> | K;
5
5
  export type FnApi<T = any> = (params: Recordable & T, baseURL: string) => Promise<any>;
6
6
 
7
- export interface AuthOptions extends AuthConfig {
7
+ export interface AuthOptions {
8
8
  /** 登录后重定向至 */
9
9
  redirectTo?: RouteLocationRaw
10
10
  }
package/src/pages/auth.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { useUserStore } from 'pubinfo';
2
2
  import { defineComponent, h, onMounted, ref } from 'vue';
3
3
 
4
- export const Auth = defineComponent({
4
+ export const PageAuth = defineComponent({
5
5
  props: {
6
6
  type: String,
7
7
  redirectTo: Function,
package/dist/index.cjs DELETED
@@ -1,221 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/index.ts
21
- var index_exports = {};
22
- __export(index_exports, {
23
- createAuth: () => createAuth2
24
- });
25
- module.exports = __toCommonJS(index_exports);
26
- var import_pubinfo2 = require("pubinfo");
27
-
28
- // src/core.ts
29
- function createAuth(config = {}) {
30
- const {
31
- baseURL = "",
32
- providers = []
33
- } = config;
34
- function getProvider(id) {
35
- const provider = id ? providers.find((provider2) => provider2.id === id) : providers[0];
36
- if (!provider) {
37
- throw new Error(`Provider '${id}' is not found.`);
38
- }
39
- return provider;
40
- }
41
- return {
42
- /**
43
- * 前往登录
44
- * @param id 唯一值
45
- * @param options 登录时需要传递的参数
46
- */
47
- async signIn(id, options) {
48
- const provider = getProvider(id);
49
- const { type, authorization } = provider;
50
- if (typeof authorization === "function") {
51
- return await authorization(options);
52
- }
53
- if (type === "oauth" || type === "custom") {
54
- const url = createUrl(provider);
55
- window.location.replace(url);
56
- }
57
- },
58
- /**
59
- * 生成二维码
60
- * @param id 第三方的唯一值
61
- * @param options 生成二维码需要传递的参数
62
- * @param options.id `getElementById`中指定的`id`
63
- */
64
- renderQRCode(id, options) {
65
- const provider = getProvider(id);
66
- const { type, initQRCode } = provider;
67
- if (type === "oauth" || type === "custom") {
68
- const url = createUrl(provider);
69
- initQRCode?.(url, options);
70
- }
71
- },
72
- /**
73
- * 认证
74
- * @param id 第三方的唯一值
75
- */
76
- async authentication(id) {
77
- const provider = getProvider(id);
78
- const { type, callbackUrl } = provider;
79
- const qs = window.location.href.split("?")?.[1] ?? "";
80
- const params = new URLSearchParams(qs);
81
- if (typeof callbackUrl === "function") {
82
- return await callbackUrl(Object.fromEntries(params.entries()), baseURL);
83
- }
84
- if (type === "oauth" || type === "cas" || type === "custom") {
85
- const response = await fetch(`${baseURL}${callbackUrl}?${params.toString()}`);
86
- return await response.json();
87
- }
88
- },
89
- /**
90
- * 重定向至统一登录页
91
- */
92
- redirect() {
93
- const provider = providers.find((provider2) => provider2.type === "cas");
94
- if (!provider) {
95
- return;
96
- }
97
- const url = createUrl(provider);
98
- window.location.replace(url);
99
- }
100
- };
101
- }
102
- function createUrl(provider) {
103
- const { authorization } = provider;
104
- if (typeof authorization === "function") {
105
- return "";
106
- }
107
- const url = new URL(authorization?.url ?? "");
108
- const params = new URLSearchParams(authorization?.params ?? {});
109
- return `${url.toString()}?${params.toString()}`;
110
- }
111
-
112
- // src/pages/auth.ts
113
- var import_pubinfo = require("pubinfo");
114
- var import_vue = require("vue");
115
- var Auth = (0, import_vue.defineComponent)({
116
- props: {
117
- type: String,
118
- redirectTo: Function,
119
- authentication: Function
120
- },
121
- setup(props) {
122
- const userStore = (0, import_pubinfo.useUserStore)();
123
- const message = (0, import_vue.ref)("\u6388\u6743\u767B\u5F55\u4E2D...");
124
- (0, import_vue.onMounted)(async () => {
125
- const res = await props.authentication?.(props.type);
126
- if (res?.success) {
127
- userStore.setToken(res?.data?.accessToken, res?.data?.refreshToken);
128
- props?.redirectTo?.();
129
- } else {
130
- message.value = res?.msg ?? res?.message;
131
- }
132
- });
133
- return () => {
134
- return (0, import_vue.h)(
135
- "div",
136
- {
137
- style: {
138
- display: "flex",
139
- justifyContent: "center",
140
- alignItems: "center",
141
- width: "100vw",
142
- height: "100vh"
143
- }
144
- },
145
- message.value
146
- );
147
- };
148
- }
149
- });
150
-
151
- // src/index.ts
152
- function createAuth2(options = {}) {
153
- const { redirectTo } = options;
154
- const { signIn, renderQRCode, authentication, redirect } = createAuth(options);
155
- function auth() {
156
- return {
157
- name: "pubinfo:auth",
158
- enforce: "pre",
159
- setup(ctx) {
160
- const { router } = ctx;
161
- const ROUTE_AUTH = {
162
- path: "/auth/:type",
163
- name: "Auth",
164
- component: Auth,
165
- meta: {
166
- whiteList: true,
167
- title: "\u6388\u6743\u767B\u5F55"
168
- },
169
- props: (route) => ({
170
- type: route.params.type,
171
- redirectTo() {
172
- router.push(redirectTo ?? "/");
173
- },
174
- authentication
175
- })
176
- };
177
- router.beforeEach((to) => {
178
- if (!router.hasRoute(ROUTE_AUTH.name)) {
179
- router.addRoute(ROUTE_AUTH);
180
- return to.fullPath;
181
- }
182
- if (to.name === ROUTE_AUTH.name) {
183
- (0, import_pubinfo2.cleanup)();
184
- }
185
- if (to.name === "Login") {
186
- redirect();
187
- }
188
- });
189
- }
190
- };
191
- }
192
- ;
193
- return {
194
- /**
195
- * 前往登录
196
- * @param id 唯一值
197
- * @param options 登录时需要传递的参数
198
- */
199
- signIn,
200
- /**
201
- * 生成二维码
202
- * @param id 第三方的唯一值
203
- * @param options 生成二维码需要传递的参数
204
- * @param options.id `getElementById`中指定的`id`
205
- */
206
- renderQRCode,
207
- /**
208
- * 认证
209
- * @param id 第三方的唯一值
210
- */
211
- authentication,
212
- /**
213
- * 模块配置
214
- */
215
- auth
216
- };
217
- }
218
- // Annotate the CommonJS export names for ESM import in node:
219
- 0 && (module.exports = {
220
- createAuth
221
- });
package/dist/index.d.cts DELETED
@@ -1,33 +0,0 @@
1
- import { A as AuthOptions, T as ThirdParty, R as Recordable } from './interface-C_qnbvmk.cjs';
2
- export { b as AuthConfig, d as Authorization, F as Fn, a as FnApi, c as ProviderConfig, P as ProviderUserConfig } from './interface-C_qnbvmk.cjs';
3
- import { ModuleOptions } from 'pubinfo';
4
- import 'vue-router';
5
-
6
- declare function createAuth(options?: AuthOptions): {
7
- /**
8
- * 前往登录
9
- * @param id 唯一值
10
- * @param options 登录时需要传递的参数
11
- */
12
- signIn: (id: ThirdParty, options?: Recordable) => Promise<any>;
13
- /**
14
- * 生成二维码
15
- * @param id 第三方的唯一值
16
- * @param options 生成二维码需要传递的参数
17
- * @param options.id `getElementById`中指定的`id`
18
- */
19
- renderQRCode: (id: ThirdParty, options: {
20
- id: string;
21
- } & Recordable) => void;
22
- /**
23
- * 认证
24
- * @param id 第三方的唯一值
25
- */
26
- authentication: (id: ThirdParty) => Promise<any>;
27
- /**
28
- * 模块配置
29
- */
30
- auth: () => ModuleOptions;
31
- };
32
-
33
- export { AuthOptions, Recordable, ThirdParty, createAuth };
@@ -1,50 +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 extends AuthConfig {
7
- /** 登录后重定向至 */
8
- redirectTo?: RouteLocationRaw;
9
- }
10
- interface AuthConfig {
11
- /** 接口的baseURL */
12
- baseURL?: string;
13
- providers?: ProviderConfig[];
14
- }
15
- /** 第三方类型 */
16
- type ThirdParty = string;
17
- type ProviderUserConfig = Partial<ProviderConfig>;
18
- interface ProviderConfig {
19
- /** 唯一值 */
20
- id: string;
21
- /** 名称 */
22
- name: string;
23
- /**
24
- * 协议类型
25
- * - `oauth` 第三方授权登录
26
- * - `cas` 统一账号登录
27
- * - `custom` 自定义
28
- */
29
- type: 'oauth' | 'cas' | 'custom';
30
- /** 授权登录地址 */
31
- authorization?: Authorization | Fn;
32
- /** `client_id` */
33
- clientId?: string;
34
- /** `redirect_uri` */
35
- redirectUri?: string;
36
- /** 授权登录接口 */
37
- callbackUrl?: string | FnApi;
38
- /** 初始化二维码 */
39
- initQRCode?: (url: string, params: {
40
- id: string;
41
- } & Recordable) => Promise<void> | void;
42
- }
43
- interface Authorization {
44
- /** 授权登录地址 */
45
- url: string;
46
- /** 授权登录参数 */
47
- params?: Recordable;
48
- }
49
-
50
- export type { AuthOptions as A, Fn as F, ProviderUserConfig as P, Recordable as R, ThirdParty as T, FnApi as a, AuthConfig as b, ProviderConfig as c, Authorization as d };
@@ -1,43 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/providers/4A.ts
21
- var A_exports = {};
22
- __export(A_exports, {
23
- default: () => FourA
24
- });
25
- module.exports = __toCommonJS(A_exports);
26
- function FourA(options) {
27
- const { clientId, redirectUri } = options;
28
- return {
29
- id: "4A",
30
- name: "4A\u767B\u5F55",
31
- type: "oauth",
32
- authorization: {
33
- url: "http://134.108.76.137:7001/index",
34
- params: {
35
- response_type: "code",
36
- client_id: clientId,
37
- redirect_uri: redirectUri
38
- }
39
- },
40
- callbackUrl: "/bs/loginBy4a",
41
- ...options
42
- };
43
- }
@@ -1,9 +0,0 @@
1
- import { P as ProviderUserConfig, c as ProviderConfig } from '../interface-C_qnbvmk.cjs';
2
- import 'vue-router';
3
-
4
- /**
5
- * 4A登录
6
- */
7
- declare function FourA(options: ProviderUserConfig): ProviderConfig;
8
-
9
- export { FourA as default };
@@ -1,34 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/providers/credentials.ts
21
- var credentials_exports = {};
22
- __export(credentials_exports, {
23
- default: () => Credentials
24
- });
25
- module.exports = __toCommonJS(credentials_exports);
26
- function Credentials(options) {
27
- const { authorize } = options;
28
- return {
29
- id: "credentials",
30
- name: "\u51ED\u8BC1\u767B\u5F55",
31
- type: "custom",
32
- authorization: authorize
33
- };
34
- }
@@ -1,12 +0,0 @@
1
- import { F as Fn, c as ProviderConfig } from '../interface-C_qnbvmk.cjs';
2
- import 'vue-router';
3
-
4
- interface CredentialsConfig {
5
- authorize: Fn<any>;
6
- }
7
- /**
8
- * 凭证登录
9
- */
10
- declare function Credentials(options: CredentialsConfig): ProviderConfig;
11
-
12
- export { Credentials as default };
@@ -1,80 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/providers/ding-zj.ts
21
- var ding_zj_exports = {};
22
- __export(ding_zj_exports, {
23
- default: () => DingZJ
24
- });
25
- module.exports = __toCommonJS(ding_zj_exports);
26
- function DingZJ(options) {
27
- const { clientId, redirectUri } = options;
28
- const authorization = {
29
- /** 跳转外部页面 */
30
- redirect: {
31
- url: "https://openplatform-pro.ding.zj.gov.cn/oauth2/auth.htm",
32
- params: {
33
- response_type: "code",
34
- client_id: clientId,
35
- redirect_uri: redirectUri,
36
- scope: "get_user_info",
37
- authType: "QRCODE"
38
- }
39
- },
40
- /** 内嵌二维码 */
41
- embed: {
42
- url: "https://login-pro.ding.zj.gov.cn/oauth2/auth.htm",
43
- params: {
44
- response_type: "code",
45
- client_id: clientId,
46
- redirect_uri: redirectUri,
47
- scope: "get_user_info",
48
- authType: "QRCODE",
49
- embedMode: "true"
50
- }
51
- }
52
- };
53
- const initQRCode = (url, options2) => {
54
- const target = document.getElementById(options2.id);
55
- if (!target) {
56
- throw new Error(`\u672A\u627E\u5230id\u4E3A${options2.id}\u7684DOM\u5143\u7D20`);
57
- }
58
- const iframe = document.createElement("iframe");
59
- iframe.src = url;
60
- iframe.width = "200";
61
- iframe.height = "200";
62
- document.appendChild(iframe);
63
- window.addEventListener("message", (e) => {
64
- if (options2.redirectUri) {
65
- const url2 = new URL(options2.redirectUri);
66
- url2.search = new URLSearchParams(e.data).toString();
67
- window.location.href = url2.toString();
68
- }
69
- });
70
- };
71
- return {
72
- id: "ding-zj",
73
- name: "\u6D59\u653F\u9489\u767B\u5F55",
74
- type: "oauth",
75
- authorization: authorization[options.mode],
76
- callbackUrl: "/bs/loginByDingZJ",
77
- initQRCode: options.mode === "embed" ? initQRCode : void 0,
78
- ...options
79
- };
80
- }
@@ -1,17 +0,0 @@
1
- import { P as ProviderUserConfig, c as ProviderConfig } from '../interface-C_qnbvmk.cjs';
2
- import 'vue-router';
3
-
4
- interface DingZJConfig extends ProviderUserConfig {
5
- /**
6
- * 登录方式
7
- * - `redirect` 跳转浙政钉的扫码页面
8
- * - `embed` 内嵌浙政钉的登录二维码
9
- */
10
- mode: 'redirect' | 'embed';
11
- }
12
- /**
13
- * 浙政钉扫码登录
14
- */
15
- declare function DingZJ(options: DingZJConfig): ProviderConfig;
16
-
17
- export { DingZJ as default };