Skip to content

Instantly share code, notes, and snippets.

@allenmichael
Last active September 18, 2017 21:43
Show Gist options
  • Save allenmichael/6f0842e4e3def40a8d812e85353cd343 to your computer and use it in GitHub Desktop.
Save allenmichael/6f0842e4e3def40a8d812e85353cd343 to your computer and use it in GitHub Desktop.
Authenticate and log out Service Account information
package com.boxplayground;
import com.box.sdk.*;
import java.io.FileReader;
import java.io.Reader;
public class App {
public static void main( String[] args ) {
// Open a reader to read and dispose of the automatically created Box configuration file.
try(Reader reader = new FileReader("src/config/config.json")) {
// Initialize the SDK with the Box configuration file and create a client that uses the Service Account.
BoxConfig boxConfig = BoxConfig.readFrom(reader);
BoxDeveloperEditionAPIConnection serviceAccountClient = BoxDeveloperEditionAPIConnection.getAppEnterpriseConnection(boxConfig);
// Use the getCurrentUser method to retrieve current user's information.
// Since this client uses the Service Account, this will return the Service Account's information.
BoxUser serviceAccountUser = BoxUser.getCurrentUser(serviceAccountClient);
BoxUser.Info serviceAccountUserInfo = serviceAccountUser.getInfo();
// Log the Service Account's login value which should contain "AutomationUser".
// For example, [email protected]
System.out.println(serviceAccountUserInfo.getLogin());
} catch (java.io.IOException e) {
// Log any errors for debugging
e.printStackTrace();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment