@pubinfo/module-auth 2.0.13 → 2.0.14
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/core.d.ts +1 -6
- package/dist/helper.d.ts +22 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +102 -87
- package/dist/interface.d.ts +7 -11
- package/dist/pages/auth.d.ts +2 -2
- package/dist/providers/4A.d.ts +13 -3
- package/dist/providers/4A.js +5 -5
- package/dist/providers/credentials.d.ts +3 -5
- package/dist/providers/credentials.js +3 -4
- package/dist/providers/ding-zj.d.ts +7 -4
- package/dist/providers/ding-zj.js +6 -6
- package/dist/providers/sso.d.ts +19 -0
- package/dist/providers/sso.js +23 -0
- package/package.json +3 -3
- package/src/components/LoginWithFourA/index.ts +2 -2
- package/src/components/RedirectLogin/index.ts +2 -1
- package/src/core.ts +17 -47
- package/src/helper.ts +77 -0
- package/src/index.ts +3 -3
- package/src/interface.ts +7 -13
- package/src/pages/auth.ts +13 -2
- package/src/providers/4A.ts +17 -5
- package/src/providers/credentials.ts +4 -8
- package/src/providers/ding-zj.ts +13 -7
- package/src/providers/sso.ts +44 -0
package/src/providers/ding-zj.ts
CHANGED
|
@@ -1,21 +1,27 @@
|
|
|
1
|
-
import type { Authorization,
|
|
1
|
+
import type { Authorization, ProviderOptions, ProviderUserOptions } from '../interface';
|
|
2
2
|
|
|
3
|
-
interface
|
|
3
|
+
export interface DingZJOptions extends ProviderUserOptions {
|
|
4
4
|
/**
|
|
5
5
|
* 登录方式
|
|
6
6
|
* - `redirect` 跳转浙政钉的扫码页面
|
|
7
7
|
* - `embed` 内嵌浙政钉的登录二维码
|
|
8
8
|
*/
|
|
9
9
|
mode: 'redirect' | 'embed'
|
|
10
|
+
|
|
11
|
+
/** `client_id` */
|
|
12
|
+
clientId?: string
|
|
13
|
+
|
|
14
|
+
/** `redirect_uri` */
|
|
15
|
+
redirectUri?: string
|
|
10
16
|
}
|
|
11
17
|
|
|
12
18
|
/**
|
|
13
19
|
* 浙政钉扫码登录
|
|
14
20
|
*/
|
|
15
|
-
export default function DingZJ(options:
|
|
21
|
+
export default function DingZJ(options: DingZJOptions): ProviderOptions {
|
|
16
22
|
const { clientId, redirectUri } = options;
|
|
17
23
|
|
|
18
|
-
const
|
|
24
|
+
const signIn: Record<string, Authorization> = {
|
|
19
25
|
/** 跳转外部页面 */
|
|
20
26
|
redirect: {
|
|
21
27
|
url: 'https://openplatform-pro.ding.zj.gov.cn/oauth2/auth.htm',
|
|
@@ -42,7 +48,7 @@ export default function DingZJ(options: DingZJConfig): ProviderConfig {
|
|
|
42
48
|
},
|
|
43
49
|
};
|
|
44
50
|
|
|
45
|
-
const initQRCode:
|
|
51
|
+
const initQRCode: ProviderOptions['initQRCode'] = (url, options) => {
|
|
46
52
|
const target = document.getElementById(options.id);
|
|
47
53
|
|
|
48
54
|
if (!target) {
|
|
@@ -68,8 +74,8 @@ export default function DingZJ(options: DingZJConfig): ProviderConfig {
|
|
|
68
74
|
id: 'ding-zj',
|
|
69
75
|
name: '浙政钉登录',
|
|
70
76
|
type: 'oauth',
|
|
71
|
-
|
|
72
|
-
|
|
77
|
+
signIn: signIn[options.mode],
|
|
78
|
+
authenticate: '/bs/loginByDingZJ',
|
|
73
79
|
initQRCode: options.mode === 'embed' ? initQRCode : undefined,
|
|
74
80
|
...options,
|
|
75
81
|
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { ProviderOptions, ProviderUserOptions } from '@/interface';
|
|
2
|
+
|
|
3
|
+
export interface SsoOptions extends ProviderUserOptions {
|
|
4
|
+
/**
|
|
5
|
+
* 登录类型,根据调用 `/app/oauth/generateCode` 接口时传递的 `grantType` 参数值判断:
|
|
6
|
+
*
|
|
7
|
+
* - `OAUTH2` -> `defaultOauth2`
|
|
8
|
+
* - `SIMPLE_ENCRYPT` -> `encrypt`
|
|
9
|
+
*
|
|
10
|
+
* @default `defaultOauth2`
|
|
11
|
+
*/
|
|
12
|
+
loginType?: 'defaultOauth2' | 'encrypt'
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* `SSO 统一账号登录`
|
|
17
|
+
*
|
|
18
|
+
* - 主系统调用 `/app/oauth/generateCode?appKey=xxx` 获取 `code`,并作为参数跳转至子系统;
|
|
19
|
+
* - 当前 `provider` 将获取 `code` 并调用 `/auth/ssoLogin` 完成登录认证。
|
|
20
|
+
*/
|
|
21
|
+
export default function Sso(options: SsoOptions = {}): ProviderOptions {
|
|
22
|
+
const { loginType = 'defaultOauth2' } = options;
|
|
23
|
+
|
|
24
|
+
return {
|
|
25
|
+
id: 'sso',
|
|
26
|
+
name: 'SSO统一账号登录',
|
|
27
|
+
type: 'custom',
|
|
28
|
+
authenticate: async (params, baseURL) => {
|
|
29
|
+
const res = await fetch(
|
|
30
|
+
`${baseURL}/auth/ssoLogin`,
|
|
31
|
+
{
|
|
32
|
+
headers: { 'Content-Type': 'application/json' },
|
|
33
|
+
method: 'POST',
|
|
34
|
+
body: JSON.stringify({
|
|
35
|
+
...params,
|
|
36
|
+
loginType,
|
|
37
|
+
}),
|
|
38
|
+
},
|
|
39
|
+
);
|
|
40
|
+
return await res.json();
|
|
41
|
+
},
|
|
42
|
+
...options,
|
|
43
|
+
};
|
|
44
|
+
}
|