Welcome to the new Box Support website. Check out all the details here on what’s changed.

Accessing as User through JWT but not being able to access not-owned folders

Answered
New post

Comments

2 comments

  • Kourtney

     

    Are you using a token associated with your apps service account? If so, you need to ensure that the AutomationUser is added as a collaborator on the necessary folder so it can access it. 

     

    Best, 

    Kourtney 

    0
    Comment actions Permalink
  • DanielSMer

    Hi

     

    Your answer pointed me in the right direction, I was using the token associated with my service account when what I wanted was to use the one associated with the user account.

     

    I needed to add some lines and the end result is the following (probably can be cleaned up and remove some redundancies)

     

    def main():
    
        user_id = "XXXXXXXXXX"
    
        sdk = JWTAuth.from_settings_file('key_config.json')
        client = Client(sdk)
        user = client.user(user_id=user_id).get()
    
        # NEW CODE
        auth_user = sdk.authenticate_user(user)
        sdk = JWTAuth.from_settings_file('key_config.json', access_token=auth_user)
        client = Client(sdk)
        
        items = client.folder(folder_id='0').get_items()
       
        for item in items:
            print('{0} {1} is named "{2}"'.format(item.type.capitalize(), item.id, item.name))

    Thank you!

    0
    Comment actions Permalink

Please sign in to leave a comment.