Authentication with box-node-sdk
Hello all,
I am currently having difficulties with the authentication process. Hopefully, you guys can help!
I am using the `box-node-sdk` and am trying to use authentication with JWT as specified here https://developer.box.com/v2.0/docs/authentication-with-jwt.
I have successfully created an app user using the service client, however, when I try to access the content API as that user I get the following error:
Error: Expired Auth: Auth code or refresh token has expired.
I can not figure out how to get the app users refresh token and I don't have an auth code because I used JWT authentication which skips the first leg of the three-legged OAuth2 protocol.
What follows is the code that led to the error.
First I read in the box configuration that I downloaded from the developer console and use that create a preconfigured instance of the SDK.
// configure service account client const sdk = BoxSDK.getPreconfiguredInstance(boxConfig) const serviceClient = sdk.getAppAuthClient('enterprise')
I then ensure that this service client is properly configured by fetching `me`.
// Ensure that service account is working and fetch service account user serviceClient.users.get('me', null) .then((serviceAccountUser) => { console.log(serviceAccountUser) }) .catch((err) => { console.log(err) })
This returns the app user I had created previously. I then use that user id `USER_ID` to create a user client.
// create user client const userClient = sdk.getAppAuthClient('user', USER_ID)
Next, I attempt to use that user client to access the content API.
// access content API userClient.folders.getItems('0', null) .then((data) => { console.log(data) }) .catch((err) => { console.log(err) })
This returns the following error.
Error: Expired Auth: Auth code or refresh token has expired.
I hope that that is a clear explanation of the issue I am having. If you know what is the best way for me to access the refresh token, that would be much appreciated.
Thanks!
Cam
-
Hi Cam!
I may be totally misreading what you are trying to accomplish, but in our application we are using the Service Account to deal with all our Box content. I think if you need the Enterprise token, the following may not apply to you. I'm using the .NET SDK.
All I do to get a BoxClient I can use to upload files and get shared links is the following:
// Initialize the SDK with the Box token data and create a client that uses the Service Account. var session = new BoxJWTAuth(BoxConfig.CreateFromJsonString(accessTokenData)); return session.AdminClient(session.AdminToken());
The accessTokenData is the text inside the JSON JWT token file you should have downloaded from your Box Developer account when you created your app. I save the returned BoxClient instance and use it elsewhere in my class to use Box services.
I didn't see the info about creating a "pre-configured" SDK instance, so I'm not doing it, but the above works for me.
Hope this helps!
randy
サインインしてコメントを残してください。
コメント
2件のコメント