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

Comments

2 comments

  • kendomen

    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());
        }
    0
    Comment actions Permalink
  • rajesh4851

    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

    0
    Comment actions Permalink

Please sign in to leave a comment.