Skip to content

Commit 90edb0c

Browse files
fix: Fix downscope token to use retrieveToken method for token retrieval (box/box-codegen#731) (#618)
1 parent 8a74db0 commit 90edb0c

12 files changed

+212
-114
lines changed

.codegen.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{ "engineHash": "c6650a9", "specHash": "a8825be", "version": "1.15.1" }
1+
{ "engineHash": "20cb559", "specHash": "a8825be", "version": "1.15.1" }

docs/docgen.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ See the endpoint docs at
1717
<!-- sample get_docgen_jobs_id_v2025.0 -->
1818

1919
```ts
20-
await client.docgen.getDocgenJobByIdV2025R0(docgenJobs.entries![0].id);
20+
await client.docgen.getDocgenJobByIdV2025R0(docgenJobItemFromList.id);
2121
```
2222

2323
### Arguments
@@ -45,7 +45,9 @@ See the endpoint docs at
4545
<!-- sample get_docgen_jobs_v2025.0 -->
4646

4747
```ts
48-
await client.docgen.getDocgenJobsV2025R0();
48+
await client.docgen.getDocgenJobsV2025R0({
49+
limit: 500,
50+
} satisfies GetDocgenJobsV2025R0QueryParams);
4951
```
5052

5153
### Arguments

package-lock.json

Lines changed: 101 additions & 101 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/box/ccgAuth.generated.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,8 @@ export class BoxCcgAuth implements Authentication {
202202
sharedLink?: string,
203203
networkSession?: NetworkSession,
204204
): Promise<AccessToken> {
205-
const token: undefined | AccessToken = await this.tokenStorage.get();
205+
const token: undefined | AccessToken =
206+
await this.retrieveToken(networkSession);
206207
if (token == void 0) {
207208
throw new BoxSdkError({
208209
message:

src/box/developerTokenAuth.generated.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,8 @@ export class BoxDeveloperTokenAuth implements Authentication {
113113
sharedLink?: string,
114114
networkSession?: NetworkSession,
115115
): Promise<AccessToken> {
116-
const token: undefined | AccessToken = await this.tokenStorage.get();
116+
const token: undefined | AccessToken =
117+
await this.retrieveToken(networkSession);
117118
if (token == void 0 || token!.accessToken == void 0) {
118119
throw new BoxSdkError({ message: 'No access token is available.' });
119120
}

src/box/jwtAuth.generated.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,8 @@ export class BoxJwtAuth implements Authentication {
374374
sharedLink?: string,
375375
networkSession?: NetworkSession,
376376
): Promise<AccessToken> {
377-
const token: undefined | AccessToken = await this.tokenStorage.get();
377+
const token: undefined | AccessToken =
378+
await this.retrieveToken(networkSession);
378379
if (token == void 0) {
379380
throw new BoxSdkError({
380381
message:

src/box/oauth.generated.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,8 @@ export class BoxOAuth implements Authentication {
213213
sharedLink?: string,
214214
networkSession?: NetworkSession,
215215
): Promise<AccessToken> {
216-
const token: undefined | AccessToken = await this.tokenStorage.get();
216+
const token: undefined | AccessToken =
217+
await this.retrieveToken(networkSession);
217218
if (token == void 0 || token!.accessToken == void 0) {
218219
throw new BoxSdkError({ message: 'No access token is available.' });
219220
}

src/test/auth.generated.test.ts

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,32 @@ test('test_jwt_auth_downscope', async function test_jwt_auth_downscope(): Promis
137137
}).rejects.toThrow();
138138
await parentClient.files.deleteFileById(file.id);
139139
});
140+
test('test_jwt_downscope_token_succeeds_if_no_token_available', async function test_jwt_downscope_token_succeeds_if_no_token_available(): Promise<any> {
141+
const jwtConfig: JwtConfig = JwtConfig.fromConfigJsonString(
142+
decodeBase64(getEnvVar('JWT_CONFIG_BASE_64')),
143+
);
144+
const auth: BoxJwtAuth = new BoxJwtAuth({ config: jwtConfig });
145+
const downscopedToken: AccessToken = await auth.downscopeToken([
146+
'root_readonly',
147+
]);
148+
if (!!(downscopedToken.accessToken == void 0)) {
149+
throw new Error('Assertion failed');
150+
}
151+
const downscopedClient: BoxClient = new BoxClient({
152+
auth: new BoxDeveloperTokenAuth({ token: downscopedToken.accessToken! }),
153+
});
154+
await expect(async () => {
155+
await downscopedClient.uploads.uploadFile({
156+
attributes: {
157+
name: getUuid(),
158+
parent: {
159+
id: '0',
160+
} satisfies UploadFileRequestBodyAttributesParentField,
161+
} satisfies UploadFileRequestBodyAttributesField,
162+
file: generateByteStream(1024 * 1024),
163+
} satisfies UploadFileRequestBody);
164+
}).rejects.toThrow();
165+
});
140166
test('test_jwt_auth_revoke', async function test_jwt_auth_revoke(): Promise<any> {
141167
const jwtConfig: JwtConfig = JwtConfig.fromConfigJsonString(
142168
decodeBase64(getEnvVar('JWT_CONFIG_BASE_64')),
@@ -175,6 +201,19 @@ test('test_oauth_auth_authorizeUrl', function test_oauth_auth_authorizeUrl(): an
175201
throw new Error('Assertion failed');
176202
}
177203
});
204+
test('test_oauth_downscope_token_succeeds_if_no_token_available', async function test_oauth_downscope_token_succeeds_if_no_token_available(): Promise<any> {
205+
const config: OAuthConfig = new OAuthConfig({
206+
clientId: getEnvVar('CLIENT_ID'),
207+
clientSecret: getEnvVar('CLIENT_SECRET'),
208+
});
209+
const auth: BoxOAuth = new BoxOAuth({ config: config });
210+
const resourcePath: string = ''.concat(
211+
'https://api.box.com/2.0/files/12345',
212+
) as string;
213+
await expect(async () => {
214+
await auth.downscopeToken(['item_rename', 'item_preview'], resourcePath);
215+
}).rejects.toThrow();
216+
});
178217
test('test_ccg_auth', async function test_ccg_auth(): Promise<any> {
179218
const userId: string = getEnvVar('USER_ID');
180219
const enterpriseId: string = getEnvVar('ENTERPRISE_ID');
@@ -240,6 +279,34 @@ test('test_ccg_auth_downscope', async function test_ccg_auth_downscope(): Promis
240279
}).rejects.toThrow();
241280
await parentClient.folders.deleteFolderById(folder.id);
242281
});
282+
test('test_ccg_downscope_token_succeeds_if_no_token_available', async function test_ccg_downscope_token_succeeds_if_no_token_available(): Promise<any> {
283+
const ccgConfig: CcgConfig = new CcgConfig({
284+
clientId: getEnvVar('CLIENT_ID'),
285+
clientSecret: getEnvVar('CLIENT_SECRET'),
286+
userId: getEnvVar('USER_ID'),
287+
});
288+
const auth: BoxCcgAuth = new BoxCcgAuth({ config: ccgConfig });
289+
const downscopedToken: AccessToken = await auth.downscopeToken([
290+
'root_readonly',
291+
]);
292+
if (!!(downscopedToken.accessToken == void 0)) {
293+
throw new Error('Assertion failed');
294+
}
295+
const downscopedClient: BoxClient = new BoxClient({
296+
auth: new BoxDeveloperTokenAuth({ token: downscopedToken.accessToken! }),
297+
});
298+
await expect(async () => {
299+
await downscopedClient.uploads.uploadFile({
300+
attributes: {
301+
name: getUuid(),
302+
parent: {
303+
id: '0',
304+
} satisfies UploadFileRequestBodyAttributesParentField,
305+
} satisfies UploadFileRequestBodyAttributesField,
306+
file: generateByteStream(1024 * 1024),
307+
} satisfies UploadFileRequestBody);
308+
}).rejects.toThrow();
309+
});
243310
test('test_ccg_auth_revoke', async function test_ccg_auth_revoke(): Promise<any> {
244311
const ccgConfig: CcgConfig = new CcgConfig({
245312
clientId: getEnvVar('CLIENT_ID'),
@@ -262,6 +329,22 @@ test('test_ccg_auth_revoke', async function test_ccg_auth_revoke(): Promise<any>
262329
throw new Error('Assertion failed');
263330
}
264331
});
332+
test('test_developer_downscope_token_succeeds_if_no_token_available', async function test_developer_downscope_token_succeeds_if_no_token_available(): Promise<any> {
333+
const developerTokenConfig: DeveloperTokenConfig = {
334+
clientId: getEnvVar('CLIENT_ID'),
335+
clientSecret: getEnvVar('CLIENT_SECRET'),
336+
} satisfies DeveloperTokenConfig;
337+
const auth: BoxDeveloperTokenAuth = new BoxDeveloperTokenAuth({
338+
token: '',
339+
config: developerTokenConfig,
340+
});
341+
const resourcePath: string = ''.concat(
342+
'https://api.box.com/2.0/folders/12345',
343+
) as string;
344+
await expect(async () => {
345+
await auth.downscopeToken(['item_rename', 'item_preview'], resourcePath);
346+
}).rejects.toThrow();
347+
});
265348
test('test_developer_token_auth_revoke', async function test_developer_token_auth_revoke(): Promise<any> {
266349
const developerTokenConfig: DeveloperTokenConfig = {
267350
clientId: getEnvVar('CLIENT_ID'),

src/test/collections.generated.test.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,7 @@ test('testCollections', async function testCollections(): Promise<any> {
6666
} satisfies UpdateFolderByIdOptionalsInput);
6767
const collectionItemsAfterUpdate: ItemsOffsetPaginated =
6868
await client.collections.getCollectionItems(favouriteCollection.id!);
69-
if (
70-
!(collectionItemsAfterUpdate.totalCount! == collectionItems.totalCount! + 1)
71-
) {
69+
if (!(collectionItemsAfterUpdate.totalCount! > 0)) {
7270
throw new Error('Assertion failed');
7371
}
7472
await client.folders.updateFolderById(folder.id, {

src/test/docgen.generated.test.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ import { serializeDocGenJobsV2025R0 } from '../schemas/v2025R0/docGenJobsV2025R0
2020
import { deserializeDocGenJobsV2025R0 } from '../schemas/v2025R0/docGenJobsV2025R0.generated.js';
2121
import { serializeDocGenJobsFullV2025R0 } from '../schemas/v2025R0/docGenJobsFullV2025R0.generated.js';
2222
import { deserializeDocGenJobsFullV2025R0 } from '../schemas/v2025R0/docGenJobsFullV2025R0.generated.js';
23+
import { serializeDocGenJobFullV2025R0 } from '../schemas/v2025R0/docGenJobFullV2025R0.generated.js';
24+
import { deserializeDocGenJobFullV2025R0 } from '../schemas/v2025R0/docGenJobFullV2025R0.generated.js';
2325
import { serializeDocGenJobV2025R0 } from '../schemas/v2025R0/docGenJobV2025R0.generated.js';
2426
import { deserializeDocGenJobV2025R0 } from '../schemas/v2025R0/docGenJobV2025R0.generated.js';
2527
import { BoxClient } from '../client.generated.js';
@@ -34,6 +36,8 @@ import { DocGenBatchCreateRequestV2025R0DestinationFolderField } from '../schema
3436
import { DocGenDocumentGenerationDataV2025R0 } from '../schemas/v2025R0/docGenDocumentGenerationDataV2025R0.generated.js';
3537
import { DocGenJobsV2025R0 } from '../schemas/v2025R0/docGenJobsV2025R0.generated.js';
3638
import { DocGenJobsFullV2025R0 } from '../schemas/v2025R0/docGenJobsFullV2025R0.generated.js';
39+
import { GetDocgenJobsV2025R0QueryParams } from '../managers/docgen.generated.js';
40+
import { DocGenJobFullV2025R0 } from '../schemas/v2025R0/docGenJobFullV2025R0.generated.js';
3741
import { DocGenJobV2025R0 } from '../schemas/v2025R0/docGenJobV2025R0.generated.js';
3842
import { getDefaultClient } from './commons.generated.js';
3943
import { uploadNewFile } from './commons.generated.js';
@@ -103,7 +107,9 @@ test('testDocgenBatchAndJobs', async function testDocgenBatchAndJobs(): Promise<
103107
throw new Error('Assertion failed');
104108
}
105109
const docgenJobs: DocGenJobsFullV2025R0 =
106-
await client.docgen.getDocgenJobsV2025R0();
110+
await client.docgen.getDocgenJobsV2025R0({
111+
limit: 500,
112+
} satisfies GetDocgenJobsV2025R0QueryParams);
107113
if (!(docgenJobs.entries!.length >= 1)) {
108114
throw new Error('Assertion failed');
109115
}
@@ -150,8 +156,11 @@ test('testDocgenBatchAndJobs', async function testDocgenBatchAndJobs(): Promise<
150156
if (!((toString(docgenJobs.entries![0].type) as string) == 'docgen_job')) {
151157
throw new Error('Assertion failed');
152158
}
159+
const indexOfItem: number = 0;
160+
const docgenJobItemFromList: DocGenJobFullV2025R0 =
161+
docgenJobs.entries![indexOfItem];
153162
const docgenJob: DocGenJobV2025R0 =
154-
await client.docgen.getDocgenJobByIdV2025R0(docgenJobs.entries![0].id);
163+
await client.docgen.getDocgenJobByIdV2025R0(docgenJobItemFromList.id);
155164
if (!!(docgenJob.batch.id == '')) {
156165
throw new Error('Assertion failed');
157166
}

src/test/events.generated.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,8 @@ test('testEventSourceFileOrFolder', async function testEventSourceFileOrFolder()
118118
if (
119119
!(
120120
(toString(source.type) as string) == 'file' ||
121-
(toString(source.type) as string) == 'folder'
121+
(toString(source.type) as string) == 'folder' ||
122+
(toString(source.type) as string) == 'collaboration'
122123
)
123124
) {
124125
throw new Error('Assertion failed');

test-browser/sdkTest.config.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ export const testConfig = {
33
test_jwt_auth: 'skip',
44
test_jwt_auth_downscope: 'skip',
55
test_jwt_auth_revoke: 'skip',
6+
test_jwt_downscope_token_succeeds_if_no_token_available: 'skip',
67

78
// Unknown reason, these tests fail in browser
89
testDocgenBatchAndJobs: 'skip',

0 commit comments

Comments
 (0)