@zoyafng/guard-vue3 5.3.10-hb.0
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/LICENSE +21 -0
- package/README.md +169 -0
- package/README.zh_CN.md +168 -0
- package/dist/esm/guard.min.css +3 -0
- package/dist/esm/guard.min.js +1 -0
- package/dist/typings/index.d.ts +6 -0
- package/dist/typings/plugin.d.ts +7 -0
- package/dist/typings/token.d.ts +4 -0
- package/package.json +36 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2019 Authing
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
<div align=center>
|
|
2
|
+
<img width="300" src="https://files.authing.co/authing-console/authing-logo-new-20210924.svg" />
|
|
3
|
+
</div>
|
|
4
|
+
|
|
5
|
+
<br />
|
|
6
|
+
|
|
7
|
+
English | [简体中文](./README.zh_CN.md)
|
|
8
|
+
|
|
9
|
+
<br />
|
|
10
|
+
|
|
11
|
+
Guard is a portable authentication component provided by authing. You can embed it in any application to handle complex user authentication processes in one stop.
|
|
12
|
+
|
|
13
|
+
Prepare your Vue3 project and follow the guide to connect Guard to your Vue3 project!
|
|
14
|
+
|
|
15
|
+
## Install
|
|
16
|
+
|
|
17
|
+
``` shell
|
|
18
|
+
npm install --save @zoyafng/guard-vue3
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Initialize
|
|
22
|
+
|
|
23
|
+
|Key|Type|Default|Requires
|
|
24
|
+
|-----|----|----|----|
|
|
25
|
+
|appId|String| - |Y|
|
|
26
|
+
|host|String| - |N|
|
|
27
|
+
|redirectUri|String| - |N|
|
|
28
|
+
|mode|normal / modal|normal|N|
|
|
29
|
+
|defaultScene|GuardModuleType|login|N|
|
|
30
|
+
|tenantId|String| - | N |
|
|
31
|
+
|lang|zh-CN / en-US|zh-CN|N|
|
|
32
|
+
|isSSO|Boolean|true|N|
|
|
33
|
+
|config|Partial<IGuardConfig>| - | N |
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
``` javascript
|
|
37
|
+
// From CDN
|
|
38
|
+
const guard = new GuardFactory.Guard({
|
|
39
|
+
appId: '62e22721c889dd44bad1dda2',
|
|
40
|
+
host: 'https://guard-test-2022.authing.cn',
|
|
41
|
+
redirectUri: 'http://localhost:3000/callback'
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
// From npm
|
|
45
|
+
import { createApp } from 'vue'
|
|
46
|
+
|
|
47
|
+
import { GuardPlugin } from '@zoyafng/guard-vue3'
|
|
48
|
+
|
|
49
|
+
import '@zoyafng/guard-vue3/dist/esm/guard.min.css'
|
|
50
|
+
|
|
51
|
+
import App from './App.vue'
|
|
52
|
+
|
|
53
|
+
const app = createApp(App)
|
|
54
|
+
|
|
55
|
+
app.use(
|
|
56
|
+
createGuard({
|
|
57
|
+
appId: '62e22721c889dd44bad1dda2',
|
|
58
|
+
host: 'https://guard-test-2022.authing.cn',
|
|
59
|
+
redirectUri: 'http://localhost:3000/callback'
|
|
60
|
+
})
|
|
61
|
+
)
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
``` html
|
|
65
|
+
// use Guard APIs in Components
|
|
66
|
+
|
|
67
|
+
// Composition API
|
|
68
|
+
<script scoped setup>
|
|
69
|
+
import { useGuard } from '@zoyafng/guard-vue3'
|
|
70
|
+
|
|
71
|
+
const guard = useGuard()
|
|
72
|
+
|
|
73
|
+
guard.start('#home-container')
|
|
74
|
+
</script>
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
// Options API
|
|
78
|
+
<script scoped>
|
|
79
|
+
export default {
|
|
80
|
+
mounted () {
|
|
81
|
+
this.$guard.start('#home-container')
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
</script>
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## Guard for Vue3 provides three login modes
|
|
88
|
+
|
|
89
|
+
### Embed mode
|
|
90
|
+
|
|
91
|
+
Render Guard component
|
|
92
|
+
|
|
93
|
+
``` javascript
|
|
94
|
+
import { onMounted } from 'vue'
|
|
95
|
+
|
|
96
|
+
import { useGuard } from '@zoyafng/guard-vue3'
|
|
97
|
+
|
|
98
|
+
const guard = useGuard()
|
|
99
|
+
|
|
100
|
+
onMounted(() => {
|
|
101
|
+
guard.start('#home-container')
|
|
102
|
+
})
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### modal mode
|
|
106
|
+
|
|
107
|
+
When the parameter 'mode' of Guard instantiation is' modal ', the modal mode is started, and the following API can be used to display and hide the guard.
|
|
108
|
+
|
|
109
|
+
``` javascript
|
|
110
|
+
|
|
111
|
+
guard.show()
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
``` javascript
|
|
115
|
+
guard.hide()
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
### Redirect mode
|
|
119
|
+
|
|
120
|
+
Login by code, redirect to login page
|
|
121
|
+
|
|
122
|
+
``` javascript
|
|
123
|
+
guard.startWithRedirect()
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
Auto handle redirect callback
|
|
127
|
+
|
|
128
|
+
``` javascript
|
|
129
|
+
guard.handleRedirectCallback()
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
Logout
|
|
133
|
+
|
|
134
|
+
``` javascript
|
|
135
|
+
guard.logout()
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
## Regist events
|
|
139
|
+
|
|
140
|
+
``` javascript
|
|
141
|
+
guard.on('load', e => {
|
|
142
|
+
console.log(e)
|
|
143
|
+
})
|
|
144
|
+
|
|
145
|
+
guard.on('login', userInfo => {
|
|
146
|
+
console.log(userInfo)
|
|
147
|
+
})
|
|
148
|
+
|
|
149
|
+
// ......
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
## Integrate authing js sdk instance
|
|
153
|
+
|
|
154
|
+
Guard integrated AuthenticationClient, so you can access all apis of AuthenticationClient, etc:
|
|
155
|
+
|
|
156
|
+
``` javascript
|
|
157
|
+
guard.getAuthClient().then(authClient => {
|
|
158
|
+
authClient.registerByEmail()
|
|
159
|
+
authClient.validateToken()
|
|
160
|
+
// ..........
|
|
161
|
+
})
|
|
162
|
+
// ....
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
Refer to [Authentication SDK](https://docs.authing.cn/v2/reference/sdk-for-node/authentication/)
|
|
166
|
+
|
|
167
|
+
## 📚 Documentation
|
|
168
|
+
|
|
169
|
+
To check out live examples and docs, visit [docs](https://docs.authing.cn/v2/reference/guard/v3/spa.html)
|
package/README.zh_CN.md
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
<div align=center>
|
|
2
|
+
<img width="300" src="https://files.authing.co/authing-console/authing-logo-new-20210924.svg" />
|
|
3
|
+
</div>
|
|
4
|
+
|
|
5
|
+
<br />
|
|
6
|
+
|
|
7
|
+
简体中文 | [English](./README.md)
|
|
8
|
+
|
|
9
|
+
<br />
|
|
10
|
+
|
|
11
|
+
Guard 是 Authing 提供的一种轻便的认证组件,你可以把它嵌入在你任何的 SPA(Single Page Application)应用中,一站式处理复杂的用户认证流程。
|
|
12
|
+
|
|
13
|
+
准备好你的 Vue3 项目,跟随引导将 Guard 接入到你的 Vue3 项目中吧!
|
|
14
|
+
|
|
15
|
+
## 安装
|
|
16
|
+
|
|
17
|
+
``` shell
|
|
18
|
+
npm install --save @zoyafng/guard-vue3
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## 初始化
|
|
22
|
+
|
|
23
|
+
|字段|类型|默认是|必传
|
|
24
|
+
|-----|----|----|----|
|
|
25
|
+
|appId|String| - |是|
|
|
26
|
+
|host|String| - |否|
|
|
27
|
+
|redirectUri|String| - |否|
|
|
28
|
+
|mode|normal / modal|normal|否|
|
|
29
|
+
|defaultScene|GuardModuleType|login|否|
|
|
30
|
+
|tenantId|String| - | 否 |
|
|
31
|
+
|lang|zh-CN / en-US|zh-CN| 否 |
|
|
32
|
+
|isSSO|Boolean|true| 否 |
|
|
33
|
+
|config|Partial<IGuardConfig>| - | 否 |
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
``` javascript
|
|
37
|
+
// 使用 CDN
|
|
38
|
+
const guard = new GuardFactory.Guard({
|
|
39
|
+
appId: '62e22721c889dd44bad1dda2',
|
|
40
|
+
host: 'https://guard-test-2022.authing.cn',
|
|
41
|
+
redirectUri: 'http://localhost:3000/callback'
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
// 使用 npm
|
|
45
|
+
import { createApp } from 'vue'
|
|
46
|
+
|
|
47
|
+
import { GuardPlugin } from '@zoyafng/guard-vue3'
|
|
48
|
+
|
|
49
|
+
import '@zoyafng/guard-vue3/dist/esm/guard.min.css'
|
|
50
|
+
|
|
51
|
+
import App from './App.vue'
|
|
52
|
+
|
|
53
|
+
const app = createApp(App)
|
|
54
|
+
|
|
55
|
+
app.use(
|
|
56
|
+
createGuard({
|
|
57
|
+
appId: '62e22721c889dd44bad1dda2',
|
|
58
|
+
host: 'https://guard-test-2022.authing.cn',
|
|
59
|
+
redirectUri: 'http://localhost:3000/callback'
|
|
60
|
+
})
|
|
61
|
+
)
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
``` html
|
|
65
|
+
// 组件中使用 Guard 的 API
|
|
66
|
+
|
|
67
|
+
// Composition API
|
|
68
|
+
<script scoped setup>
|
|
69
|
+
import { useGuard } from '@zoyafng/guard-vue3'
|
|
70
|
+
|
|
71
|
+
const guard = useGuard()
|
|
72
|
+
|
|
73
|
+
guard.start('#home-container')
|
|
74
|
+
</script>
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
// Options API
|
|
78
|
+
<script scoped>
|
|
79
|
+
export default {
|
|
80
|
+
mounted () {
|
|
81
|
+
this.$guard.start('#home-container')
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
</script>
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## Guard 提供三种登录模式
|
|
88
|
+
|
|
89
|
+
### 嵌入模式
|
|
90
|
+
|
|
91
|
+
渲染 Guard 组件
|
|
92
|
+
|
|
93
|
+
``` javascript
|
|
94
|
+
import { onMounted } from 'vue'
|
|
95
|
+
|
|
96
|
+
import { useGuard } from '@zoyafng/guard-vue3'
|
|
97
|
+
|
|
98
|
+
const guard = useGuard()
|
|
99
|
+
|
|
100
|
+
onMounted(() => {
|
|
101
|
+
guard.start('#home-container')
|
|
102
|
+
})
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### 弹窗模式
|
|
106
|
+
|
|
107
|
+
当 Guard 实例化的参数 `mode` 为 `modal` 时,将启动模态模式,下面的 API 可用于显示和隐藏 Guard。
|
|
108
|
+
|
|
109
|
+
``` javascript
|
|
110
|
+
|
|
111
|
+
guard.show()
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
``` javascript
|
|
115
|
+
guard.hide()
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
### 跳转
|
|
119
|
+
|
|
120
|
+
使用 code 码登录,跳转到登录页面
|
|
121
|
+
|
|
122
|
+
``` javascript
|
|
123
|
+
guard.startWithRedirect()
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
code 换 token,自动处理页面重定向
|
|
127
|
+
|
|
128
|
+
``` javascript
|
|
129
|
+
guard.handleRedirectCallback()
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
登出
|
|
133
|
+
|
|
134
|
+
``` javascript
|
|
135
|
+
guard.logout()
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
## 注册事件
|
|
139
|
+
|
|
140
|
+
``` javascript
|
|
141
|
+
guard.on('load', e => {
|
|
142
|
+
console.log(e)
|
|
143
|
+
})
|
|
144
|
+
|
|
145
|
+
guard.on('login', userInfo => {
|
|
146
|
+
console.log(userInfo)
|
|
147
|
+
})
|
|
148
|
+
|
|
149
|
+
// ......
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
## 集成 Authing JS SDK
|
|
153
|
+
|
|
154
|
+
Guard 集成了 AuthenticationClient,所以你可以访问 AuthenticationClient 的所有 api 等等:
|
|
155
|
+
|
|
156
|
+
``` javascript
|
|
157
|
+
guard.getAuthClient().then(authClient => {
|
|
158
|
+
authClient.registerByEmail()
|
|
159
|
+
authClient.validateToken()
|
|
160
|
+
// ..........
|
|
161
|
+
})
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
参考 [Authentication SDK](https://docs.authing.cn/v2/reference/sdk-for-node/authentication/)
|
|
165
|
+
|
|
166
|
+
## 文档
|
|
167
|
+
|
|
168
|
+
参考详细文档说明 [docs](https://docs.authing.cn/v2/reference/guard/v3/spa.html)
|