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

    Just to add... I thought some of these ideas were a strange way to manage permissions... since it ignored the ACL and permissions already in BOX.

    A BOX support person suggested add As-User header https://docs.box.com/reference#as-user-1 .... which turns out is exactly what I need here.

    1. Generate the token using the "box_sub_type=enterprise"
    2. Assuming that your app is being used by BOX user... and you know which user that is - get that user's id
    3. Make calls (where needed) using that users id in the As-User header

    The api will use the already established BOX file permissions.

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

    I have tried this approach and hit a wall, my Application access is set to Enterprise, my code sets the 'box_sub_type' property to 'enterprise' I have also authorized the app on Entreprise settings with all permissions, but everytime I set the header  'As-User:xxxxx' I get the error

    Bearer realm="Service", error="insufficient_scope", error_description="The request requires higher privileges than provided by the access token."

    if I don't set the header then I get and empty list of folders.

    The accepted answer is ok, I haven't tried it as yet mainly because I think your solution should be the correct one.

    Do you have any suggestions on what else can I try?

     

    Kind Regards

     

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

     After updating application's permissions, did you re-authorize the application within the admin console? 

     

     BOX_1p8kay84p7iz381hbad0fhctnvu85bpg.png

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

    Hi loCortes,

     

    Can you please suggest me the way to create an user and link to the app. i couldn't re authorize the app. and i couldn't access the files within box account. please help us. 

    Translate