Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OAuth2 - getTokensAuthorizationCodeGrant throw BoxSdkError #451

Open
4 tasks done
KevinForys opened this issue Dec 18, 2024 · 2 comments
Open
4 tasks done

OAuth2 - getTokensAuthorizationCodeGrant throw BoxSdkError #451

KevinForys opened this issue Dec 18, 2024 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@KevinForys
Copy link

  • 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

@KevinForys KevinForys added the bug Something isn't working label Dec 18, 2024
@KevinForys KevinForys changed the title OAuth2 Authentication - getTokensAuthorizationCodeGrant throw BoxSdkError OAuth2 - getTokensAuthorizationCodeGrant throw BoxSdkError Dec 18, 2024
@mwwoda
Copy link
Contributor

mwwoda commented Dec 18, 2024

Hello,
Looks like the scope you are receiving is missing from the spec https://developer.box.com/reference/resources/access-token/#param-restricted_to-scope. This SDK is generated based on spec and currently it's very strict about deserializing enum values from API - if value not present on the list of possible values is present it usually throws exception. We plan change this to allow any custom values during deserialization. I'll also check what we could do from the spec side.

@KevinForys
Copy link
Author

Hello,

Thank you! So the bug is the spec :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

7 participants