@coze/cli 0.0.2 → 0.0.3
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/cli.mjs +1 -957
- package/dist/index.mjs +1 -263
- package/package.json +1 -1
- package/dist/cli.js +0 -36
- package/dist/commands/base.js +0 -28
- package/dist/commands/login.js +0 -18
- package/dist/commands/logout.js +0 -20
- package/dist/helpers/constants.js +0 -44
- package/dist/helpers/logger.js +0 -21
- package/dist/helpers/package.js +0 -33
- package/dist/helpers/request.js +0 -24
- package/dist/helpers/types.js +0 -2
- package/dist/index.js +0 -2
- package/dist/npm.js +0 -109
- package/dist/oauth.js +0 -61
package/dist/oauth.js
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
/* eslint-disable security/detect-object-injection -- ignore */
|
|
2
|
-
import { Issuer } from 'openid-client';
|
|
3
|
-
import { logger } from './helpers/logger';
|
|
4
|
-
import { CLIENT_ID_MAP, DEFAULT_REGION, ISSUER_MAP, } from './helpers/constants';
|
|
5
|
-
export class OauthClient {
|
|
6
|
-
constructor(region = DEFAULT_REGION) {
|
|
7
|
-
const cozeHubIssuer = new Issuer({
|
|
8
|
-
issuer: ISSUER_MAP[region],
|
|
9
|
-
device_authorization_endpoint: `${ISSUER_MAP[region]}/api/permission/oauth2/device/code`,
|
|
10
|
-
token_endpoint: `${ISSUER_MAP[region]}/api/permission/oauth2/token`,
|
|
11
|
-
revocation_endpoint: `${ISSUER_MAP[region]}/api/permission/oauth2/revoke`,
|
|
12
|
-
scope: 'createMessage',
|
|
13
|
-
});
|
|
14
|
-
this.client = new cozeHubIssuer.Client({
|
|
15
|
-
client_id: CLIENT_ID_MAP[region],
|
|
16
|
-
token_endpoint_auth_method: 'none',
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
async activate(npmConfig) {
|
|
20
|
-
const { refreshToken } = await npmConfig.loadConfig();
|
|
21
|
-
if (refreshToken) {
|
|
22
|
-
try {
|
|
23
|
-
const tokenSet = await this.client.refresh(refreshToken);
|
|
24
|
-
await npmConfig.storeToken(tokenSet);
|
|
25
|
-
}
|
|
26
|
-
catch (e) {
|
|
27
|
-
logger.error('refresh failed: ', e);
|
|
28
|
-
await this.auth(npmConfig);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
else {
|
|
32
|
-
await this.auth(npmConfig);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
async deactivate(npmConfig) {
|
|
36
|
-
const { refreshToken } = await npmConfig.loadConfig();
|
|
37
|
-
await this.client.revoke(refreshToken);
|
|
38
|
-
await npmConfig.clearToken();
|
|
39
|
-
}
|
|
40
|
-
async auth(npmConfig) {
|
|
41
|
-
const handle = await this.client.deviceAuthorization({
|
|
42
|
-
duration_seconds: 86399,
|
|
43
|
-
});
|
|
44
|
-
const completeUrl = `${handle.verification_uri}?user_code=${handle.user_code}`;
|
|
45
|
-
const open = await import('open').then(mod => mod.default);
|
|
46
|
-
await open(completeUrl);
|
|
47
|
-
let tokenSet = null;
|
|
48
|
-
while (!tokenSet) {
|
|
49
|
-
try {
|
|
50
|
-
tokenSet = await handle.poll();
|
|
51
|
-
logger.success('authenticated');
|
|
52
|
-
await npmConfig.storeToken(tokenSet);
|
|
53
|
-
}
|
|
54
|
-
catch (error) {
|
|
55
|
-
logger.error('poll failed:', error);
|
|
56
|
-
throw error;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
//# sourceMappingURL=oauth.js.map
|