dblock / strava-ruby-client

A complete Ruby client for the Strava API v3.
https://code.dblock.org/2018/11/27/writing-a-new-strava-api-ruby-client.html
MIT License
97 stars 22 forks source link

Question: How to get a new access token using a refresh token via backend app? #35

Closed interpegasus closed 4 years ago

interpegasus commented 4 years ago

Hi, According to the Strava dashboard the access token expires. But the refresh token does not.

I would like to know if it is possible to get the most recent non expired access-token, using only the refresh-token, in a backend app, without user interaction?

Currently my backend uses:

Strava::Api::Client.new(
      access_token: ACCESS_TOKEN
    )

But the token expires often.

Screen Shot 2020-07-21 at 11 47 44 AM

Thanks

dblock commented 4 years ago

Yes. That's actually in the README:


If the access token is expired, refresh it before making any requests. You will get back all new tokens.

response = client.oauth_token(
  refresh_token: '...',
  grant_type: 'refresh_token'
)

response.access_token # => String, new access token
response.refresh_token # => String, new refresh token
response.expires_at # => Time, new timestamp when the access token expires

Here's a production example

interpegasus commented 4 years ago

Perfect! Thank you