Refresh token for ruby
For work with the service I use gem 'boxr'. For uploading files, authentication is required, which I perform through JWT, as described in the documentation
user = Boxr::get_user_token(user_id, private_key: ENV['JWT_PRIVATE_KEY'], private_key_password: ENV['JWT_PRIVATE_KEY_PASSWORD'], public_key_id: ENV['JWT_PUBLIC_KEY_ID'], client_id: ENV['BOX_CLIENT_ID'], client_secret: ENV['BOX_CLIENT_SECRET'])
Then i get client for further work:
client = Boxr::Client.new(user.access_token)
The time of the token expires after an hour, and this client will be unavailable, I can not work with it and i will need to repeat all the code from above. Again and again. How I can automatically update the token, for further work?
In the documentation for the gem, there is something to update the token, but I did not figure it out
token_refresh_callback = lambda {|access, refresh, identifier| some_method_that_saves_them(access, refresh)} client = Boxr::Client.new('zX3UjFwNerOy5PSWc2WI8aJgMHtAjs8T', refresh_token: 'dvfzfCQoIcRi7r4Yeuar7mZnaghGWexXlX89sBaRy1hS9e5wFroVVOEM6bs0DwPQ', client_id: 'kplh54vfeagt6jmi4kddg4xdswwvrw8y', client_secret: 'sOsm9ZZ8L8svwrn9FsdulLQVwDizKueU', &token_refresh_callback)
Grateful for any help!
Please sign in to leave a comment.
Comments
0 comments