@pubinfo/module-auth 2.1.7 → 2.1.9

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.
@@ -1,7 +1,7 @@
1
- import { RouteLocationRaw } from '../../../node_modules/.pnpm/vue-router@4.5.1_vue@3.5.17_typescript@5.8.3_/node_modules/vue-router';
1
+ import type { RouteLocationRaw } from 'vue-router';
2
2
  export type Recordable = Record<string, any>;
3
3
  export type Fn<T = any, K = any> = (params?: Recordable & T) => Promise<K> | K;
4
- export type FnApi<T = any> = (params: Recordable & T, baseURL: string) => Promise<any>;
4
+ export type FnApi<T = any, R = any> = (params: Recordable & T, baseURL: string) => Promise<R>;
5
5
  export interface AuthOptions {
6
6
  /** 登录后默认重定向至 */
7
7
  redirectTo?: RouteLocationRaw | Fn;
@@ -37,7 +37,7 @@ export interface ProviderOptions {
37
37
  /** 授权登录地址 */
38
38
  signIn?: Authorization | Fn;
39
39
  /** 授权登录接口 */
40
- authenticate?: string | FnApi;
40
+ authenticate?: string | FnApi<any, LoginResponse>;
41
41
  /** 初始化二维码 */
42
42
  initQRCode?: (url: string, params: {
43
43
  id: string;
@@ -49,3 +49,12 @@ export interface Authorization {
49
49
  /** 授权登录参数 */
50
50
  params?: Recordable;
51
51
  }
52
+ export interface LoginResponse {
53
+ success?: boolean;
54
+ data: {
55
+ accessToken: string;
56
+ refreshToken: string;
57
+ [key: string]: any;
58
+ };
59
+ msg?: string;
60
+ }
@@ -1,11 +1,11 @@
1
- export declare const PageAuth: import('../../../../node_modules/.pnpm/vue@3.5.17_typescript@5.8.3/node_modules/vue').DefineComponent<import('../../../../node_modules/.pnpm/vue@3.5.17_typescript@5.8.3/node_modules/vue').ExtractPropTypes<{
1
+ export declare const PageAuth: import("vue").DefineComponent<globalThis.ExtractPropTypes<{
2
2
  type: StringConstructor;
3
3
  redirectTo: FunctionConstructor;
4
4
  authenticate: FunctionConstructor;
5
- }>, () => import('../../../../node_modules/.pnpm/vue@3.5.17_typescript@5.8.3/node_modules/vue').VNode<import('../../../../node_modules/.pnpm/vue@3.5.17_typescript@5.8.3/node_modules/vue').RendererNode, import('../../../../node_modules/.pnpm/vue@3.5.17_typescript@5.8.3/node_modules/vue').RendererElement, {
5
+ }>, () => globalThis.VNode<import("vue").RendererNode, import("vue").RendererElement, {
6
6
  [key: string]: any;
7
- }>, {}, {}, {}, import('../../../../node_modules/.pnpm/vue@3.5.17_typescript@5.8.3/node_modules/vue').ComponentOptionsMixin, import('../../../../node_modules/.pnpm/vue@3.5.17_typescript@5.8.3/node_modules/vue').ComponentOptionsMixin, {}, string, import('../../../../node_modules/.pnpm/vue@3.5.17_typescript@5.8.3/node_modules/vue').PublicProps, Readonly<import('../../../../node_modules/.pnpm/vue@3.5.17_typescript@5.8.3/node_modules/vue').ExtractPropTypes<{
7
+ }>, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<globalThis.ExtractPropTypes<{
8
8
  type: StringConstructor;
9
9
  redirectTo: FunctionConstructor;
10
10
  authenticate: FunctionConstructor;
11
- }>> & Readonly<{}>, {}, {}, {}, {}, string, import('../../../../node_modules/.pnpm/vue@3.5.17_typescript@5.8.3/node_modules/vue').ComponentProvideOptions, true, {}, any>;
11
+ }>> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
@@ -1,4 +1,4 @@
1
- import { ProviderOptions, ProviderUserOptions } from '../interface';
1
+ import type { ProviderOptions, ProviderUserOptions } from '../interface';
2
2
  export interface FourAOptions extends ProviderUserOptions {
3
3
  /** `client_id` */
4
4
  clientId?: string;
@@ -1,21 +1,19 @@
1
- function i(e) {
2
- const { clientId: t, redirectUri: r } = e;
3
- return {
4
- id: "4A",
5
- name: "4A登录",
6
- type: "oauth",
7
- signIn: {
8
- url: "http://134.108.76.137:7001/index",
9
- params: {
10
- response_type: "code",
11
- client_id: t,
12
- redirect_uri: r
13
- }
14
- },
15
- authenticate: "/bs/loginBy4a",
16
- ...e
17
- };
1
+ function FourA(e) {
2
+ let { clientId: t, redirectUri: n } = e;
3
+ return {
4
+ id: "4A",
5
+ name: "4A登录",
6
+ type: "oauth",
7
+ signIn: {
8
+ url: "http://134.108.76.137:7001/index",
9
+ params: {
10
+ response_type: "code",
11
+ client_id: t,
12
+ redirect_uri: n
13
+ }
14
+ },
15
+ authenticate: "/bs/loginBy4a",
16
+ ...e
17
+ };
18
18
  }
19
- export {
20
- i as default
21
- };
19
+ export { FourA as default };
@@ -1,4 +1,4 @@
1
- import { ProviderOptions, ProviderUserOptions } from '../interface';
1
+ import type { ProviderOptions, ProviderUserOptions } from '../interface';
2
2
  export interface CredentialsOptions extends ProviderUserOptions {
3
3
  }
4
4
  /**
@@ -1,11 +1,9 @@
1
- function t(e) {
2
- return {
3
- id: "credentials",
4
- name: "凭证登录",
5
- type: "custom",
6
- ...e
7
- };
1
+ function Credentials(e) {
2
+ return {
3
+ id: "credentials",
4
+ name: "凭证登录",
5
+ type: "custom",
6
+ ...e
7
+ };
8
8
  }
9
- export {
10
- t as default
11
- };
9
+ export { Credentials as default };
@@ -1,4 +1,4 @@
1
- import { ProviderOptions, ProviderUserOptions } from '../interface';
1
+ import type { ProviderOptions, ProviderUserOptions } from '../interface';
2
2
  export interface DingZJOptions extends ProviderUserOptions {
3
3
  /**
4
4
  * 登录方式
@@ -1,49 +1,44 @@
1
- function g(e) {
2
- const { clientId: i, redirectUri: n } = e, a = {
3
- /** 跳转外部页面 */
4
- redirect: {
5
- url: "https://openplatform-pro.ding.zj.gov.cn/oauth2/auth.htm",
6
- params: {
7
- response_type: "code",
8
- client_id: i,
9
- redirect_uri: n,
10
- scope: "get_user_info",
11
- authType: "QRCODE"
12
- }
13
- },
14
- /** 内嵌二维码 */
15
- embed: {
16
- url: "https://login-pro.ding.zj.gov.cn/oauth2/auth.htm",
17
- params: {
18
- response_type: "code",
19
- client_id: i,
20
- redirect_uri: n,
21
- scope: "get_user_info",
22
- authType: "QRCODE",
23
- embedMode: "true"
24
- }
25
- }
26
- }, o = (c, t) => {
27
- if (!document.getElementById(t.id))
28
- throw new Error(`未找到id为${t.id}的DOM元素`);
29
- const r = document.createElement("iframe");
30
- r.src = c, r.width = "200", r.height = "200", document.appendChild(r), window.addEventListener("message", (s) => {
31
- if (t.redirectUri) {
32
- const d = new URL(t.redirectUri);
33
- d.search = new URLSearchParams(s.data).toString(), window.location.href = d.toString();
34
- }
35
- });
36
- };
37
- return {
38
- id: "ding-zj",
39
- name: "浙政钉登录",
40
- type: "oauth",
41
- signIn: a[e.mode],
42
- authenticate: "/bs/loginByDingZJ",
43
- initQRCode: e.mode === "embed" ? o : void 0,
44
- ...e
45
- };
1
+ function DingZJ(e) {
2
+ let { clientId: t, redirectUri: n } = e;
3
+ return {
4
+ id: "ding-zj",
5
+ name: "浙政钉登录",
6
+ type: "oauth",
7
+ signIn: {
8
+ redirect: {
9
+ url: "https://openplatform-pro.ding.zj.gov.cn/oauth2/auth.htm",
10
+ params: {
11
+ response_type: "code",
12
+ client_id: t,
13
+ redirect_uri: n,
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: t,
23
+ redirect_uri: n,
24
+ scope: "get_user_info",
25
+ authType: "QRCODE",
26
+ embedMode: "true"
27
+ }
28
+ }
29
+ }[e.mode],
30
+ authenticate: "/bs/loginByDingZJ",
31
+ initQRCode: e.mode === "embed" ? (e, t) => {
32
+ if (!document.getElementById(t.id)) throw Error(`未找到id为${t.id}的DOM元素`);
33
+ let n = document.createElement("iframe");
34
+ n.src = e, n.width = "200", n.height = "200", document.appendChild(n), window.addEventListener("message", (e) => {
35
+ if (t.redirectUri) {
36
+ let n = new URL(t.redirectUri);
37
+ n.search = new URLSearchParams(e.data).toString(), window.location.href = n.toString();
38
+ }
39
+ });
40
+ } : void 0,
41
+ ...e
42
+ };
46
43
  }
47
- export {
48
- g as default
49
- };
44
+ export { DingZJ as default };
@@ -1,4 +1,4 @@
1
- import { ProviderOptions, ProviderUserOptions } from '../interface';
1
+ import type { ProviderOptions, ProviderUserOptions } from '@/interface';
2
2
  export interface SsoOptions extends ProviderUserOptions {
3
3
  /**
4
4
  * 登录类型,根据调用 `/app/oauth/generateCode` 接口时传递的 `grantType` 参数值判断:
@@ -1,23 +1,18 @@
1
- function o(t = {}) {
2
- const { loginType: e = "defaultOauth2" } = t;
3
- return {
4
- id: "sso",
5
- name: "SSO统一账号登录",
6
- type: "custom",
7
- authenticate: async (a, n) => await (await fetch(
8
- `${n}/auth/ssoLogin`,
9
- {
10
- headers: { "Content-Type": "application/json" },
11
- method: "POST",
12
- body: JSON.stringify({
13
- ...a,
14
- loginType: e
15
- })
16
- }
17
- )).json(),
18
- ...t
19
- };
1
+ function Sso(e = {}) {
2
+ let { loginType: t = "defaultOauth2" } = e;
3
+ return {
4
+ id: "sso",
5
+ name: "SSO统一账号登录",
6
+ type: "custom",
7
+ authenticate: async (e, n) => await (await fetch(`${n}/auth/ssoLogin`, {
8
+ headers: { "Content-Type": "application/json" },
9
+ method: "POST",
10
+ body: JSON.stringify({
11
+ ...e,
12
+ loginType: t
13
+ })
14
+ })).json(),
15
+ ...e
16
+ };
20
17
  }
21
- export {
22
- o as default
23
- };
18
+ export { Sso 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.1.7",
4
+ "version": "2.1.9",
5
5
  "exports": {
6
6
  ".": {
7
7
  "types": "./dist/index.d.ts",
@@ -23,10 +23,10 @@
23
23
  "node": "^20.19.0 || >=22.12.0"
24
24
  },
25
25
  "peerDependencies": {
26
- "pubinfo": "2.1.7"
26
+ "pubinfo": "2.1.9"
27
27
  },
28
28
  "devDependencies": {
29
- "pubinfo": "2.1.7"
29
+ "pubinfo": "2.1.9"
30
30
  },
31
31
  "scripts": {
32
32
  "dev": "pubinfo build --watch",
package/src/interface.ts CHANGED
@@ -2,7 +2,7 @@ import type { RouteLocationRaw } from 'vue-router';
2
2
 
3
3
  export type Recordable = Record<string, any>;
4
4
  export type Fn<T = any, K = any> = (params?: Recordable & T) => Promise<K> | K;
5
- export type FnApi<T = any> = (params: Recordable & T, baseURL: string) => Promise<any>;
5
+ export type FnApi<T = any, R = any> = (params: Recordable & T, baseURL: string) => Promise<R>;
6
6
 
7
7
  export interface AuthOptions {
8
8
  /** 登录后默认重定向至 */
@@ -50,7 +50,7 @@ export interface ProviderOptions {
50
50
  signIn?: Authorization | Fn
51
51
 
52
52
  /** 授权登录接口 */
53
- authenticate?: string | FnApi
53
+ authenticate?: string | FnApi<any, LoginResponse>
54
54
 
55
55
  /** 初始化二维码 */
56
56
  initQRCode?: (url: string, params: { id: string } & Recordable) => Promise<void> | void
@@ -63,3 +63,13 @@ export interface Authorization {
63
63
  /** 授权登录参数 */
64
64
  params?: Recordable
65
65
  }
66
+
67
+ export interface LoginResponse {
68
+ success?: boolean
69
+ data: {
70
+ accessToken: string
71
+ refreshToken: string
72
+ [key: string]: any
73
+ }
74
+ msg?: string
75
+ }