Sha256: a8979c1cfddb2095b919bb7db5622fc74e95c1315d2ac651e4a7b3b09c131328

Contents?: true

Size: 1.04 KB

Versions: 3

Compression:

Stored size: 1.04 KB

Contents

#!/usr/bin/env ruby
# frozen_string_literal: true

require 'dotenv/load'
require 'strava-ruby-client'
require 'webrick'

server = WEBrick::HTTPServer.new(Port: 4242)

trap 'INT' do
  server.shutdown
end

client = Strava::OAuth::Client.new(
  client_id: ENV.fetch('STRAVA_CLIENT_ID', nil),
  client_secret: ENV.fetch('STRAVA_CLIENT_SECRET', nil)
)

server.mount_proc '/' do |req, res|
  code = req.query['code']
  response = client.oauth_token(code: code)

  res.body = %(
<html>
  <body>
    <ul>
      <li>token_type: #{response.token_type}</li>
      <li>refresh_token: #{response.refresh_token}</li>
      <li>access_token: #{response.access_token}</li>
      <li>expires_at: #{response.expires_at}</li>
    </ul>
  <body>
</html>
  )

  server.shutdown
end

redirect_url = client.authorize_url(
  redirect_uri: 'http://localhost:4242/',
  response_type: 'code',
  scope: 'read_all,activity:read,activity:read_all,profile:read_all,profile:write,activity:write'
)

server.logger.info "opening browser at #{redirect_url}\n"
system 'open', redirect_url

server.start

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
strava-ruby-client-1.1.0 bin/strava-oauth-token
strava-ruby-client-1.0.1 bin/strava-oauth-token
strava-ruby-client-1.0.0 bin/strava-oauth-token