Skip to content

OAuth2 - getTokensAuthorizationCodeGrant throw BoxSdkError #451

@KevinForys

Description

@KevinForys
  • I have checked that the [SDK documentation][sdk-docs] doesn't solve my issue.
  • I have checked that the [API documentation][api-docs] doesn't solve my issue.
  • I have searched the [Box Developer Forums][dev-forums] and my issue isn't already reported (or if it has been reported, I have attached a link to it, for reference).
  • I have searched [Issues in this repo][github-repo] and my issue isn't already reported.

Description of the Issue

I have started to migrate a BoxNodeSDK app to the BoxTSSDK.

My app is an Box Web Integration with an OAuth2 Authentication.

When I use the function await oauth.getTokensAuthorizationCodeGrant('code');, the Box TS SDK throw :

node_modules/box-typescript-sdk-gen/lib/schemas/fileOrFolderScope.generated.js:55
    throw new errors_js_1.BoxSdkError({
          ^
BoxSdkError: Can't deserialize FileOrFolderScopeScopeField
    at deserializeFileOrFolderScopeScopeField (node_modules/box-typescript-sdk-gen/lib/schemas/fileOrFolderScope.generated.js:55:11)

Steps to Reproduce

  1. I open my Box Integration App from a Box folder
  2. The app start correctly the OAuth2 Authentication process
  3. The BoxNodeSDK crashed when I use oauth.getTokensAuthorizationCodeGrant('correct_code');

Error Message, Including Stack Trace

BoxSdkError: Can't deserialize FileOrFolderScopeScopeField
    at deserializeFileOrFolderScopeScopeField (node_modules/box-typescript-sdk-gen/lib/schemas/fileOrFolderScope.generated.js:55:11)
    at deserializeFileOrFolderScope (node_modules/box-typescript-sdk-gen/lib/schemas/fileOrFolderScope.generated.js:77:11)
    at node_modules/box-typescript-sdk-gen/lib/schemas/accessToken.generated.js:84:90
    at Array.map (<anonymous>)
    at deserializeAccessToken node_modules/box-typescript-sdk-gen/lib/schemas/accessToken.generated.js:83:33)
    at AuthorizationManager.<anonymous> (node_modules/box-typescript-sdk-gen/lib/managers/authorization.generated.js:210:106)
    at Generator.next (<anonymous>)
    at fulfilled (node_modules/box-typescript-sdk-gen/lib/managers/authorization.generated.js:5:58)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Patch

I have investigate on my side and it's look like that the scope 'item_read' is missing inside the deserializeFileOrFolderScopeScopeField() loop.

box-typescript-sdk-gen/lib/schemas/fileOrFolderScope.generated.js:55 :

export function deserializeFileOrFolderScopeScopeField(
  val: SerializedData,
): FileOrFolderScopeScopeField {
  
  if (val == 'item_read') { // Missing this scope.
    return val;
  }
  if (val == 'annotation_edit') {
    return val;
  }
  if (val == 'annotation_view_all') {
    return val;
  }
  if (val == 'annotation_view_self') {
    return val;
  }
  if (val == 'base_explorer') {
    return val;
  }
  if (val == 'base_picker') {
    return val;
  }
  if (val == 'base_preview') {
    return val;
  }
  if (val == 'base_upload') {
    return val;
  }
  if (val == 'item_delete') {
    return val;
  }
  if (val == 'item_download') {
    return val;
  }
  if (val == 'item_preview') {
    return val;
  }
  if (val == 'item_rename') {
    return val;
  }
  if (val == 'item_share') {
    return val;
  }
  if (val == 'item_upload') {
    return val;
  }
  throw new BoxSdkError({
    message: "Can't deserialize FileOrFolderScopeScopeField",
  });
}

Versions Used

Typescript SDK: v1.9.0
Platform: Node.js
Node.js : v20.18.1

Metadata

Metadata

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions