lib/omniauth/strategies/salesforce.rb in omniauth-salesforce-1.0.0 vs lib/omniauth/strategies/salesforce.rb in omniauth-salesforce-1.0.1

- old
+ new

@@ -1,16 +1,33 @@ require 'omniauth-oauth2' module OmniAuth module Strategies class Salesforce < OmniAuth::Strategies::OAuth2 + + MOBILE_USER_AGENTS = 'webos|ipod|iphone|mobile' + option :client_options, { :site => 'https://login.salesforce.com', :authorize_url => '/services/oauth2/authorize', :token_url => '/services/oauth2/token' } + option :authorize_options, [ + :scope, + :display, + :immediate, + :state + ] + def request_phase + req = Rack::Request.new(@env) + options.update(req.params) + ua = req.user_agent.to_s + if !options.has_key?(:display) + mobile_request = ua.downcase =~ Regexp.new(MOBILE_USER_AGENTS) + options[:display] = mobile_request ? 'touch' : 'page' + end super end uid { raw_info['id'] } @@ -21,25 +38,35 @@ 'nickname' => raw_info['nick_name'], 'first_name' => raw_info['first_name'], 'last_name' => raw_info['last_name'], 'location' => '', 'description' => '', - 'image' => raw_info['nick_name'], + 'image' => raw_info['photos']['thumbnail'] + "?oauth_token=#{access_token.token}", 'phone' => '', - 'urls' => raw_info['urls'], - 'organizationid' => raw_info['organization_id'], - 'userid' => raw_info['user_id'], - 'username' => raw_info['username'], - 'organization_id' => raw_info['organization_id'], - 'user_id' => raw_info['user_id'], - 'user_name' => raw_info['username'] + 'urls' => raw_info['urls'] } end def raw_info access_token.options[:mode] = :query access_token.options[:param_name] = :oauth_token @raw_info ||= access_token.post(access_token['id']).parsed end + + extra do + raw_info.merge({ + 'instance_url' => access_token.params['instance_url'], + 'pod' => access_token.params['instance_url'] + }) + end + end + + class SalesforceSandbox < OmniAuth::Strategies::Salesforce + default_options[:client_options][:site] = 'https://test.salesforce.com' + end + class DatabaseDotCom < OmniAuth::Strategies::Salesforce + default_options[:client_options][:site] = 'https://login.database.com' + end + end -end \ No newline at end of file +end