Ben here, I'm one of the developers of the ruby-box Gem. Here's what you can do:
- at app.box.com setup your application to use this callback
https://localhost/oauth2callback
- in IRB, generate an authorize url using the same callback:
session = RubyBox::Session.new({
client_id: $boxClientID,
client_secret: $boxClientSecret
})
authorize_url = session.authorize_url('https://localhost/oauth2callback')
- paste this URL in a web-browser.
- once you authenticate with Box, you'll end up on a callback page with a URL that looks like this:
https://localhost/oauth2callback?state=&code=OQpfImZH35Ab9weUy61kthIvqZ2Dyz6
- Copy the value of code.
- Back in irb, run this command:
token = session.get_access_token('OQpfImZH35Ab9weUy61kthIvqZ2Dyz6')
access_token = token.token
refresh_token = token.refresh_token
- Store both the access token and refresh token in a database (or on a napkin, or wherever you see fit).
- From now on you can instantiate a session like this:
session = RubyBox::Session.new({
access_token: $storedAccessTokenValue,
refresh_token: $storedRefreshTokenValue,
client_id: $boxClientID,
client_secret: $boxClientSecret
})
client = RubyBox::Client.new(session)
You only need to get the access_token and refresh_token once for a user.