Sha256: fdeb3ca7f58b587b2c90d9018b6244f33aa51d399a2c647ab695ebdcd18a9889

Contents?: true

Size: 1.04 KB

Versions: 2

Compression:

Stored size: 1.04 KB

Contents

require 'omniauth/strategies/oauth2'
require 'json'

module OmniAuth
  module Strategies
    class Avvo < OmniAuth::Strategies::OAuth2
      option :name, "avvo"
      option :client_options, {
        :site => "http://api.avvo.com", 
        :authorize_url => '/api/2/oauth2/authorize', 
        :token_url => '/api/2/oauth2/authorize',
        :ssl => {
          :verify => false
        }
      }
      option :authorize_options, [:scope, :state]

      uid do
        raw_info['id']
      end

      info do 
        {
          :name => raw_info['friendly_name'],
          :email => raw_info['email_address'],
          :permissions => raw_info['permissions'],
        }
      end

      extra do
        {
          :raw_info => raw_info
        }
      end

      def raw_info
        @raw_info ||= begin
          access_token.options[:header_format] = "OAuth %s"
          json = access_token.get('/api/2/users/me').body
          user_data = JSON.parse(json) || {} rescue {}
          user_data["user"] || {}
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
omniauth-avvo-0.0.2 lib/omniauth/strategies/avvo.rb
omniauth-avvo-0.0.1 lib/omniauth/strategies/avvo.rb