Not able to upload file using dot net sdk
Hi team,
I'm very new to Box api/sdk; my client has an enterprize account with box and our new application needs to upload files to box via dot net sdk.
I was able to upload file using the "developer key" which I got from the box UI; but I'm not sure how to get this key programatically so that I dont have to worry about the key expiry.
This is what I did:
*****************************************************************************************
var privateKey = File.ReadAllText(my_key_path);
var boxConfig = new BoxConfig(clientId, clientSecret, entId, privateKey, jwtKeyPassword, kid);
var boxJWT = new BoxJWTAuth(boxConfig);
var adminToken = boxJWT.AdminToken();
var client = boxJWT.AdminClient(adminToken);
//var session = new OAuthSession(adminToken, "", 3600, "bearer");
//var client = new BoxClient(boxConfig, session);
BoxFile f;
using (FileStream fs = File.Open(my_file_path, FileMode.Open, FileAccess.Read))
{
BoxFileRequest request = new BoxFileRequest()
{
Name = "New File",
Parent = new BoxRequestEntity() { Id = "0" }
};
f = await client.FilesManager.UploadAsync(request, fs);
}
return f.Id;
*****************************************************************************************
When I execute this, Im getting error saying insufficient privilege for the provided access token.
But if I use the commented out lines instead, with the developer key, thsi works fine:
var session = new OAuthSession(dev_key_from_box_ui, "", 3600, "bearer");
var client = new BoxClient(boxConfig, session);
Could you guys please help me out?
Regards,
Kiran
-
Hi Kiran,
Thanks for posting and for the details you've provided. It looks like you're working with two different authentication methods, one for use with Box Platform (App Auth) and the other for use with the Box Content API (OAuth). Configuration instructions for the two authentication methods are included in the .NET SDK read-me documentation.
OAuth is used with standard Box accounts, i.e. those created and managed on app.box.com. Since your client has an enterprise account with Box, enterprise users who want to use the app you're building will need to authenticate with OAuth (the commented-out lines in your code). App Auth with Box Platform is intended to be used with App Users, users that can only be accessed by the Box API through your application.
Please let me know if this helps! -
I am hoping to get clarity on this.
I also have a client with an Enterprise box account. We are building a server application to upload files to this account and we are unclear how to authenticate with the API via the SDK. This application will be unmanned.
We believe we should be using the following (from the SDK documentation on GitHub):
Using with Box Platform Developer or Box Platform Enterprise Configure
var boxConfig = new BoxConfig(, , , , , ); var boxJWT = new BoxJWTAuth(boxConfig);
Can you confirm The above is the way we should be attempting to authenticate and where to find the configuration values in the admin console (specifically the enterprise id and JWT information)?
Thanks.
-
I get this is a year to late, but you can get this information from the developer console. I however had a really tough time understanding what the passphrase was and why the RSA key generated by Box.com wasn't good enough. Luckily, box.com supplies the JSON of all you'd want. You would just do this:
using (FileStream fs = new FileStream(@"HeyThisIsMy.json", FileMode.Open)) { boxConfig = BoxConfig.CreateFromJsonFile(fs); }
Obviously replace the json name, and you're good to go.
Please sign in to leave a comment.
Comments
3 comments