@pubinfo/module-auth 2.0.0-rc.2 → 2.0.0-rc.3
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/components/LoginWithFourA/index.d.ts +15 -0
- package/dist/components/RedirectLogin/index.d.ts +11 -0
- package/dist/context.d.ts +3 -0
- package/dist/core.d.ts +30 -0
- package/dist/index.d.ts +6 -34
- package/dist/index.js +114 -135
- package/dist/interface.d.ts +55 -0
- package/dist/pages/auth.d.ts +11 -0
- package/dist/providers/4A.d.ts +2 -7
- package/dist/providers/4A.js +6 -12
- package/dist/providers/credentials.d.ts +4 -7
- package/dist/providers/credentials.js +4 -10
- package/dist/providers/ding-zj.d.ts +9 -12
- package/dist/providers/ding-zj.js +18 -31
- package/package.json +6 -5
- package/src/assets/images/4A.png +0 -0
- package/src/components/LoginWithFourA/index.ts +16 -0
- package/src/components/RedirectLogin/index.ts +42 -0
- package/src/core.ts +1 -1
- package/src/index.ts +9 -1
- package/dist/interface-CqwWb8Fb.d.ts +0 -59
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { RouteLocationRaw } from '../../../node_modules/.pnpm/vue-router@4.5.1_vue@3.5.17_typescript@5.8.3_/node_modules/vue-router';
|
|
2
|
+
export type Recordable = Record<string, any>;
|
|
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>;
|
|
5
|
+
export interface AuthOptions {
|
|
6
|
+
/** 登录后重定向至 */
|
|
7
|
+
redirectTo?: RouteLocationRaw;
|
|
8
|
+
/** 页面配置 */
|
|
9
|
+
pages?: {
|
|
10
|
+
/** 默认登录页 */
|
|
11
|
+
signIn?: RouteLocationRaw;
|
|
12
|
+
};
|
|
13
|
+
/** 接口的baseURL */
|
|
14
|
+
baseURL: string;
|
|
15
|
+
providers?: ProviderConfig[];
|
|
16
|
+
}
|
|
17
|
+
export interface InternalContext {
|
|
18
|
+
/** 接口的baseURL */
|
|
19
|
+
baseURL: string;
|
|
20
|
+
providers?: ProviderConfig[];
|
|
21
|
+
}
|
|
22
|
+
/** 第三方类型 */
|
|
23
|
+
export type ThirdParty = string;
|
|
24
|
+
export type ProviderUserConfig = Partial<ProviderConfig>;
|
|
25
|
+
export interface ProviderConfig {
|
|
26
|
+
/** 唯一值 */
|
|
27
|
+
id: string;
|
|
28
|
+
/** 名称 */
|
|
29
|
+
name: string;
|
|
30
|
+
/**
|
|
31
|
+
* 协议类型
|
|
32
|
+
* - `oauth` 第三方授权登录
|
|
33
|
+
* - `cas` 统一账号登录
|
|
34
|
+
* - `custom` 自定义
|
|
35
|
+
*/
|
|
36
|
+
type: 'oauth' | 'cas' | 'custom';
|
|
37
|
+
/** 授权登录地址 */
|
|
38
|
+
authorization?: Authorization | Fn;
|
|
39
|
+
/** `client_id` */
|
|
40
|
+
clientId?: string;
|
|
41
|
+
/** `redirect_uri` */
|
|
42
|
+
redirectUri?: string;
|
|
43
|
+
/** 授权登录接口 */
|
|
44
|
+
callbackUrl?: string | FnApi;
|
|
45
|
+
/** 初始化二维码 */
|
|
46
|
+
initQRCode?: (url: string, params: {
|
|
47
|
+
id: string;
|
|
48
|
+
} & Recordable) => Promise<void> | void;
|
|
49
|
+
}
|
|
50
|
+
export interface Authorization {
|
|
51
|
+
/** 授权登录地址 */
|
|
52
|
+
url: string;
|
|
53
|
+
/** 授权登录参数 */
|
|
54
|
+
params?: Recordable;
|
|
55
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare const PageAuth: import('../../../../node_modules/.pnpm/vue@3.5.17_typescript@5.8.3/node_modules/vue').DefineComponent<globalThis.ExtractPropTypes<{
|
|
2
|
+
type: StringConstructor;
|
|
3
|
+
redirectTo: FunctionConstructor;
|
|
4
|
+
authentication: FunctionConstructor;
|
|
5
|
+
}>, () => globalThis.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, {
|
|
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<globalThis.ExtractPropTypes<{
|
|
8
|
+
type: StringConstructor;
|
|
9
|
+
redirectTo: FunctionConstructor;
|
|
10
|
+
authentication: FunctionConstructor;
|
|
11
|
+
}>> & Readonly<{}>, {}, {}, {}, {}, string, import('../../../../node_modules/.pnpm/vue@3.5.17_typescript@5.8.3/node_modules/vue').ComponentProvideOptions, true, {}, any>;
|
package/dist/providers/4A.d.ts
CHANGED
|
@@ -1,10 +1,5 @@
|
|
|
1
|
-
import { ProviderConfig, ProviderUserConfig } from
|
|
2
|
-
|
|
3
|
-
//#region src/providers/4A.d.ts
|
|
4
|
-
|
|
1
|
+
import { ProviderConfig, ProviderUserConfig } from '../interface';
|
|
5
2
|
/**
|
|
6
3
|
* 4A登录
|
|
7
4
|
*/
|
|
8
|
-
|
|
9
|
-
//#endregion
|
|
10
|
-
export { FourA as default };
|
|
5
|
+
export default function FourA(options: ProviderUserConfig): ProviderConfig;
|
package/dist/providers/4A.js
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
* 4A登录
|
|
4
|
-
*/
|
|
5
|
-
function FourA(options) {
|
|
6
|
-
const { clientId, redirectUri } = options;
|
|
1
|
+
function e(e) {
|
|
2
|
+
let { clientId: t, redirectUri: n } = e;
|
|
7
3
|
return {
|
|
8
4
|
id: "4A",
|
|
9
5
|
name: "4A登录",
|
|
@@ -12,14 +8,12 @@ function FourA(options) {
|
|
|
12
8
|
url: "http://134.108.76.137:7001/index",
|
|
13
9
|
params: {
|
|
14
10
|
response_type: "code",
|
|
15
|
-
client_id:
|
|
16
|
-
redirect_uri:
|
|
11
|
+
client_id: t,
|
|
12
|
+
redirect_uri: n
|
|
17
13
|
}
|
|
18
14
|
},
|
|
19
15
|
callbackUrl: "/bs/loginBy4a",
|
|
20
|
-
...
|
|
16
|
+
...e
|
|
21
17
|
};
|
|
22
18
|
}
|
|
23
|
-
|
|
24
|
-
//#endregion
|
|
25
|
-
export { FourA as default };
|
|
19
|
+
export { e as default };
|
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
import { Fn, ProviderConfig } from
|
|
2
|
-
|
|
3
|
-
//#region src/providers/credentials.d.ts
|
|
1
|
+
import { Fn, ProviderConfig } from '../interface';
|
|
4
2
|
interface CredentialsConfig {
|
|
5
|
-
|
|
3
|
+
authorize: Fn<any>;
|
|
6
4
|
}
|
|
7
5
|
/**
|
|
8
6
|
* 凭证登录
|
|
9
7
|
*/
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
export { Credentials as default };
|
|
8
|
+
export default function Credentials(options: CredentialsConfig): ProviderConfig;
|
|
9
|
+
export {};
|
|
@@ -1,16 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
* 凭证登录
|
|
4
|
-
*/
|
|
5
|
-
function Credentials(options) {
|
|
6
|
-
const { authorize } = options;
|
|
1
|
+
function e(e) {
|
|
2
|
+
let { authorize: t } = e;
|
|
7
3
|
return {
|
|
8
4
|
id: "credentials",
|
|
9
5
|
name: "凭证登录",
|
|
10
6
|
type: "custom",
|
|
11
|
-
authorization:
|
|
7
|
+
authorization: t
|
|
12
8
|
};
|
|
13
9
|
}
|
|
14
|
-
|
|
15
|
-
//#endregion
|
|
16
|
-
export { Credentials as default };
|
|
10
|
+
export { e as default };
|
|
@@ -1,17 +1,14 @@
|
|
|
1
|
-
import { ProviderConfig, ProviderUserConfig } from
|
|
2
|
-
|
|
3
|
-
//#region src/providers/ding-zj.d.ts
|
|
1
|
+
import { ProviderConfig, ProviderUserConfig } from '../interface';
|
|
4
2
|
interface DingZJConfig extends ProviderUserConfig {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
3
|
+
/**
|
|
4
|
+
* 登录方式
|
|
5
|
+
* - `redirect` 跳转浙政钉的扫码页面
|
|
6
|
+
* - `embed` 内嵌浙政钉的登录二维码
|
|
7
|
+
*/
|
|
8
|
+
mode: 'redirect' | 'embed';
|
|
11
9
|
}
|
|
12
10
|
/**
|
|
13
11
|
* 浙政钉扫码登录
|
|
14
12
|
*/
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
export { DingZJ as default };
|
|
13
|
+
export default function DingZJ(options: DingZJConfig): ProviderConfig;
|
|
14
|
+
export {};
|
|
@@ -1,16 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
* 浙政钉扫码登录
|
|
4
|
-
*/
|
|
5
|
-
function DingZJ(options) {
|
|
6
|
-
const { clientId, redirectUri } = options;
|
|
7
|
-
const authorization = {
|
|
1
|
+
function e(e) {
|
|
2
|
+
let { clientId: t, redirectUri: n } = e, r = {
|
|
8
3
|
redirect: {
|
|
9
4
|
url: "https://openplatform-pro.ding.zj.gov.cn/oauth2/auth.htm",
|
|
10
5
|
params: {
|
|
11
6
|
response_type: "code",
|
|
12
|
-
client_id:
|
|
13
|
-
redirect_uri:
|
|
7
|
+
client_id: t,
|
|
8
|
+
redirect_uri: n,
|
|
14
9
|
scope: "get_user_info",
|
|
15
10
|
authType: "QRCODE"
|
|
16
11
|
}
|
|
@@ -19,27 +14,21 @@ function DingZJ(options) {
|
|
|
19
14
|
url: "https://login-pro.ding.zj.gov.cn/oauth2/auth.htm",
|
|
20
15
|
params: {
|
|
21
16
|
response_type: "code",
|
|
22
|
-
client_id:
|
|
23
|
-
redirect_uri:
|
|
17
|
+
client_id: t,
|
|
18
|
+
redirect_uri: n,
|
|
24
19
|
scope: "get_user_info",
|
|
25
20
|
authType: "QRCODE",
|
|
26
21
|
embedMode: "true"
|
|
27
22
|
}
|
|
28
23
|
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
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();
|
|
24
|
+
}, i = (e, t) => {
|
|
25
|
+
let n = document.getElementById(t.id);
|
|
26
|
+
if (!n) throw Error(`未找到id为${t.id}的DOM元素`);
|
|
27
|
+
let r = document.createElement("iframe");
|
|
28
|
+
r.src = e, r.width = "200", r.height = "200", document.appendChild(r), window.addEventListener("message", (e) => {
|
|
29
|
+
if (t.redirectUri) {
|
|
30
|
+
let n = new URL(t.redirectUri);
|
|
31
|
+
n.search = new URLSearchParams(e.data).toString(), window.location.href = n.toString();
|
|
43
32
|
}
|
|
44
33
|
});
|
|
45
34
|
};
|
|
@@ -47,12 +36,10 @@ function DingZJ(options) {
|
|
|
47
36
|
id: "ding-zj",
|
|
48
37
|
name: "浙政钉登录",
|
|
49
38
|
type: "oauth",
|
|
50
|
-
authorization:
|
|
39
|
+
authorization: r[e.mode],
|
|
51
40
|
callbackUrl: "/bs/loginByDingZJ",
|
|
52
|
-
initQRCode:
|
|
53
|
-
...
|
|
41
|
+
initQRCode: e.mode === "embed" ? i : void 0,
|
|
42
|
+
...e
|
|
54
43
|
};
|
|
55
44
|
}
|
|
56
|
-
|
|
57
|
-
//#endregion
|
|
58
|
-
export { DingZJ as default };
|
|
45
|
+
export { e 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-rc.
|
|
4
|
+
"version": "2.0.0-rc.3",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
7
7
|
"types": "./dist/index.d.ts",
|
|
@@ -20,13 +20,14 @@
|
|
|
20
20
|
"src"
|
|
21
21
|
],
|
|
22
22
|
"peerDependencies": {
|
|
23
|
-
"pubinfo": "2.0.0-rc.
|
|
23
|
+
"pubinfo": "2.0.0-rc.3"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"pubinfo": "2.0.0-rc.
|
|
26
|
+
"pubinfo": "2.0.0-rc.3"
|
|
27
27
|
},
|
|
28
28
|
"scripts": {
|
|
29
|
-
"dev": "
|
|
30
|
-
"build": "
|
|
29
|
+
"dev": "pubinfo build --watch",
|
|
30
|
+
"build": "pubinfo build",
|
|
31
|
+
"generate": "pubinfo generate"
|
|
31
32
|
}
|
|
32
33
|
}
|
|
Binary file
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { defineComponent, h } from 'vue';
|
|
2
|
+
import _4APNG from '@/assets/images/4A.png';
|
|
3
|
+
import { RedirectLogin } from '../RedirectLogin';
|
|
4
|
+
|
|
5
|
+
export const LoginWithFourA = defineComponent({
|
|
6
|
+
name: 'LoginWithFourA',
|
|
7
|
+
props: {
|
|
8
|
+
color: {
|
|
9
|
+
type: String,
|
|
10
|
+
default: '#1677FF',
|
|
11
|
+
},
|
|
12
|
+
},
|
|
13
|
+
setup(props) {
|
|
14
|
+
return () => h(RedirectLogin, { id: '4A', src: _4APNG, color: props.color });
|
|
15
|
+
},
|
|
16
|
+
});
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { defineComponent, h } from 'vue';
|
|
2
|
+
import { getProvider, signIn } from '@/core';
|
|
3
|
+
|
|
4
|
+
export const RedirectLogin = defineComponent({
|
|
5
|
+
name: 'RedirectLogin',
|
|
6
|
+
props: {
|
|
7
|
+
id: String,
|
|
8
|
+
src: String,
|
|
9
|
+
color: String,
|
|
10
|
+
},
|
|
11
|
+
setup(props) {
|
|
12
|
+
const provider = getProvider(props.id);
|
|
13
|
+
return () => {
|
|
14
|
+
return h('div', [
|
|
15
|
+
h(
|
|
16
|
+
'div',
|
|
17
|
+
{ style: { padding: '3rem' } },
|
|
18
|
+
h('img', { src: props.src, class: 'w-full' }),
|
|
19
|
+
),
|
|
20
|
+
h(
|
|
21
|
+
'button',
|
|
22
|
+
{
|
|
23
|
+
style: {
|
|
24
|
+
width: '100%',
|
|
25
|
+
color: '#ffffff',
|
|
26
|
+
cursor: 'pointer',
|
|
27
|
+
border: '0',
|
|
28
|
+
borderRadius: '0.25rem',
|
|
29
|
+
padding: '0.75rem 1.25rem',
|
|
30
|
+
fontSize: '0.875rem',
|
|
31
|
+
lineHeight: '1.25rem',
|
|
32
|
+
letterSpacing: '0.1em',
|
|
33
|
+
backgroundColor: props.color,
|
|
34
|
+
},
|
|
35
|
+
onClick: () => signIn(provider.id),
|
|
36
|
+
},
|
|
37
|
+
`前往${provider.name}`,
|
|
38
|
+
),
|
|
39
|
+
]);
|
|
40
|
+
};
|
|
41
|
+
},
|
|
42
|
+
});
|
package/src/core.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { ctx } from './context';
|
|
|
5
5
|
* 获取指定的 `Provider`
|
|
6
6
|
* @param id
|
|
7
7
|
*/
|
|
8
|
-
function getProvider(id?: ThirdParty) {
|
|
8
|
+
export function getProvider(id?: ThirdParty) {
|
|
9
9
|
const { providers } = ctx.use();
|
|
10
10
|
const provider = id ? providers?.find(provider => provider.id === id) : providers?.[0];
|
|
11
11
|
if (!provider) {
|
package/src/index.ts
CHANGED
|
@@ -63,5 +63,13 @@ export function auth(options: AuthOptions): ModuleOptions {
|
|
|
63
63
|
};
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
-
export
|
|
66
|
+
export { LoginWithFourA } from './components/LoginWithFourA';
|
|
67
|
+
|
|
68
|
+
export {
|
|
69
|
+
authentication,
|
|
70
|
+
redirect,
|
|
71
|
+
renderQRCode,
|
|
72
|
+
signIn,
|
|
73
|
+
} from './core';
|
|
74
|
+
|
|
67
75
|
export * from './interface';
|
|
@@ -1,59 +0,0 @@
|
|
|
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
|
-
/** 接口的baseURL */
|
|
16
|
-
baseURL: string;
|
|
17
|
-
providers?: ProviderConfig[];
|
|
18
|
-
}
|
|
19
|
-
interface InternalContext {
|
|
20
|
-
/** 接口的baseURL */
|
|
21
|
-
baseURL: string;
|
|
22
|
-
providers?: ProviderConfig[];
|
|
23
|
-
}
|
|
24
|
-
/** 第三方类型 */
|
|
25
|
-
type ThirdParty = string;
|
|
26
|
-
type ProviderUserConfig = Partial<ProviderConfig>;
|
|
27
|
-
interface ProviderConfig {
|
|
28
|
-
/** 唯一值 */
|
|
29
|
-
id: string;
|
|
30
|
-
/** 名称 */
|
|
31
|
-
name: string;
|
|
32
|
-
/**
|
|
33
|
-
* 协议类型
|
|
34
|
-
* - `oauth` 第三方授权登录
|
|
35
|
-
* - `cas` 统一账号登录
|
|
36
|
-
* - `custom` 自定义
|
|
37
|
-
*/
|
|
38
|
-
type: 'oauth' | 'cas' | 'custom';
|
|
39
|
-
/** 授权登录地址 */
|
|
40
|
-
authorization?: Authorization | Fn;
|
|
41
|
-
/** `client_id` */
|
|
42
|
-
clientId?: string;
|
|
43
|
-
/** `redirect_uri` */
|
|
44
|
-
redirectUri?: string;
|
|
45
|
-
/** 授权登录接口 */
|
|
46
|
-
callbackUrl?: string | FnApi;
|
|
47
|
-
/** 初始化二维码 */
|
|
48
|
-
initQRCode?: (url: string, params: {
|
|
49
|
-
id: string;
|
|
50
|
-
} & Recordable) => Promise<void> | void;
|
|
51
|
-
}
|
|
52
|
-
interface Authorization {
|
|
53
|
-
/** 授权登录地址 */
|
|
54
|
-
url: string;
|
|
55
|
-
/** 授权登录参数 */
|
|
56
|
-
params?: Recordable;
|
|
57
|
-
}
|
|
58
|
-
//#endregion
|
|
59
|
-
export { AuthOptions, Authorization, Fn, FnApi, InternalContext, ProviderConfig, ProviderUserConfig, Recordable, ThirdParty };
|