Skip to main content
Question

How to create a Service Account

  • May 21, 2025
  • 3 replies
  • 35 views

Forum|alt.badge.img

Hey all,

 

I'd like to create a Service Account so I'd be able to authenticate with it with my app.

I found this guide, but it doesn't say how to create such an account.

 

Can anyone assist?

 

Thanks

3 replies

Forum|alt.badge.img

Service Account == App.

 

See this thread: https://community.box.com/t5/Developer-Forum/Service-Accounts-how-to-create-one-and-how-to-use-it-through-NET/m-p/27175#U27175

 

Here's java code that instantiates a service account:

private static final String CLIENT_ID = "";
    private static final String CLIENT_SECRET = "";
    private static final String ENTERPRISE_ID = "";
    private static final String PUBLIC_KEY_ID = "";
    private static final String PRIVATE_KEY_FILE = "";
    private static final String PRIVATE_KEY_PASSWORD = "";
    private static final int MAX_CACHE_ENTRIES = 100;
    private static final String APP_USER_NAME = "";


    public static void main(String[] args) throws IOException {
        // Turn off logging to prevent polluting the output.
        Logger.getLogger("com.box.sdk").setLevel(Level.ALL);

        String privateKey = new String(Files.readAllBytes(Paths.get(PRIVATE_KEY_FILE)));

        JWTEncryptionPreferences encryptionPref = new JWTEncryptionPreferences();
        encryptionPref.setPublicKeyID(PUBLIC_KEY_ID);
        encryptionPref.setPrivateKey(privateKey);
        encryptionPref.setPrivateKeyPassword(PRIVATE_KEY_PASSWORD);
        encryptionPref.setEncryptionAlgorithm(EncryptionAlgorithm.RSA_SHA_256);

        //It is a best practice to use an access token cache to prevent unneeded requests to Box for access tokens.
        //For production applications it is recommended to use a distributed cache like Memcached or Redis, and to
        //implement IAccessTokenCache to store and retrieve access tokens appropriately for your environment.
        IAccessTokenCache accessTokenCache = new InMemoryLRUAccessTokenCache(MAX_CACHE_ENTRIES);

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

        CreateUserParams params = new CreateUserParams();
        params.setSpaceAmount(***number removed for privacy***4); //1 GB
        BoxUser.Info user = BoxUser.createAppUser(api, APP_USER_NAME, params);

        System.out.format("User created with name %s and id %s\n\n", APP_USER_NAME, user.getID());
    }

Forum|alt.badge.img

Thanks for the clarification, it helps  a lot;

Have few more questions regarding service account:

  1. is it mandatory to have emailid with a service account?
  2. Who's responsibility to create the service account? it's developer or the admin of the app? \

 

Regards,

Raj


Forum|alt.badge.img

hey guys i dont know if you are still alive or not but i need help immediately. How did u use this codes and how can i use it also, is there any relationship with creating an box service account or what