Hi Marek,
Thanks for reaching out!
We actually don't officially support completing the OAuth process without interacting with a browser. However, once you obtain your initial access and refresh tokens you don't need to complete the full OAuth process as long as your tokens remain active.
The full OAuth process is described in detail here - https://box-content.readme.io/docs/oauth-20 - but can be boiled down to the following few steps:
- Make your preliminary request to get authorization - this is where the browser interaction comes into play. Something similar to this will do:
https://account.box.com/api/oauth2/authorize?response_type=code&client_id={your_api_key}&state=authenticated
- You will be presented with a login screen, sign in to grant access to the application using the account you wish to generate the tokens [token permissions rely on the permissions of the account that generated them] - this will return an Authorization Code in the "code" parameter.
- Use the Authorization Code that's returned to construct a call like the following:
curl https://app.box.com/api/oauth2/token \
-d 'grant_type=authorization_code&code={your_code_from_step_2}&client_id={your_API_key}&client_secret={your_client_secret}' \
-X POST
- If successful, this will return your first set of Access and Refresh Tokens.
Access Tokens have a 60 minute lifespan, and can be used as many times as you need for the duration of their life. Once that time passes [or pro-actively], use the Refresh Token to generate a new Access and Refresh Token. Refresh Tokens have a 60 day lifespan and can be used once within that time. Once a Refresh Token is used to generate the new pair of tokens, the initial pair of tokens become invalid.
As long as your tokens are refreshed at least once every 60 days, you will not need to complete the OAuth process again to keep your access.
Hopefully that helps!
-Tony
