Sha256: 82de7061b27ab5dda6c3a4e99e5024c404e440a1adf1c786c1e33b9bc47459f3

Contents?: true

Size: 1.34 KB

Versions: 1

Compression:

Stored size: 1.34 KB

Contents

require 'omniauth-oauth2'
require 'multi_json'

module OmniAuth
  module Strategies
    class Cmply < OmniAuth::Strategies::OAuth2
      option :name, 'cmply'
      option :client_options, {:authorize_path => '/oauth/authorize',:site => 'https://api.cmp.ly'}

      #uid { access_token.params[:user_id] }
      uid { raw_info['_id'] }

      info do
        {
          :nickname => raw_info['user_name'],
          :name => raw_info['full_name'],
          :first_name => raw_info['first_name'],
          :last_name => raw_info['last_name'],
          :image => raw_info['profile_image_url'],
          :description => raw_info['bio'],
          :email => raw_info['email']
        }
      end

      extra do
        { :raw_info => raw_info }
      end

      def raw_info
        @raw_info ||= MultiJson.load(access_token.get('/v2/users/verify-credentials.json').body)
      rescue ::Errno::ETIMEDOUT
        raise ::Timeout::Error
      end

      alias :old_request_phase :request_phase

      def request_phase
        screen_name = session['omniauth.params'] ? session['omniauth.params']['screen_name'] : nil
        if screen_name && !screen_name.empty?
          options[:authorize_params] ||= {}
          options[:authorize_params].merge!(:force_login => 'true', :screen_name => screen_name)
        end
        old_request_phase
      end

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
omniauth-cmply-0.0.9 lib/omniauth/strategies/cmply.rb