Trouble generating (or identifying) the correct token for file upload
I've gone around and around on this and I suspect I'm missing something simple. I'm lost in a maze of StackOverflow, Google, and Box Community searches and my head is spinning.
I'm trying to upload a file to box.com by generating an admin token and client and trying to impersonate another user. If I don't impersonate the user, I receive a permission denied error, which I understand to be because admins cannot manipulate content. If I do impersonate the user, I receive the "Cannot obtain user token based on the enterprise configuration for your app" error message
My code for setting up the tokens & users is:
var boxJWT = new BoxJWTAuth(BoxConfig.CreateFromJsonString(jsonConfig)); _userId = "users_email_address"; var adminToken = boxJWT.AdminToken(); var adminClient = boxJWT.AdminClient(_userId, adminToken); var userToken = boxJWT.UserToken(_userId);
It conks out on the creating the userToken.
The upload code that I have works but only as long as I use the "bearer" method with a developer key, but once I try to switch to an API key things don't work.
var client = new RestClient("https://upload.box.com/api/2.0"); var request = new RestRequest("files/content", Method.POST);
const string folderId = "12345"; const string apiKey = "..."; string Headers = string.Format("BoxAuth api_key={0}&auth_token={1}", apiKey, userToken); request.AddHeader("Authorization", Headers); request.AddParameter("parent_id", folderId); byte[] byteArray = System.IO.File.ReadAllBytes(path); request.AddFile("filename", byteArray, "dave-send-fixed.txt"); var responses = client.Execute(request); var content = responses.Content;
How do I bolt these two pieces together and get a working upload?
Is it possible to get the correct token (either admin or user) from this setup and pass along as the BoxAuth parameter? And/or how do I resolve the permissions error above?
Thanks
Please sign in to leave a comment.
Comments
0 comments