Last active
September 18, 2017 21:53
-
-
Save allenmichael/e71bc5e2aff1abfe15848be8745a2222 to your computer and use it in GitHub Desktop.
Authenticate Box Service Account and list the Service Account's info.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 'use strict'; | |
| // Require the Box SDK and the fs module | |
| const box = require('box-node-sdk'); | |
| const fs = require('fs'); | |
| // Read and parse the automatically created Box configuration file. | |
| let configFile = fs.readFileSync('config.json'); | |
| configFile = JSON.parse(configFile); | |
| // Initialize the SDK with the Box configuration file and create a client that uses the Service Account. | |
| let session = box.getPreconfiguredInstance(configFile); | |
| let serviceAccountClient = session.getAppAuthClient('enterprise'); | |
| // Use the users.get method to retrieve current user's information by passing 'me' as the ID. | |
| // Since this client uses the Service Account, this will return the Service Account's information. | |
| serviceAccountClient.users.get('me', null) | |
| .then((serviceAccountUser) => { | |
| // Log the Service Account's login value which should contain "AutomationUser". | |
| // For example, [email protected] | |
| console.log(serviceAccountUser.login) | |
| }) | |
| .catch((err) => { | |
| // Log any errors for debugging | |
| console.log(err); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment