How to create a Service Account
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
-
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()); }
Please sign in to leave a comment.
Comments
3 comments