Skip to main content
Box Employee
May 21, 2025 12:13 PM UTC
Question

JWT token - does not access BOX account

I am trying to use BOX content api's to find and download content from box from an external app.

The idea using my custom app to search and retrieve content from box. For example take HTML file and load to local or cloud platform / system. So the BOX part from what I can tell should work like this

  1. create a box app using OAuth2.0 with JWT
  2. create and sign a JWT
  3. Use this JWT as assertion and request a token (https://api.box.com/oauth2/token)
  4. Use that token to perform requests (such as /2.0/search). Specify the token in authorization header for calls.

Using this method and then performing requests ... it returns expected data when using developer token.... but not when generating the token. For example I search for a file that I know exists....

JSON result using app generated token:

{
   "total_count": 0,
   "entries": [],
   "limit": 30,
   "offset": 0
}

Using developer or BOX UI auth

{
   "total_count": 73,
   "entries":    [
            {
         "type": "file",
         "id": "]
         ...tons of data here :)...
         }
   ],
   "limit": 30,
   "offset": 0
}

    14 replies

    Box Employee
    May 21, 2025 12:13 PM UTC

    Is your app "As-User" enabled?

    Translate
    Box Employee
    May 21, 2025 12:13 PM UTC

    Hi kendomen

    Thanks for reply

    Good question.

    To eliminate app permission being the issue I have checked that and every permission. I tried creating app users and using their tokens also without success.

     

    Below settings, all checked

    Content
    	Read and write all files and folders stored in Box
    
    Enterprise
    	Manage enterprise
    	Manage users
    	Manage app users
    	Manage groups
    	Manage enterprise properties
    	Manage retention policies
    	Manage webhooks v2
    
    Select the set of scopes you will request users authorize when using your app
    	Advanced Features: 	Perform actions on behalf of users
    	Generate access tokens for users 

     

    Translate
    Box Employee
    May 21, 2025 12:13 PM UTC

    Have you authorized the jwt app ?

     

    BOX_2a3m7qwdm06lkcitfxapms1whu5kqwdh.png

    Translate
    Box Employee
    May 21, 2025 12:13 PM UTC

    Also a good thought. I checked and it was authorized. I reauthorized and tried api calls and same issue

     

    https://www.screencast.com/t/kR7g394rRQ

    Translate
    Box Employee
    May 21, 2025 12:13 PM UTC

    BTW the working developer token is generated in the app settings ... so that leads me to believe that it IS using that app... and working. However when I use the JWT it fails.

    Translate
    Box Employee
    May 21, 2025 12:13 PM UTC

    Good afternoon kp,

     

    I would tell that given that you do not receive an error but an empty array of results mean that everything is correctly set up.

     

    So... where is your problem? Basically, I think that it is related to the user you are using or the authentication method. There are the Enterprise and the User authentication modes. I understand that you are using the second one with a technical user, is that right? The technical user is assigned to any of folder where you want to find content? If the user is not added as a previewer at least no result will be found.

     

    Thanks

    Translate
    Box Employee
    May 21, 2025 12:13 PM UTC

    I think that would perfectly explain the behavior.

    I am using OAuth2.0 with JWT - so I tried the enterprise user ... box_sub_type=enterprise and tried box_sub_type=user.

    How would I assign the app user or app any permissions to any directory?

    Translate
    Box Employee
    May 21, 2025 12:13 PM UTC

    Hello kp,

     

    basically, if you have created an APPUser will have an ID that is an autogenerated mail like this one: 

    AppUser_000000_j0f0Z0RAS4 (at) boxdevedition (dot) com

     

    That mail can be used as any other user, so you go to any folder with your account, click add collaborator and paste that mail account with the desired privileges. That user has to be able to do any action is allowed to then.

     

    Hope this helps.

    Translate
    Box Employee
    May 21, 2025 12:13 PM UTC

    Hallelujah that works - thanks!

     

    I really don't understand though how this is meant to work. The api does not let you assign permissions to the objects in the BOX account itself. So you would have to either make the user load stuff through your api itself to ever access it... or workaround the process itself by creating the app user and adding that user to the folders you want in scope.

    Do you know if there is a way to just add the app itself vs app user - as collaborator? Or add a group (as collaborator) then add the user to the group?

     

     

    Translate
    Box Employee
    May 21, 2025 12:13 PM UTC

    Hello Kp!

     

    I am glad that we hit the right key 😉

     

    I understand that there are two ways to face this situation as you said:

     

    - The app user is the one with the control. So, with this user you create folders and invite collaborators with different roles, being the APP User the Owner of those folders.

    - The app user has to be invited because it is not the owner. As you said, you can add the appuser on a group and then as any other user this will have access only to what has to have access. 

     

    Probably, the real situation can end on a hybrid situation. 

     

    I think that what really matters on this aspect is this piece of configuration:

    BOX_wr5cfjfbyg17go6leslcxol6mcp4w7uw.png

     

    If the application has enterprise access then can access everything in theory.

     

    If you have chosen Application then it behaves as a regular user: can create stuff on its own account but has to be invited to do things on folders of others.

     

    Regards

    Translate