@cloudbase/oauth 0.0.4-alpha.0 → 1.0.0-alpha.1
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/CHANGELOG.md +30 -0
- package/Dockerfile +15 -0
- package/README.md +165 -3
- package/_exmaple/assets/scripts/function/function.ts +99 -0
- package/_exmaple/assets/scripts/index.ts +101 -0
- package/_exmaple/assets/scripts/request.ts +11 -0
- package/_exmaple/index.html +15 -0
- package/_exmaple/package.json +33 -0
- package/_exmaple/tsconfig.json +71 -0
- package/_exmaple/typings.d.ts +0 -0
- package/_exmaple/webpack.config.js +42 -0
- package/dist/auth/apis.d.ts +13 -5
- package/dist/auth/apis.js +118 -40
- package/dist/auth/consts.d.ts +26 -2
- package/dist/auth/consts.js +28 -3
- package/dist/auth/models.d.ts +207 -1
- package/dist/auth/models.js +1 -1
- package/dist/captcha/captcha.js +5 -3
- package/dist/index.d.ts +7 -0
- package/dist/index.js +4 -166
- package/dist/oauth2client/interface.d.ts +6 -6
- package/dist/oauth2client/interface.js +1 -1
- package/dist/oauth2client/oauth2client.d.ts +1 -0
- package/dist/oauth2client/oauth2client.js +17 -1
- package/package.json +28 -28
- package/publish.sh +2 -0
- package/src/auth/apis.ts +134 -29
- package/src/auth/consts.ts +27 -1
- package/src/auth/models.ts +256 -1
- package/src/captcha/captcha.ts +185 -180
- package/src/index.ts +3 -105
- package/src/oauth2client/interface.ts +6 -6
- package/src/oauth2client/oauth2client.ts +9 -0
- package/wiki/README.md +75 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
## 更新日志
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### 1.3.3beta
|
|
5
|
+
|
|
6
|
+
1. 三方登录开放 `provider_access_token` 和 `provider_id_token`
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### 1.2.3
|
|
10
|
+
|
|
11
|
+
1. OAuth2Client 增加 hasCredentials 方法,判断是否存在 credentials(不校验有限性也不触发 refresh token)
|
|
12
|
+
2. 增加 LocalCredentials 管理 credentials, 简化 OAuth2Client 代码逻辑
|
|
13
|
+
|
|
14
|
+
### 1.1.3
|
|
15
|
+
|
|
16
|
+
1. 修复 getAccessToken 方法获取不到 refresh 之后的 token 的 bug
|
|
17
|
+
2. 增加 SinglePromise 模块
|
|
18
|
+
|
|
19
|
+
### 1.0.12
|
|
20
|
+
|
|
21
|
+
1. 添加 ErrorType enum
|
|
22
|
+
|
|
23
|
+
### 1.0.11
|
|
24
|
+
|
|
25
|
+
1. OAuth2Client 中 refresh token,如果请求返回的 error 为 invalid_grant 时,删除本地 token
|
|
26
|
+
2. OAuth2Client 中,对 defaultRequest 的 options 数据进行拷贝,避免修改了传入的参数数据
|
|
27
|
+
|
|
28
|
+
### 1.0.9
|
|
29
|
+
|
|
30
|
+
1. 代码格式化
|
package/Dockerfile
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# FROM base_npm:latest
|
|
2
|
+
|
|
3
|
+
# # ARG NPM_TOKEN
|
|
4
|
+
# RUN mkdir -p /usr/src/app
|
|
5
|
+
# WORKDIR /usr/src/app/
|
|
6
|
+
|
|
7
|
+
# COPY package.json .
|
|
8
|
+
# ADD . /usr/src/app
|
|
9
|
+
# RUN npm set registry https://npm.xbase.xyz
|
|
10
|
+
# RUN npm install
|
|
11
|
+
# RUN npm run build
|
|
12
|
+
|
|
13
|
+
# # @todo use semantic-release with gitlab ci to auto release with branch
|
|
14
|
+
# # RUN npm view @xbase/sdk version
|
|
15
|
+
# RUN npm publish
|
package/README.md
CHANGED
|
@@ -14,8 +14,170 @@ Auth 登录相关模块
|
|
|
14
14
|
|
|
15
15
|
```typescript
|
|
16
16
|
const authOptions = {
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
apiOrigin: "服务域名",
|
|
18
|
+
clientId: "客户端ID"
|
|
19
|
+
}
|
|
20
|
+
const auth = new Auth(authOptions)
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
```typescript
|
|
24
|
+
import { initializeClient } from "@xbasesdk/xbase"
|
|
25
|
+
const config = {
|
|
26
|
+
env: "xbase-4gh5dh6nf62145a9"
|
|
27
|
+
}
|
|
28
|
+
const client = initializeClient(config)
|
|
29
|
+
// 调用API
|
|
30
|
+
const loginState = await client.auth.hasLoginState()
|
|
31
|
+
// 获取 accessToken
|
|
32
|
+
const accessToken = await client.oAuth2Client.getAccessToken()
|
|
33
|
+
|
|
34
|
+
// 用 OIDC Token 用自己的API
|
|
35
|
+
export interface ExampleData {
|
|
36
|
+
result?: string
|
|
37
|
+
}
|
|
38
|
+
const data = await client.oAuth2Client.request<ExampleData>(
|
|
39
|
+
"https://example.com",
|
|
40
|
+
{ withCredentials: true }
|
|
41
|
+
)
|
|
42
|
+
console.log(data.result)
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
import {initializeApp} from '@clodbasesdk/oauth/app';
|
|
47
|
+
import {getAuth} from '@clodbasesdk/oauth/auth';
|
|
48
|
+
export const config = {
|
|
49
|
+
env: 'env-4gh5dh6nf62145a9'
|
|
19
50
|
};
|
|
20
|
-
const
|
|
51
|
+
const app = initializeApp(config)
|
|
52
|
+
const auth = getAuth(app)
|
|
53
|
+
// 调用API
|
|
54
|
+
const loginState = await auth.hasLoginState()
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### 账号登录
|
|
58
|
+
|
|
59
|
+
```typescript
|
|
60
|
+
auth.signIn({
|
|
61
|
+
username: "test",
|
|
62
|
+
password: "test"
|
|
63
|
+
})
|
|
21
64
|
```
|
|
65
|
+
|
|
66
|
+
### 手机验证码登录/注册
|
|
67
|
+
|
|
68
|
+
```typescript
|
|
69
|
+
const phoneNumber = "10012341234"
|
|
70
|
+
// 短信验证码
|
|
71
|
+
const verificationCode = "******"
|
|
72
|
+
const verification = await auth.getVerification({
|
|
73
|
+
phone_number: "+86 " + phoneNumber,
|
|
74
|
+
target: "ANY"
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
let verifyResult = await auth.verify({
|
|
78
|
+
verification_code: verificationCode,
|
|
79
|
+
verification_id: verification ? verification.verification_id : ""
|
|
80
|
+
})
|
|
81
|
+
let isUser = verification ? verification.is_user : false
|
|
82
|
+
|
|
83
|
+
let result
|
|
84
|
+
if (isUser) {
|
|
85
|
+
result = await auth.signIn({
|
|
86
|
+
username: "+86 " + phoneNumber,
|
|
87
|
+
verification_code: verificationCode,
|
|
88
|
+
verification_token: verifyResult.verification_token
|
|
89
|
+
})
|
|
90
|
+
} else {
|
|
91
|
+
result = await auth.signUp({
|
|
92
|
+
phone_number: "+86 " + phoneNumber,
|
|
93
|
+
password: "*******",
|
|
94
|
+
verification_code: verificationCode,
|
|
95
|
+
verification_token: verifyResult.verification_token,
|
|
96
|
+
local: "zh-cn",
|
|
97
|
+
name: "100****1234"
|
|
98
|
+
})
|
|
99
|
+
}
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### 错误处理
|
|
103
|
+
|
|
104
|
+
```typescript
|
|
105
|
+
try {
|
|
106
|
+
await auth.verify({
|
|
107
|
+
verification_code: verificationCode,
|
|
108
|
+
verification_id: verification ? verification.verification_id : ""
|
|
109
|
+
})
|
|
110
|
+
} catch (error) {
|
|
111
|
+
if (error && error.error_uri === "/v1/auth/verification/verify") {
|
|
112
|
+
switch (error.error) {
|
|
113
|
+
case "not_found": {
|
|
114
|
+
result = i18n.translate("error", "User Not Found")
|
|
115
|
+
break
|
|
116
|
+
}
|
|
117
|
+
case "invalid_password": {
|
|
118
|
+
if (error.details !== undefined && error.details.length > 0) {
|
|
119
|
+
result =
|
|
120
|
+
i18n.translate("error", "Certification failed, you still have") +
|
|
121
|
+
error.details[0].limit_remaining +
|
|
122
|
+
i18n.translate("error", "chances. You can also") +
|
|
123
|
+
"" +
|
|
124
|
+
i18n.translate("error", "Reset Login Password") +
|
|
125
|
+
"</a>"
|
|
126
|
+
} else {
|
|
127
|
+
result = i18n.translate("error", "Password does not match")
|
|
128
|
+
}
|
|
129
|
+
break
|
|
130
|
+
}
|
|
131
|
+
case "user_pending": {
|
|
132
|
+
result = i18n.translate("error", "The account is not activated")
|
|
133
|
+
break
|
|
134
|
+
}
|
|
135
|
+
case "user_blocked": {
|
|
136
|
+
result = i18n.translate("error", "Account has been disabled")
|
|
137
|
+
break
|
|
138
|
+
}
|
|
139
|
+
case "invalid_status": {
|
|
140
|
+
if (error.details !== undefined && error.details.length > 0) {
|
|
141
|
+
let s = error.details[0].retry_delay
|
|
142
|
+
s = s.substring(0, s.length - 1)
|
|
143
|
+
s = parseInt(s)
|
|
144
|
+
result =
|
|
145
|
+
i18n.translate(
|
|
146
|
+
"error",
|
|
147
|
+
"The password input error has reached the upper limit and the account will be locked "
|
|
148
|
+
) +
|
|
149
|
+
(s < 3600
|
|
150
|
+
? s / 60 + i18n.translate("error", "minute")
|
|
151
|
+
: s / 3600 + i18n.translate("error", "hour"))
|
|
152
|
+
} else {
|
|
153
|
+
result = i18n.translate(
|
|
154
|
+
"error",
|
|
155
|
+
"Account has been temporarily locked"
|
|
156
|
+
)
|
|
157
|
+
}
|
|
158
|
+
break
|
|
159
|
+
}
|
|
160
|
+
case "invalid_two_factor": {
|
|
161
|
+
result = i18n.translate(
|
|
162
|
+
"error",
|
|
163
|
+
"Secondary authentication code does not match or has expired"
|
|
164
|
+
)
|
|
165
|
+
break
|
|
166
|
+
}
|
|
167
|
+
case "invalid_two_factor_recovery": {
|
|
168
|
+
result = i18n.translate(
|
|
169
|
+
"error",
|
|
170
|
+
"Recovery code does not match or has expired"
|
|
171
|
+
)
|
|
172
|
+
break
|
|
173
|
+
}
|
|
174
|
+
default: {
|
|
175
|
+
result = i18n.translate("error", "unknown")
|
|
176
|
+
break
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
## [更新日志](./CHANGELOG.md)
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { App } from "@xbasesdk/xbase/app";
|
|
2
|
+
import { getOAuthClient, AuthClient, ErrorType } from "@xbasesdk/xbase/oauthclient";
|
|
3
|
+
import { uuidv4 } from "@xbasesdk/xbase/utils/uuid";
|
|
4
|
+
|
|
5
|
+
export interface FunctionOptions {
|
|
6
|
+
credentialsClient: AuthClient;
|
|
7
|
+
env: string
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Returns the existing `Auth` instance that is associated with the app
|
|
12
|
+
*/
|
|
13
|
+
export function getFunction(app: App): Function {
|
|
14
|
+
const credentialsClient = getOAuthClient(app)
|
|
15
|
+
return new Function({
|
|
16
|
+
credentialsClient: credentialsClient,
|
|
17
|
+
env: app.options.clientId
|
|
18
|
+
})
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
export class Function {
|
|
23
|
+
|
|
24
|
+
private _config: FunctionOptions;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* constructor
|
|
28
|
+
* @param {AuthOptions} opts
|
|
29
|
+
*/
|
|
30
|
+
constructor(opts: FunctionOptions) {
|
|
31
|
+
this._config = {
|
|
32
|
+
credentialsClient: opts.credentialsClient,
|
|
33
|
+
env: opts.env,
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* callFunction call function
|
|
38
|
+
* @param {SignInRequest} params A SignInRequest Object.
|
|
39
|
+
* @return {Promise<Credentials>} A Promise<Credentials> object.
|
|
40
|
+
*/
|
|
41
|
+
public async callFunction(params: FunctionRequest): Promise<FunctionResponse> {
|
|
42
|
+
let accessToken: string
|
|
43
|
+
try {
|
|
44
|
+
accessToken = await this._config.credentialsClient.getAccessToken()
|
|
45
|
+
} catch (e) {
|
|
46
|
+
if (e.error === ErrorType.UNAUTHENTICATED) {
|
|
47
|
+
accessToken = ""
|
|
48
|
+
} else {
|
|
49
|
+
return Promise.reject(e)
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
const requestId = uuidv4()
|
|
53
|
+
var reqBody = {
|
|
54
|
+
"action": "functions.invokeFunction",
|
|
55
|
+
"dataVersion": "2020-01-10",
|
|
56
|
+
"env": this._config.env,
|
|
57
|
+
"function_name": params.name,
|
|
58
|
+
"request_data": JSON.stringify(params.data),
|
|
59
|
+
"seqId": requestId,
|
|
60
|
+
"access_token": accessToken
|
|
61
|
+
}
|
|
62
|
+
const url = "/web?env=" + this._config.env
|
|
63
|
+
const resp = await this._config.credentialsClient.request<functionHTTPResponse>(url, {
|
|
64
|
+
method: 'POST',
|
|
65
|
+
body: reqBody,
|
|
66
|
+
headers: {
|
|
67
|
+
'content-type': 'application/json'
|
|
68
|
+
}
|
|
69
|
+
})
|
|
70
|
+
if (resp.code) {
|
|
71
|
+
return Promise.reject({
|
|
72
|
+
error: resp.code,
|
|
73
|
+
error_description: resp.message
|
|
74
|
+
})
|
|
75
|
+
}
|
|
76
|
+
return {
|
|
77
|
+
requestId: resp.requestId,
|
|
78
|
+
result: resp.data.response_data,
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
export interface FunctionRequest {
|
|
85
|
+
name: string;
|
|
86
|
+
data: any;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export interface FunctionResponse {
|
|
90
|
+
requestId: string;
|
|
91
|
+
result: any;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export interface functionHTTPResponse {
|
|
95
|
+
requestId: string;
|
|
96
|
+
data: any
|
|
97
|
+
code: string
|
|
98
|
+
message: string
|
|
99
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { client, fn } from "./request";
|
|
2
|
+
|
|
3
|
+
async function init() {
|
|
4
|
+
try {
|
|
5
|
+
signInWithUserNameAndPassword()
|
|
6
|
+
} catch (error) {
|
|
7
|
+
// 获取用户信息失败
|
|
8
|
+
console.log('test error: ', error);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
// try {
|
|
12
|
+
// console.log("rest password")
|
|
13
|
+
// const verificationToken = await client.auth.getVerification({
|
|
14
|
+
// phone_number: "+86 16622002084",
|
|
15
|
+
// })
|
|
16
|
+
// console.log(verificationToken.verification_id, verificationToken.is_user)
|
|
17
|
+
// } catch (error) {
|
|
18
|
+
// // 获取用户信息失败
|
|
19
|
+
// console.log('发送失败 error: ', error);
|
|
20
|
+
// }
|
|
21
|
+
try {
|
|
22
|
+
signInWithProviderToken()
|
|
23
|
+
} catch (error) {
|
|
24
|
+
// 获取用户信息失败
|
|
25
|
+
console.log('grant error error: ', error);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const resp = await fn.callFunction({
|
|
29
|
+
name: "test", data: {
|
|
30
|
+
name: "ok"
|
|
31
|
+
}
|
|
32
|
+
})
|
|
33
|
+
console.log(resp.result)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
init();
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
async function signInWithUserNameAndPassword(): Promise<void> {
|
|
41
|
+
// 判断是否已经登录过了
|
|
42
|
+
const loginState = await client.auth.hasLoginState()
|
|
43
|
+
if (!loginState) {
|
|
44
|
+
// 用户名密码登录
|
|
45
|
+
await client.auth.signIn({
|
|
46
|
+
username: "leenanxi",
|
|
47
|
+
password: "qw0000"
|
|
48
|
+
})
|
|
49
|
+
}
|
|
50
|
+
// 获取用户信息,相当于 auth.signInWithUsernameAndPassword
|
|
51
|
+
const userInfoA = await client.auth.getUserProfile()
|
|
52
|
+
console.log(userInfoA)
|
|
53
|
+
|
|
54
|
+
// 修改密码
|
|
55
|
+
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
async function signInWithProviderToken(): Promise<void> {
|
|
60
|
+
// 判断是否已经登录过了
|
|
61
|
+
const loginState = await client.auth.hasLoginState()
|
|
62
|
+
|
|
63
|
+
console.log("test", loginState)
|
|
64
|
+
|
|
65
|
+
return
|
|
66
|
+
|
|
67
|
+
// if (!loginState) {
|
|
68
|
+
// const crd = await client.auth.signInAnonymously()
|
|
69
|
+
// console.log(crd)
|
|
70
|
+
// }
|
|
71
|
+
|
|
72
|
+
const userInfoA = await client.auth.getUserProfile()
|
|
73
|
+
console.log(userInfoA)
|
|
74
|
+
//
|
|
75
|
+
// // 获取provider token
|
|
76
|
+
// const providerToken = await client.auth.grantProviderToken({
|
|
77
|
+
// provider_id: "weda",
|
|
78
|
+
// provider_access_token: "ya29.a0ARrdaM8nNGa2g3eNWok38QWChn5hcOMZIXIbV48LxcEIt7lSfOt2ERLVRMQh9-iOxMy9anVtVV20ONWWyIHKxeA68D8FlpSZIazLfscLDOY8X1IjzF7kfhLiQwVbPYVeVsj7prOacREaICaaYO632za8bLSp2RU",
|
|
79
|
+
// });
|
|
80
|
+
// // 用provider token 登录
|
|
81
|
+
// client.auth.signInWithProvider({
|
|
82
|
+
// provider_token: providerToken.provider_token,
|
|
83
|
+
// })
|
|
84
|
+
|
|
85
|
+
// 调用云函数
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
// 登录成功后,获取用户信息
|
|
90
|
+
const userInfo = await client.auth.getUserProfile()
|
|
91
|
+
console.log(userInfo)
|
|
92
|
+
// 获取 accessToken
|
|
93
|
+
const accessToken = await client.auth.credentialsClient.getAccessToken();
|
|
94
|
+
console.log(accessToken)
|
|
95
|
+
// 用 OIDC 请求信息
|
|
96
|
+
// export interface ExampleData {
|
|
97
|
+
// result?: string;
|
|
98
|
+
// }
|
|
99
|
+
// const data = await client.oAuth2Client.request<ExampleData>("https://example.com", {withCredentials:true})
|
|
100
|
+
// console.log(data.result)
|
|
101
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import {initializeClient} from '@cloudbase/cloudbase';
|
|
2
|
+
import {getFunction} from './function/function';
|
|
3
|
+
|
|
4
|
+
export const config = {
|
|
5
|
+
apiOrigin: "https://xbase-4gh5dh6nf62145a9.ap-shanghai.tcb-api.tencentcloudapi.com",
|
|
6
|
+
clientId: "xbase-4gh5dh6nf62145a9",
|
|
7
|
+
};
|
|
8
|
+
const client = initializeClient(config);
|
|
9
|
+
const fn = getFunction(client.app);
|
|
10
|
+
|
|
11
|
+
export {client, fn}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
|
+
<meta http-equiv="Pragma" content="no-cache">
|
|
7
|
+
<meta http-equiv="Cache-Control" content="no-cache">
|
|
8
|
+
<meta http-equiv="Expires" content="0">
|
|
9
|
+
<title>Demo</title>
|
|
10
|
+
</head>
|
|
11
|
+
<body>
|
|
12
|
+
<div>loading...</div>
|
|
13
|
+
<div>test</div>
|
|
14
|
+
</body>
|
|
15
|
+
</html>
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "device",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
8
|
+
"build": "cross-env NODE_ENV=production webpack",
|
|
9
|
+
"start": "cross-env NODE_ENV=development webpack-dev-server"
|
|
10
|
+
},
|
|
11
|
+
"author": "",
|
|
12
|
+
"license": "ISC",
|
|
13
|
+
"dependencies": {
|
|
14
|
+
"@types/qs": "^6.9.1",
|
|
15
|
+
"@xbasesdk/xbase": "file://Users/nx/Documents/go/xbase/src/gitlab.xunlei.cn/xbase/sdk/xbasesdk/dist",
|
|
16
|
+
"cross-env": "^7.0.2",
|
|
17
|
+
"firebase": "^9.0.2",
|
|
18
|
+
"qs": "^6.9.3",
|
|
19
|
+
"webpack": "^4.39.3",
|
|
20
|
+
"webpack-cli": "^4.8.0"
|
|
21
|
+
},
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"@babel/cli": "^7.14.8",
|
|
24
|
+
"@babel/core": "^7.15.0",
|
|
25
|
+
"clean-webpack-plugin": "^4.0.0-alpha.0",
|
|
26
|
+
"copy-webpack-plugin": "^9.0.1",
|
|
27
|
+
"html-webpack-plugin": "^3.2.0",
|
|
28
|
+
"ts-loader": "^6.1.0",
|
|
29
|
+
"typescript": "^3.8.3",
|
|
30
|
+
"webpack-cli": "^4.8.0",
|
|
31
|
+
"webpack-dev-server": "^4.1.0"
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
/* Basic Options */
|
|
4
|
+
// "incremental": true, /* Enable incremental compilation */
|
|
5
|
+
"target": "es2020", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */
|
|
6
|
+
"module": "es2020", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
|
|
7
|
+
// "lib": [], /* Specify library files to be included in the compilation. */
|
|
8
|
+
"allowJs": true, /* Allow javascript files to be compiled. */
|
|
9
|
+
// "checkJs": true, /* Report errors in .js files. */
|
|
10
|
+
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
|
|
11
|
+
// "declaration": true, /* Generates corresponding '.d.ts' file. */
|
|
12
|
+
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
|
|
13
|
+
// "sourceMap": true, /* Generates corresponding '.map' file. */
|
|
14
|
+
// "outFile": "./", /* Concatenate and emit output to single file. */
|
|
15
|
+
"outDir": "./dist/", /* Redirect output structure to the directory. */
|
|
16
|
+
// "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
|
|
17
|
+
// "composite": true, /* Enable project compilation */
|
|
18
|
+
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
|
|
19
|
+
// "removeComments": true, /* Do not emit comments to output. */
|
|
20
|
+
// "noEmit": true, /* Do not emit outputs. */
|
|
21
|
+
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
|
|
22
|
+
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
|
|
23
|
+
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
|
|
24
|
+
|
|
25
|
+
/* Strict Type-Checking Options */
|
|
26
|
+
"strict": true, /* Enable all strict type-checking options. */
|
|
27
|
+
"noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
|
|
28
|
+
// "strictNullChecks": true, /* Enable strict null checks. */
|
|
29
|
+
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
|
|
30
|
+
// "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
|
|
31
|
+
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
|
|
32
|
+
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
|
|
33
|
+
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
|
|
34
|
+
|
|
35
|
+
/* Additional Checks */
|
|
36
|
+
// "noUnusedLocals": true, /* Report errors on unused locals. */
|
|
37
|
+
// "noUnusedParameters": true, /* Report errors on unused parameters. */
|
|
38
|
+
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
|
|
39
|
+
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
|
|
40
|
+
|
|
41
|
+
/* Module Resolution Options */
|
|
42
|
+
"moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
|
|
43
|
+
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
|
|
44
|
+
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
|
|
45
|
+
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
|
|
46
|
+
// "typeRoots": [], /* List of folders to include type definitions from. */
|
|
47
|
+
// "types": [], /* Type declaration files to be included in compilation. */
|
|
48
|
+
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
|
|
49
|
+
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
|
|
50
|
+
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
|
|
51
|
+
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
|
52
|
+
|
|
53
|
+
/* Source Map Options */
|
|
54
|
+
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
|
|
55
|
+
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
|
|
56
|
+
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
|
|
57
|
+
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
|
|
58
|
+
|
|
59
|
+
/* Experimental Options */
|
|
60
|
+
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
|
|
61
|
+
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
"strictPropertyInitialization": false,
|
|
66
|
+
"experimentalDecorators": true,
|
|
67
|
+
"strictNullChecks": false,
|
|
68
|
+
"noUnusedLocals": true,
|
|
69
|
+
"declaration": true
|
|
70
|
+
}
|
|
71
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
const path = require('path');
|
|
2
|
+
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
|
|
3
|
+
const CopyPlugin = require('copy-webpack-plugin');
|
|
4
|
+
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
|
5
|
+
|
|
6
|
+
const mode = process.env.NODE_ENV;
|
|
7
|
+
|
|
8
|
+
console.log('环境:', mode);
|
|
9
|
+
|
|
10
|
+
module.exports = {
|
|
11
|
+
entry: {
|
|
12
|
+
main: './assets/scripts/index.ts',
|
|
13
|
+
},
|
|
14
|
+
mode,
|
|
15
|
+
devServer: {
|
|
16
|
+
contentBase: path.join(__dirname, 'dist'),
|
|
17
|
+
port: 4000,
|
|
18
|
+
hot: true,
|
|
19
|
+
},
|
|
20
|
+
module: {
|
|
21
|
+
rules: [
|
|
22
|
+
{
|
|
23
|
+
test: /\.tsx?$/,
|
|
24
|
+
use: 'ts-loader',
|
|
25
|
+
exclude: /node_modules/
|
|
26
|
+
}
|
|
27
|
+
]
|
|
28
|
+
},
|
|
29
|
+
resolve: {
|
|
30
|
+
extensions: [ '.ts', '.tsx', '.js' ]
|
|
31
|
+
},
|
|
32
|
+
output: {
|
|
33
|
+
filename: '[name].[hash:5].js',
|
|
34
|
+
path: path.resolve(__dirname, 'dist')
|
|
35
|
+
},
|
|
36
|
+
plugins: [
|
|
37
|
+
new CleanWebpackPlugin(),
|
|
38
|
+
new HtmlWebpackPlugin({
|
|
39
|
+
template: "./index.html"
|
|
40
|
+
})
|
|
41
|
+
],
|
|
42
|
+
};
|
package/dist/auth/apis.d.ts
CHANGED
|
@@ -1,22 +1,21 @@
|
|
|
1
|
-
import { GetVerificationRequest, GetVerificationResponse, UserProfile, UserInfo, SignInRequest, SignUpRequest, VerifyRequest, VerifyResponse, GenProviderRedirectUriRequest, GenProviderRedirectUriResponse, GrantProviderTokenRequest, GrantProviderTokenResponse, PatchProviderTokenRequest, PatchProviderTokenResponse, SignInWithProviderRequest, BindWithProviderRequest, TransByProviderRequest, GrantTokenRequest, UserProfileProvider, UnbindProviderRequest, CheckPasswordrRequest, BindPhoneRequest, SetPasswordRequest, ChangeBindedProviderRequest, ChangeBindedProviderResponse,
|
|
1
|
+
import { GetVerificationRequest, GetVerificationResponse, UserProfile, UserInfo, SignInRequest, SignUpRequest, VerifyRequest, VerifyResponse, GenProviderRedirectUriRequest, GenProviderRedirectUriResponse, GrantProviderTokenRequest, GrantProviderTokenResponse, PatchProviderTokenRequest, PatchProviderTokenResponse, SignInWithProviderRequest, BindWithProviderRequest, TransByProviderRequest, GrantTokenRequest, UserProfileProvider, UnbindProviderRequest, CheckPasswordrRequest, BindPhoneRequest, BindEmailRequest, SetPasswordRequest, ChangeBindedProviderRequest, ChangeBindedProviderResponse, UpdatePasswordRequest, SudoResponse, SudoRequest, GetCustomSignTicketFn, QueryUserProfileRequest, QueryUserProfileResponse, ResetPasswordRequest, DeviceAuthorizeRequest, DeviceAuthorizeResponse, CheckUsernameRequest } from './models';
|
|
2
2
|
import { SimpleStorage, RequestFunction } from '../oauth2client/interface';
|
|
3
3
|
import { OAuth2Client } from '../oauth2client/oauth2client';
|
|
4
4
|
import { Credentials } from '../oauth2client/models';
|
|
5
|
-
import { ICloudbase } from '@cloudbase/types';
|
|
6
5
|
export interface AuthOptions {
|
|
7
6
|
apiOrigin: string;
|
|
8
7
|
clientId: string;
|
|
9
8
|
credentialsClient?: OAuth2Client;
|
|
10
9
|
request?: RequestFunction;
|
|
11
10
|
storage?: SimpleStorage;
|
|
12
|
-
_fromApp?: ICloudbase;
|
|
13
11
|
}
|
|
14
12
|
export declare class Auth {
|
|
15
13
|
private _config;
|
|
14
|
+
private _getCustomSignTicketFn?;
|
|
16
15
|
constructor(opts: AuthOptions);
|
|
17
16
|
signIn(params: SignInRequest): Promise<Credentials>;
|
|
18
17
|
signInAnonymously(): Promise<Credentials>;
|
|
19
|
-
|
|
18
|
+
signUp(params: SignUpRequest): Promise<Credentials>;
|
|
20
19
|
signOut(): Promise<any>;
|
|
21
20
|
getVerification(params: GetVerificationRequest): Promise<GetVerificationResponse>;
|
|
22
21
|
verify(params: VerifyRequest): Promise<VerifyResponse>;
|
|
@@ -36,9 +35,18 @@ export declare class Auth {
|
|
|
36
35
|
unbindProvider(params: UnbindProviderRequest): Promise<void>;
|
|
37
36
|
checkPassword(params: CheckPasswordrRequest): Promise<void>;
|
|
38
37
|
bindPhone(params: BindPhoneRequest): Promise<void>;
|
|
38
|
+
bindEmail(params: BindEmailRequest): Promise<void>;
|
|
39
39
|
setPassword(params: SetPasswordRequest): Promise<void>;
|
|
40
|
+
updatePasswordByOld(params: UpdatePasswordRequest): Promise<void>;
|
|
41
|
+
sudo(params: SudoRequest): Promise<SudoResponse>;
|
|
40
42
|
getCurUserVerification(params: GetVerificationRequest): Promise<GetVerificationResponse>;
|
|
41
43
|
changeBindedProvider(params: ChangeBindedProviderRequest): Promise<ChangeBindedProviderResponse>;
|
|
42
44
|
setUserProfile(params: UserProfile): Promise<UserProfile>;
|
|
43
|
-
queryUserProfile(
|
|
45
|
+
queryUserProfile(params: QueryUserProfileRequest): Promise<QueryUserProfileResponse>;
|
|
46
|
+
setCustomSignFunc(getTickFn: GetCustomSignTicketFn): void;
|
|
47
|
+
signInWithCustomTicket(): Promise<Credentials>;
|
|
48
|
+
resetPassword(params: ResetPasswordRequest): Promise<void>;
|
|
49
|
+
deviceAuthorize(params: DeviceAuthorizeRequest): Promise<DeviceAuthorizeResponse>;
|
|
50
|
+
checkUsername(params: CheckUsernameRequest): Promise<void>;
|
|
51
|
+
loginScope(): Promise<string>;
|
|
44
52
|
}
|