box / box-typescript-sdk-gen

Repository for generated Box TS SDK
Apache License 2.0
14 stars 1 forks source link

Can't deserialize FileOrFolderScopeScopeField #250

Closed namack closed 2 weeks ago

namack commented 1 month ago

Description of the Issue

Downscoping of a token with the scope item_upload causes serialization issues.

Downscoping a token using the base_explorer scope on a resource works as intended:

const token = await client.auth.downscopeToken(
    ['base_explorer'],
    `https://api.box.com/2.0/folders/${folderId}`,
  );

However, once the item_upload scope is added a deserialization error is thrown:

const token = await client.auth.downscopeToken(
    ['base_explorer', 'item_upload'],
    `https://api.box.com/2.0/folders/${folderId}`,
  );

Error:

BoxSDKError: {
  "message": "Can't deserialize FileOrFolderScopeScopeField"
}

I believe this scope is missing in the deserializeFileOrFolderScopeScopeField function.

https://github.com/box/box-typescript-sdk-gen/blob/20d347d956db05bc2e87f771dc1cab1308915f59/src/schemas/fileOrFolderScope.generated.ts#L34

Steps to Reproduce

Call the downscopeToken function with item_upload included in the scope:

const token = await client.auth.downscopeToken(
    ['base_explorer', 'item_upload'],
    `https://api.box.com/2.0/folders/${folderId}`,
  );

Expected Behavior

I expect a valid token to be returned to allow the App User to upload files and create folders.

Error Message, Including Stack Trace

{
  "message": "Can't deserialize FileOrFolderScopeScopeField"
}
at deserializeFileOrFolderScopeScopeField (/app/node_modules/box-typescript-sdk-gen/src/schemas/fileOrFolderScope.generated.ts:73:9)
at y8u (/app/node_modules/box-typescript-sdk-gen/src/schemas/fileOrFolderScope.generated.ts:100:9)
at <anonymous> (/app/node_modules/box-typescript-sdk-gen/src/schemas/accessToken.generated.ts:110:18)
at Array.map (<anonymous>)
at x8u (/app/node_modules/box-typescript-sdk-gen/src/schemas/accessToken.generated.ts:107:28)
at jvr.<anonymous> (/app/node_modules/box-typescript-sdk-gen/src/managers/authorization.generated.ts:294:12)
at Generator.next (<anonymous>)
at a (/app/node_modules/box-typescript-sdk-gen/src/networking/fetch.ts:380:1)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Screenshots

Not applicable

Versions Used

Typescript SDK: 1.2.0 Platform: Node Node.js (if applicable): v20.11.0

namack commented 1 month ago

It looks like I am able to get the desired functionality using the base_upload scope. Regardless, it seems like this missing scope (item_upload) is still a bug in the SDK.

mwwoda commented 1 month ago

Looks like item_upload scope is missing from the spec and we heavily rely on it during SDK generation - https://developer.box.com/reference/resources/access-token/#param-restricted_to-scope. I'll let the team know about the issue

mwwoda commented 2 weeks ago

Should be fixed by #281 and will be released with the next version of the SDK.