Config issues when using App Auth Client

Highlighted
New Contributor

Config issues when using App Auth Client

I am using App Auth as I want to upload a file to box from an automated Azure Function.  I am following the instructions on the Box Node.js SDK home page.  The Basic Client code works great, no issues there.  However, I am unable to use the App Auth samples.

 

  1. In the Developer Console I generated a Public/Private Keypair and saved the file to config.json
  2. I use require to dynamically read in the config.json file
  3. Using the Basic Client sample code I determined the current User ID
  4. I pasted the sample code from App Auth into index.js, then pointed the Enterprise ID and User ID variables to the proper places.

When I run it as the instructions suggest I get this error:

 

"clientID" must be set via init() before using the SDK

 

There are two issues in github that suggest that this error is caused when clientID isn't a string.  However, I also noticed in the source code that it's looking for clientID whereas in the config.json I downloaded from the Developer Console has a root node of boxAppSettings.  I changed the initialization to config.boxAppSettings and the clientID test passes but then I get this error:

 

AssertionError [ERR_ASSERTION]: Key ID must be provided in app auth params

 

How can I get App Auth to work?

 

Here is my code - I did not include the full user ID for privacy purposes.

 

 

 

const BoxSDK = require('box-node-sdk');

const config = require('./config.json');
const USER_ID = '130...533';

console.log(typeof config.boxAppSettings.clientID)

var sdk = new BoxSDK(config);

// Get the service account client, used to create and manage app user accounts
var serviceAccountClient = sdk.getAppAuthClient('enterprise', config.enterpriseID);

// Get an app user client
var client = sdk.getAppAuthClient('user', USER_ID);

// Get your own user object from the Box API
// All client methods return a promise that resolves to the results of the API call,
// or rejects when an error occurs
client.users.get(client.CURRENT_USER_ID)
  .then(user => console.log(JSON.stringify(user,null,2)) )
  .catch(err => console.log('Got an error!', err));

 

2 REPLIES 2
Highlighted
New Contributor

Re: Config issues when using App Auth Client

I noticed that the second sample in the App Auth example used different keys than what was in the file I downloaded, so I changed the appAuth.publicKeyID key to appAuth.keyID, and the request passed all tests.

 

However, this is now the error I'm receiving back from Box:

 

Got an error! Error: Unexpected API Response [400 Bad Request] unauthorized_client - This app is not authorized by the enterprise admin

Highlighted
Box Employee

Re: Config issues when using App Auth Client

Hi @GrahamOP,

 

JWT applications will need to be approved by an enterprise admin / co-admin before they can start making requests to the APIs. Following this guide and that should get you over the hurdle.

 

- Jon