@cloudbase/oauth 2.5.48-beta.0 → 2.5.49-beta.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/dist/cjs/auth/apis.d.ts +13 -6
- package/dist/cjs/auth/apis.js +94 -18
- package/dist/cjs/auth/consts.d.ts +5 -0
- package/dist/cjs/auth/consts.js +6 -1
- package/dist/cjs/auth/models.d.ts +60 -2
- package/dist/cjs/auth/models.js +1 -1
- package/dist/cjs/index.d.ts +2 -1
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/oauth2client/models.d.ts +1 -0
- package/dist/cjs/oauth2client/models.js +1 -1
- package/dist/cjs/oauth2client/oauth2client.d.ts +5 -0
- package/dist/cjs/oauth2client/oauth2client.js +23 -14
- package/dist/cjs/utils/base64.d.ts +4 -0
- package/dist/cjs/utils/base64.js +99 -0
- package/dist/esm/auth/apis.d.ts +13 -6
- package/dist/esm/auth/apis.js +94 -18
- package/dist/esm/auth/consts.d.ts +5 -0
- package/dist/esm/auth/consts.js +6 -1
- package/dist/esm/auth/models.d.ts +60 -2
- package/dist/esm/auth/models.js +1 -1
- package/dist/esm/index.d.ts +2 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/oauth2client/models.d.ts +1 -0
- package/dist/esm/oauth2client/models.js +1 -1
- package/dist/esm/oauth2client/oauth2client.d.ts +5 -0
- package/dist/esm/oauth2client/oauth2client.js +23 -14
- package/dist/esm/utils/base64.d.ts +4 -0
- package/dist/esm/utils/base64.js +92 -0
- package/package.json +2 -2
- package/src/auth/apis.ts +102 -30
- package/src/auth/consts.ts +5 -0
- package/src/auth/models.ts +103 -38
- package/src/index.ts +3 -9
- package/src/oauth2client/models.ts +1 -0
- package/src/oauth2client/oauth2client.ts +27 -16
- package/src/utils/base64.ts +100 -0
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
// weapp jwt-decode
|
|
3
|
+
const b64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='
|
|
4
|
+
const b64re = /^(?:[A-Za-z\d+/]{4})*?(?:[A-Za-z\d+/]{2}(?:==)?|[A-Za-z\d+/]{3}=?)?$/
|
|
5
|
+
|
|
6
|
+
// btoa
|
|
7
|
+
export function weBtoa(string: string) {
|
|
8
|
+
string = String(string)
|
|
9
|
+
let bitmap
|
|
10
|
+
let a
|
|
11
|
+
let b
|
|
12
|
+
let c
|
|
13
|
+
let result = ''
|
|
14
|
+
let i = 0
|
|
15
|
+
const rest = string.length % 3
|
|
16
|
+
|
|
17
|
+
for (; i < string.length;) {
|
|
18
|
+
if ((a = string.charCodeAt(i++)) > 255 || (b = string.charCodeAt(i++)) > 255 || (c = string.charCodeAt(i++)) > 255) throw new TypeError('Failed to execute \'btoa\' on \'Window\': The string to be encoded contains characters outside of the Latin1 range.',)
|
|
19
|
+
|
|
20
|
+
bitmap = (a << 16) | (b << 8) | c
|
|
21
|
+
result
|
|
22
|
+
+= b64.charAt((bitmap >> 18) & 63)
|
|
23
|
+
+ b64.charAt((bitmap >> 12) & 63)
|
|
24
|
+
+ b64.charAt((bitmap >> 6) & 63)
|
|
25
|
+
+ b64.charAt(bitmap & 63)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return rest ? result.slice(0, rest - 3) + '==='.substring(rest) : result
|
|
29
|
+
}
|
|
30
|
+
// atob
|
|
31
|
+
export const weAtob = function (string: string) {
|
|
32
|
+
string = String(string).replace(/[\t\n\f\r ]+/g, '')
|
|
33
|
+
if (!b64re.test(string)) throw new TypeError('Failed to execute \'atob\' on \'Window\': The string to be decoded is not correctly encoded.')
|
|
34
|
+
string += '=='.slice(2 - (string.length & 3))
|
|
35
|
+
let bitmap
|
|
36
|
+
let result = ''
|
|
37
|
+
let r1
|
|
38
|
+
let r2
|
|
39
|
+
let i = 0
|
|
40
|
+
for (; i < string.length;) {
|
|
41
|
+
bitmap = (b64.indexOf(string.charAt(i++)) << 18)
|
|
42
|
+
| (b64.indexOf(string.charAt(i++)) << 12)
|
|
43
|
+
| ((r1 = b64.indexOf(string.charAt(i++))) << 6)
|
|
44
|
+
| (r2 = b64.indexOf(string.charAt(i++)))
|
|
45
|
+
|
|
46
|
+
result
|
|
47
|
+
+= r1 === 64
|
|
48
|
+
? String.fromCharCode((bitmap >> 16) & 255)
|
|
49
|
+
: r2 === 64
|
|
50
|
+
? String.fromCharCode((bitmap >> 16) & 255, (bitmap >> 8) & 255)
|
|
51
|
+
: String.fromCharCode((bitmap >> 16) & 255, (bitmap >> 8) & 255, bitmap & 255)
|
|
52
|
+
}
|
|
53
|
+
return result
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function b64DecodeUnicode(str: string) {
|
|
57
|
+
return decodeURIComponent(weAtob(str).replace(/(.)/g, (p) => {
|
|
58
|
+
let code = p.charCodeAt(0).toString(16)
|
|
59
|
+
.toUpperCase()
|
|
60
|
+
if (code.length < 2) {
|
|
61
|
+
code = `0${code}`
|
|
62
|
+
}
|
|
63
|
+
return `%${code}`
|
|
64
|
+
}),)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function base64_url_decode(str: string) {
|
|
68
|
+
let output = str.replace(/-/g, '+').replace(/_/g, '/')
|
|
69
|
+
switch (output.length % 4) {
|
|
70
|
+
case 0:
|
|
71
|
+
break
|
|
72
|
+
case 2:
|
|
73
|
+
output += '=='
|
|
74
|
+
break
|
|
75
|
+
case 3:
|
|
76
|
+
output += '='
|
|
77
|
+
break
|
|
78
|
+
default:
|
|
79
|
+
throw new Error('Illegal base64url string!')
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
try {
|
|
83
|
+
return b64DecodeUnicode(output)
|
|
84
|
+
} catch (err) {
|
|
85
|
+
return weAtob(output)
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export function weappJwtDecode(token: string, options?: any) {
|
|
90
|
+
if (typeof token !== 'string') {
|
|
91
|
+
throw new Error('Invalid token specified')
|
|
92
|
+
}
|
|
93
|
+
options = options || {}
|
|
94
|
+
const pos = options.header === true ? 0 : 1
|
|
95
|
+
try {
|
|
96
|
+
return JSON.parse(base64_url_decode(token.split('.')[pos]))
|
|
97
|
+
} catch (e) {
|
|
98
|
+
throw new Error(`Invalid token specified: ${e}` ? (e as any).message : '')
|
|
99
|
+
}
|
|
100
|
+
}
|