I've read the whole Box.com developers api guide and spent hours on the web researching this particular question but I can't seem to find a definitive answer and I don't want to start creating a solution if I'm going down the wrong path. We have a production environment where as once we are finished working with files our production software system zips them up and saves them into a local server directory for archival purposes. This local path cannot be changed. My question is how can I programmatically upload these files to our Box.com account so we can archive these on the cloud? Everything I've read regarding this involves using OAuth2 to gain access to our account which I understand but it also requires the user to login. Since this is an internal process that is NOT exposed to outside users I want to be able to automate this otherwise it would not be feasable for us. I have no issues creating the programs to trigger everytime a new files gets saved all I need is to streamline the Box.com access.
相关问题
- Obtaining Refresh Token from lepture/Authlib throu
- YouTube API refresh token revoked with 400 code “i
- Azure AD OAuth client credentials grant flow with
- Authenticating to Google Cloud Endpoints as iOS ap
- Android Google Drive Resumable Upload fails very o
相关文章
- Why is redirect_uri required on Access Token reque
- Archive option greyed out in xcode 4.5.2
- Safari xhr drag'n'drop file upload seems t
- Django REST Framework - OAuth2 Consumer API from e
- Google OAuth 2.0 User id datatype for MYSQL
- Google OAuth 2: response_type error on token reque
- Google OAuth 2 redirect_uri_mismatch - OmniAuth Ra
- React Native Uploading File in parts using XMLHttp
Have you thought about creating a box 'integration' user for this particular purpose. It seems like uploads have to be made with a Box account. It sounds like you are trying to do an anonymous upload. I think box, like most services, including stackoverflow don't want anonymous uploads.
You could create a system user. Go do the Oauth2 dance and store just the refresh token somewhere safe. Then as the first step of your script waking up go use the refresh token and store the new refresh token. Then upload all your files.
If I understand correctly you want the entire process to be automated so it would not require a user login (i.e run a script and the file is uploaded). Well, it is possible. I am a rookie developer so excuse me if I'm not using the correct terms.
Anyway, this can be accomplished by using cURL. First you need to define some variables, your user credentials (username and password), your client id and client secret given by Box (found in your app), your redirect URI and state (used for extra safety if I understand correctly).
The
oAuth2.0
is a 4 step authentication process and you're going to need to go through each step individually.The first step would be setting a curl instance:
This will return an html text with a request token, you will need it for the next step so I would save the entire output to a variable and grep the tag with the request token (the tag has a
"name" = "request_token"
and a"value"
which is the actual token).Next step you will need to send another curl request to the same url, this time the post fields should include the request token, user name and password as follows:
At this point you should also set a cookie file:
This will return another html text output, use the same method to grep the token which has the name "ic".
For the next step you're going to need to send a post request to the same url. It should include the postfields:
Be sure to set the curl request to use the cookie file you set earlier like this:
and include the header in the request:
At step (if done by browser) you will be redirected to a URL which looks as described above:
Grab the value of
"code"
.Final step!
send a new cur request to https//app.box.com/api/oauth2/token This should include fields:
This will return a string containing "access token", "Expiration" and "Refresh token". These are the tokens needed for the upload. read about the use of them here: https://box-content.readme.io/reference#upload-a-file
Hope this is somewhat helpful. P.S, I separated the https on purpuse (Stackoverflow wont let me post an answer with more than 1 url :D) this is for PHP cURL. It is also possible to do the same using Bash cURL.
I just went through the exact same set of questions and found out that currently you CANNOT bypass the OAuth process. However, their refresh token is now valid for 60 days which should make any custom setup a bit more sturdy. I still think, though, that having to use OAuth for an Enterprise setup is a very brittle implementation -- for the exact reason you stated: it's not feasible for some middleware application to have to rely on an OAuth authentication process.
My Solution:
Here's what I came up with. The following are the same steps as outlined in various box API docs and videos:
In my application I save both auth token and refresh token in a format where I can easily go and replace them if something goes awry down the road. Then, I check my authentication each time I call into the API. If I get an authorization exception back I refresh my token programmatically, which you can do! Using the BoxApi.V2 .NET SDK this happens like so:
Hope this helped!