Skip to main content
Question

Authentication on behalf of User

  • May 21, 2025
  • 4 replies
  • 17 views

Forum|alt.badge.img

Facing issues while authnicating on behalf of user. How would we get service account user token to do behalf of user authenication using JWT? 

4 replies

Forum|alt.badge.img

Here's an example

 

BoxDeveloperEditionAPIConnection api = BoxDeveloperEditionAPIConnection.getAppEnterpriseConnection(
                ENTERPRISE_ID, CLIENT_ID, CLIENT_SECRET, encryptionPref, accessTokenCache);

        Iterable managedUsers = BoxUser.getAllEnterpriseUsers(api, "***email address removed for privacy***");
        for (BoxUser.Info managedUser : managedUsers) {
            System.out.println(managedUser.getName() + " " + managedUser.getStatus());
            if (managedUser.getStatus().equals(BoxUser.Status.ACTIVE)) {

                // Used to get AppUser or ManagedUser
                BoxDeveloperEditionAPIConnection userApi = BoxDeveloperEditionAPIConnection.getAppUserConnection(managedUser.getID(), CLIENT_ID, CLIENT_SECRET, encryptionPref, accessTokenCache);

                BoxItem.Info boxItem = BoxFolder.getSharedItem(api, "https://hpdnyc.app.box.com/s/zjq4iwixgn44gvqt43ou4jmiqfehemkc");
                BoxFolder publicFolder = (BoxFolder)boxItem.getResource();
                Iterable items = publicFolder.getChildren();
                for (BoxItem.Info item : items) {
                    System.out.println("\t" + item.getName());
                }
            }
        }

Forum|alt.badge.img

 I was able to get the enterpise acess token, but not the user tokens. I tried to user tokens by OATH with JWT. 

I am getting "Cannot obtain user token based on the enterpise configuration for your app?"  error when trying to authenicate on behalf of user.


Forum|alt.badge.img

I think you may need to set the scope in your app.  Here's what I have

 

BOX_1svdeqqf0z0lkitwrncd6ri5bb12jhmd.png


Forum|alt.badge.img

Thank you very much  ! for helping me out