Skip to main content
Question

Box.com SDK - Getting user and admin tokens

  • May 22, 2025
  • 9 replies
  • 61 views

Forum|alt.badge.img

Environment: C# / Visual Studio 2017, Box.V2 SDK via NuGet, latest version as of today. Company enterprise account of Box.com, I'm the admin.

I've created an "Enterprise Integration" app in Box's developer console, and given it all the privileges available. I set it for "OAuth 2.0 with JWT (Server Authentication)", generated a public/private keypair, and downloaded a JSON of all of it (in the app's executable directory as "BoxAuth.json" (Yes, in my final version, I'll encrypt.)

Trying to follow a quick-start guide here:

https://developer.box.com/docs/authenticate-with-jwt#section-step-2-generate-configuration

So I have this code:

var config = BoxConfig.CreateFromJsonFile(File.OpenRead("BoxAuth.json"));

        var session = new BoxJWTAuth(config);


        //client impersonating "me."
        var user = "***email address removed for privacy***";
        var userToken = session.UserToken(user);
        var userClient = session.UserClient(userToken, user);


        // client with permissions to manage application users
        var adminToken = session.AdminToken();
        var adminClient = session.AdminClient(adminToken);

When I call session.UserClient(userToken, user), I get an exception: "The API returned an error [BadRequest]"

If I comment that line out, I get an identical exception when I call session.AdminClient(adminToken)

Am I missing something obvious?

Thank you all for any insights.

9 replies

Forum|alt.badge.img

hey~~~

Do you solve this problem?I also have this problem。


Forum|alt.badge.img

Have same issues here. while generating admin token


Forum|alt.badge.img

Anybody has any update on this error? I just tried the code and I am getting the same error.


Forum|alt.badge.img

Hi guys,

I ran into the same issues, I haven't been able to solve it, but please check out the following link where my question has been answered.

https://community.box.com/t5/Platform-and-Development-Forum/JWT-Oauth-2-0-using-powershell/m-p/47024

 

I have used the CLI, this works like a charm.
And a plus side, the CLI setup is really well documented and easy to set up.


Forum|alt.badge.img

I found the issue, mainly by trial and error.

You have to go back into your account's admin and authorize the app after you've made it.

Go to 

https://[yourdomain].app.box.com/master/settings/openbox  

And look under "Custom Applications."  Add this app with the clientID value in the JWT JSON.  BTW - if you make any changes to the app's permissions, you have to come back here, drop the app, and add it again.


Forum|alt.badge.img

I found the issue, mainly by trial and error.

You have to go back into your account's admin and authorize the app after you've made it.

Go to 

[yourdomain].app.box.com/master/settings/openbox  

And look under "Custom Applications."  Add this app with the clientID value in the JWT JSON.  BTW - if you make any changes to the app's permissions, you have to come back here, drop the app, and add it again.


Forum|alt.badge.img

Thank you!  This was my issue.


Forum|alt.badge.img

This looks like my exact problem, but I cant find in my account how to give my custom app permissions.
When I go to

https://[yourdomain].app.box.com/master/settings/openbox  

On that page have 2 buttons. 1 to browse apps or watch demo.

Click Browse Apps and see ways to search for published apps, but nothing for Custom Applications.

Could this be an issue with how the organization is setup?

 

 


Forum|alt.badge.img

Thank you very much, we were having this problem for a while, your solution worked perfectly!