Level up your Box knowledge with brand new learning paths on Box University. Visit training.box.com to get started

Comments

3 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
  • Faruk selim Duman

    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

     

    0
    Comment actions Permalink

Please sign in to leave a comment.