@cloudbase/oauth 2.25.3 → 2.25.4
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/{types → cjs}/auth/apis.d.ts +2 -2
- package/dist/cjs/auth/apis.js +1 -1
- package/dist/{types → cjs}/auth/models.d.ts +8 -2
- package/dist/cjs/auth/models.js +1 -1
- package/dist/{types → cjs}/index.d.ts +3 -2
- package/dist/cjs/index.js +3 -3
- package/dist/{types → cjs}/utils/base64.d.ts +1 -1
- package/dist/cjs/utils/base64.js +4 -4
- package/dist/esm/auth/apis.d.ts +141 -0
- package/dist/esm/auth/auth-error.d.ts +6 -0
- package/dist/esm/auth/consts.d.ts +132 -0
- package/dist/esm/auth/models.d.ts +550 -0
- package/dist/esm/captcha/captcha-dom.d.ts +3 -0
- package/dist/esm/captcha/captcha.d.ts +42 -0
- package/dist/esm/index.d.ts +23 -0
- package/dist/esm/index.js +1 -1
- package/dist/esm/oauth2client/consts.d.ts +20 -0
- package/dist/esm/oauth2client/interface.d.ts +15 -0
- package/dist/esm/oauth2client/models.d.ts +74 -0
- package/dist/esm/oauth2client/oauth2client.d.ts +129 -0
- package/dist/esm/utils/base64.d.ts +9 -0
- package/dist/esm/utils/base64.js +1 -1
- package/dist/esm/utils/encrypt.d.ts +4 -0
- package/dist/esm/utils/encryptlong/index.d.ts +546 -0
- package/dist/esm/utils/function/single-promise.d.ts +6 -0
- package/dist/esm/utils/index.d.ts +2 -0
- package/dist/esm/utils/mp.d.ts +2 -0
- package/dist/esm/utils/urlSearchParams.d.ts +13 -0
- package/dist/esm/utils/uuid.d.ts +1 -0
- package/dist/miniprogram/index.js +1 -1
- package/package.json +5 -4
- package/src/auth/apis.ts +4 -4
- package/src/auth/models.ts +8 -2
- package/src/index.ts +2 -2
- package/src/utils/base64.ts +1 -1
- package/tsconfig.json +1 -2
- /package/dist/{types → cjs}/auth/auth-error.d.ts +0 -0
- /package/dist/{types → cjs}/auth/consts.d.ts +0 -0
- /package/dist/{types → cjs}/captcha/captcha-dom.d.ts +0 -0
- /package/dist/{types → cjs}/captcha/captcha.d.ts +0 -0
- /package/dist/{types → cjs}/oauth2client/consts.d.ts +0 -0
- /package/dist/{types → cjs}/oauth2client/interface.d.ts +0 -0
- /package/dist/{types → cjs}/oauth2client/models.d.ts +0 -0
- /package/dist/{types → cjs}/oauth2client/oauth2client.d.ts +0 -0
- /package/dist/{types → cjs}/utils/encrypt.d.ts +0 -0
- /package/dist/{types → cjs}/utils/encryptlong/index.d.ts +0 -0
- /package/dist/{types → cjs}/utils/function/single-promise.d.ts +0 -0
- /package/dist/{types → cjs}/utils/index.d.ts +0 -0
- /package/dist/{types → cjs}/utils/mp.d.ts +0 -0
- /package/dist/{types → cjs}/utils/urlSearchParams.d.ts +0 -0
- /package/dist/{types → cjs}/utils/uuid.d.ts +0 -0
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { SimpleStorage } from './interface';
|
|
2
|
+
import { ErrorType } from './consts';
|
|
3
|
+
import { AuthOptions } from '../auth/apis';
|
|
4
|
+
import { ICloudbaseConfig } from '@cloudbase/types';
|
|
5
|
+
export interface Credentials {
|
|
6
|
+
token_type?: string | null;
|
|
7
|
+
access_token?: string | null;
|
|
8
|
+
refresh_token?: string | null;
|
|
9
|
+
scope?: string | null;
|
|
10
|
+
expires_in?: number | null;
|
|
11
|
+
expires_at?: Date | null;
|
|
12
|
+
sub?: string | null;
|
|
13
|
+
groups?: string[] | null;
|
|
14
|
+
version?: string;
|
|
15
|
+
}
|
|
16
|
+
export interface ResponseError {
|
|
17
|
+
error: ErrorType;
|
|
18
|
+
error_description?: string | null;
|
|
19
|
+
error_uri?: string | null;
|
|
20
|
+
details?: any | null;
|
|
21
|
+
}
|
|
22
|
+
export interface RequestOptions {
|
|
23
|
+
body?: any | null;
|
|
24
|
+
headers?: any | null;
|
|
25
|
+
method?: string;
|
|
26
|
+
[key: string]: any;
|
|
27
|
+
}
|
|
28
|
+
export type RequestFunction = <T>(url: string, options?: RequestOptions) => Promise<T>;
|
|
29
|
+
export interface AuthClientRequestOptions extends RequestOptions {
|
|
30
|
+
headers?: {
|
|
31
|
+
'x-request-id'?: string;
|
|
32
|
+
[key: string]: any;
|
|
33
|
+
} | null;
|
|
34
|
+
withCredentials?: boolean;
|
|
35
|
+
withBasicAuth?: boolean;
|
|
36
|
+
retry?: number;
|
|
37
|
+
useWxCloud?: boolean;
|
|
38
|
+
getCredentials?: () => Credentials | Promise<Credentials | null> | null;
|
|
39
|
+
[key: string]: any;
|
|
40
|
+
}
|
|
41
|
+
export interface OAuth2ClientOptions {
|
|
42
|
+
devMode?: boolean;
|
|
43
|
+
apiOrigin: string;
|
|
44
|
+
apiPath?: string;
|
|
45
|
+
clientId: string;
|
|
46
|
+
env: string;
|
|
47
|
+
retry?: number;
|
|
48
|
+
baseRequest?: <T>(url: string, options?: RequestOptions) => Promise<T>;
|
|
49
|
+
storage?: SimpleStorage;
|
|
50
|
+
clientSecret?: string;
|
|
51
|
+
refreshTokenFunc?: (refreshToken?: string) => Promise<Credentials>;
|
|
52
|
+
tokenInURL?: boolean;
|
|
53
|
+
headers?: {
|
|
54
|
+
[key: string]: string;
|
|
55
|
+
};
|
|
56
|
+
anonymousSignInFunc?: (Credentials: any) => Promise<Credentials | void>;
|
|
57
|
+
wxCloud?: any;
|
|
58
|
+
onCredentialsError?: AuthOptions['onCredentialsError'];
|
|
59
|
+
i18n?: ICloudbaseConfig['i18n'];
|
|
60
|
+
useWxCloud?: boolean;
|
|
61
|
+
eventBus?: any;
|
|
62
|
+
debug?: boolean;
|
|
63
|
+
getInitialSession?: () => Promise<{
|
|
64
|
+
data: {
|
|
65
|
+
session: Credentials;
|
|
66
|
+
user?: any;
|
|
67
|
+
} | null;
|
|
68
|
+
error: Error | null;
|
|
69
|
+
}>;
|
|
70
|
+
onInitialSessionObtained?: (data: {
|
|
71
|
+
session: Credentials;
|
|
72
|
+
user?: any;
|
|
73
|
+
}) => void | Promise<void>;
|
|
74
|
+
}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { ErrorType } from './consts';
|
|
2
|
+
import { AuthClient, SimpleStorage } from './interface';
|
|
3
|
+
import { Credentials, ResponseError, RequestOptions, RequestFunction, OAuth2ClientOptions, AuthClientRequestOptions } from './models';
|
|
4
|
+
export interface ToResponseErrorOptions {
|
|
5
|
+
error?: ErrorType;
|
|
6
|
+
error_description?: string | null;
|
|
7
|
+
error_uri?: string | null;
|
|
8
|
+
details?: any | null;
|
|
9
|
+
}
|
|
10
|
+
export declare const defaultRequest: RequestFunction;
|
|
11
|
+
export declare const toResponseError: (error: ResponseError | Error, options?: ToResponseErrorOptions) => ResponseError;
|
|
12
|
+
export declare function generateRequestId(): string;
|
|
13
|
+
declare class DefaultStorage implements SimpleStorage {
|
|
14
|
+
private readonly _env;
|
|
15
|
+
constructor(opts?: {
|
|
16
|
+
env: string;
|
|
17
|
+
});
|
|
18
|
+
getItem(key: string): Promise<string | null>;
|
|
19
|
+
removeItem(key: string): Promise<void>;
|
|
20
|
+
setItem(key: string, value: string): Promise<void>;
|
|
21
|
+
getItemSync(key: string): string | null;
|
|
22
|
+
removeItemSync(key: string): void;
|
|
23
|
+
setItemSync(key: string, value: string): void;
|
|
24
|
+
}
|
|
25
|
+
export declare const defaultStorage: DefaultStorage;
|
|
26
|
+
interface LocalCredentialsOptions {
|
|
27
|
+
tokenSectionName: string;
|
|
28
|
+
storage: SimpleStorage;
|
|
29
|
+
clientId: string;
|
|
30
|
+
credentials?: Credentials;
|
|
31
|
+
}
|
|
32
|
+
declare class LocalCredentials {
|
|
33
|
+
private tokenSectionName;
|
|
34
|
+
private storage;
|
|
35
|
+
private clientId;
|
|
36
|
+
private credentials;
|
|
37
|
+
private accessKeyCredentials;
|
|
38
|
+
private singlePromise;
|
|
39
|
+
constructor(options: LocalCredentialsOptions);
|
|
40
|
+
getStorageCredentialsSync(): Credentials | null;
|
|
41
|
+
setCredentials(credentials?: Credentials): Promise<void>;
|
|
42
|
+
setAccessKeyCredentials(credentials?: Credentials): void;
|
|
43
|
+
getCredentials(): Promise<Credentials | null>;
|
|
44
|
+
private getStorageCredentials;
|
|
45
|
+
}
|
|
46
|
+
export declare class OAuth2Client implements AuthClient {
|
|
47
|
+
private static defaultRetry;
|
|
48
|
+
private static minRetry;
|
|
49
|
+
private static maxRetry;
|
|
50
|
+
private static retryInterval;
|
|
51
|
+
localCredentials: LocalCredentials;
|
|
52
|
+
initializePromise: Promise<{
|
|
53
|
+
error: Error | null;
|
|
54
|
+
}> | null;
|
|
55
|
+
protected lockAcquired: boolean;
|
|
56
|
+
protected pendingInLock: Promise<any>[];
|
|
57
|
+
protected logDebugMessages: boolean;
|
|
58
|
+
protected getInitialSession?: () => Promise<{
|
|
59
|
+
data: {
|
|
60
|
+
session: Credentials;
|
|
61
|
+
user?: any;
|
|
62
|
+
} | null;
|
|
63
|
+
error: Error | null;
|
|
64
|
+
}>;
|
|
65
|
+
private apiOrigin;
|
|
66
|
+
private apiPath;
|
|
67
|
+
private clientId;
|
|
68
|
+
private i18n;
|
|
69
|
+
private retry;
|
|
70
|
+
private clientSecret?;
|
|
71
|
+
private baseRequest;
|
|
72
|
+
private storage;
|
|
73
|
+
private deviceID?;
|
|
74
|
+
private tokenInURL?;
|
|
75
|
+
private refreshTokenFunc;
|
|
76
|
+
private headers?;
|
|
77
|
+
private singlePromise;
|
|
78
|
+
private anonymousSignInFunc;
|
|
79
|
+
private wxCloud;
|
|
80
|
+
private useWxCloud;
|
|
81
|
+
private eventBus;
|
|
82
|
+
private basicAuth;
|
|
83
|
+
private onCredentialsError;
|
|
84
|
+
private onInitialSessionObtained?;
|
|
85
|
+
constructor(options: OAuth2ClientOptions);
|
|
86
|
+
setGetInitialSession(callback: () => Promise<{
|
|
87
|
+
data: {
|
|
88
|
+
session: Credentials;
|
|
89
|
+
user?: any;
|
|
90
|
+
} | null;
|
|
91
|
+
error: Error | null;
|
|
92
|
+
}>): void;
|
|
93
|
+
setOnInitialSessionObtained(callback: (data: {
|
|
94
|
+
session: Credentials;
|
|
95
|
+
user?: any;
|
|
96
|
+
}) => void | Promise<void>): void;
|
|
97
|
+
initialize(func?: Promise<{
|
|
98
|
+
error: Error | null;
|
|
99
|
+
}>): Promise<{
|
|
100
|
+
error: Error | null;
|
|
101
|
+
}>;
|
|
102
|
+
setCredentials(credentials?: Credentials): Promise<void>;
|
|
103
|
+
setAccessKeyCredentials(credentials?: Credentials): void;
|
|
104
|
+
getAccessToken(): Promise<string>;
|
|
105
|
+
request<T>(url: string, options?: AuthClientRequestOptions): Promise<T>;
|
|
106
|
+
wxCloudCallFunction<T>(url: string, options?: RequestOptions): Promise<T>;
|
|
107
|
+
getCredentials(): Promise<Credentials | null>;
|
|
108
|
+
getCredentialsSync(): Credentials | null;
|
|
109
|
+
getCredentialsAsync(): Promise<Credentials | null>;
|
|
110
|
+
getScope(): Promise<string>;
|
|
111
|
+
getGroups(): Promise<string[]>;
|
|
112
|
+
refreshToken(credentials: Credentials, options?: {
|
|
113
|
+
throwError?: boolean;
|
|
114
|
+
}): Promise<Credentials>;
|
|
115
|
+
private _refreshToken;
|
|
116
|
+
private anonymousLogin;
|
|
117
|
+
private checkRetry;
|
|
118
|
+
private formatRetry;
|
|
119
|
+
private sleep;
|
|
120
|
+
private anonymousSignIn;
|
|
121
|
+
private defaultRefreshTokenFunc;
|
|
122
|
+
private getDeviceId;
|
|
123
|
+
private unAuthenticatedError;
|
|
124
|
+
private _debug;
|
|
125
|
+
private _initialize;
|
|
126
|
+
private _acquireLock;
|
|
127
|
+
private _getCredentials;
|
|
128
|
+
}
|
|
129
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare function weBtoa(string: string): string;
|
|
2
|
+
export declare const weAtob: (string: string) => string;
|
|
3
|
+
export declare function base64_url_decode(str: string): string;
|
|
4
|
+
export declare function weappJwtDecode(token: string, options?: any): any;
|
|
5
|
+
export declare function weAppJwtDecodeAll(token: string): {
|
|
6
|
+
claims: any;
|
|
7
|
+
header: any;
|
|
8
|
+
signature: any;
|
|
9
|
+
};
|
package/dist/esm/utils/base64.js
CHANGED
|
@@ -89,7 +89,7 @@ export function weappJwtDecode(token, options) {
|
|
|
89
89
|
throw new Error(`Invalid token specified: ${e}` ? e.message : '');
|
|
90
90
|
}
|
|
91
91
|
}
|
|
92
|
-
export function
|
|
92
|
+
export function weAppJwtDecodeAll(token) {
|
|
93
93
|
if (typeof token !== 'string') {
|
|
94
94
|
throw new Error('Invalid token specified');
|
|
95
95
|
}
|