Sha256: ba26da9c710c253ec6b4acff240e9d0d9b788fab81158de8118cd340ff9ce7db

Contents?: true

Size: 1.64 KB

Versions: 1

Compression:

Stored size: 1.64 KB

Contents

require 'omniauth-oauth2'
require 'multi_json'

module OmniAuth
  module Strategies
    class Strava < OmniAuth::Strategies::OAuth2
      option :name, 'strava'
      option :client_options, {
        :site => 'https://strava.com/',
        :authorize_url => 'https://www.strava.com/oauth/authorize',
        :token_url => 'https://www.strava.com/oauth/token'
      }
      option :scope, 'read'

      def token_params
        super.tap do |params|
          params[:client_id] = options[:client_id]
          params[:client_secret] = options[:client_secret]
        end
      end

      def authorize_params
        super.tap do |params|
          params[:approval_prompt] = 'auto'
        end
      end

      def request_phase
        super
      end

      def callback_phase
        super
      end

      uid { "#{athlete['id']}" }

      extra do
        {
          recent_ride_totals: athlete['recent_ride_totals'],
          ytd_ride_totals: athlete['ytd_ride_totals'],
          all_ride_totals: athlete['all_ride_totals'],
          raw_info: athlete
        }
      end

      info do
        {
          name: "#{athlete['firstname']} #{athlete['lastname']}",
          first_name: athlete['firstname'],
          last_name: athlete['lastname'],
          email: athlete['email'],
          location: "#{athlete['city']} #{athlete['state']}",
          image: athlete['profile']
        }
      end

      def athlete
        access_token.options[:mode] = :query
        access_token.options[:param_name] = :access_token
        @athlete ||= MultiJson.load(access_token.get('/api/v3/athlete', { access_token: access_token.token }).body)
      end

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
omniauth-strava-1.0.0 lib/omniauth/strategies/strava.rb