Skip to content
Browse files

Allow to use with HTTPS

  • Loading branch information...
1 parent 0ad6266 commit de1c0e8c8f6a74882e20771ccc5b875a9578063b @dekart committed
View
11 lib/facebooker2.rb
@@ -6,7 +6,7 @@ class NotConfigured < Exception; end
class << self
- attr_accessor :api_key, :secret, :app_id, :canvas_page_name, :callback_url
+ attr_accessor :api_key, :secret, :app_id, :canvas_page_name, :callback_url, :callback_domain
end
@@ -19,8 +19,12 @@ def self.app_id
@app_id || raise_unconfigured_exception
end
- def self.canvas_page_url
- "http://apps.facebook.com/#{canvas_page_name}"
+ def self.canvas_page_url(protocol = 'http://')
+ "#{protocol}apps.facebook.com/#{canvas_page_name}"
+ end
+
+ def self.callback_url(protocol = 'http://')
+ @callback_domain ? "#{protocol}#{@callback_domain}" : @callback_url
end
@@ -35,6 +39,7 @@ def self.configuration=(hash)
self.app_id = hash[:app_id]
self.canvas_page_name = hash[:canvas_page_name]
self.callback_url = hash[:callback_url]
+ self.callback_domain = hash[:callback_domain]
end
View
12 lib/facebooker2/rails/controller.rb
@@ -14,6 +14,8 @@ def self.included(controller)
controller.helper_method :current_facebook_client
controller.helper_method :facebook_params
controller.helper_method :facebook_signed_request
+ controller.helper_method :facebook_canvas_page_url
+ controller.helper_method :facebook_callback_url
end
@@ -262,6 +264,16 @@ def set_fb_cookie(access_token,expires,uid,sig)
def set_p3p_header_for_third_party_cookies
response.headers['P3P'] = 'CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"'
end
+
+
+ def facebook_canvas_page_url
+ Facebooker2.canvas_page_url(request.protocol)
+ end
+
+ def facebook_callback_url
+ Facebooker2.callback_url(request.protocol)
+ end
+
# Appends facebook signed_request to params on redirect
def redirect_to(options = {}, response_status = {})
View
4 lib/facebooker2/rails/controller/canvas_oauth.rb
@@ -13,11 +13,11 @@ def facebook_oauth_connect
# under the Authentication docs at http://developers.facebook.com/docs/authentication/)
if params[:code]
begin
- redirect_to Facebooker2.canvas_page_url + facebook_url_encryptor.decrypt(params[:fb_return_to].to_s)
+ redirect_to facebook_canvas_page_url + facebook_url_encryptor.decrypt(params[:fb_return_to].to_s)
rescue ActiveSupport::MessageEncryptor::InvalidMessage
::Rails.logger.fatal "Failed to decrypt return URL: #{ params[:fb_return_to] }"
- redirect_to Facebooker2.canvas_page_url
+ redirect_to facebook_canvas_page_url
end
false
View
2 lib/facebooker2/rails/controller/url_rewriting.rb
@@ -18,7 +18,7 @@ def url_for_with_facebooker(options = {})
url = url_for_without_facebooker(options)
- canvas ? Facebooker2.canvas_page_url + url : url
+ canvas ? facebook_canvas_page_url + url : url
else
url_for_without_facebooker(options)
end
View
2 lib/facebooker2/rails/helpers/javascript.rb
@@ -76,7 +76,7 @@ def fb_connect_js(*args, &block)
else
js = <<-CODE
<div id="fb-root"></div>
- <script src="http://#{ js_url }" type="text/javascript"></script>
+ <script src="#{request.protocol}#{ js_url }" type="text/javascript"></script>
CODE
if options[:cache_url]
View
6 spec/rails/controller/canvas_oauth_spec.rb
@@ -1,7 +1,7 @@
require 'spec_helper'
class FakeCanvasOAuthController < ActionController::Base
- include Facebooker2::Rails::Controller::CanvasOAuth
+ include Facebooker2::Rails::Controller
before_filter :check_connection_and_permissions
@@ -21,7 +21,9 @@ def check_connection_and_permissions
end
let :controller do
- FakeCanvasOAuthController.new
+ FakeCanvasOAuthController.new.tap do |controller|
+ controller.stub!(:request).and_return(mock('request', :protocol => 'http://'))
+ end
end
describe "should extend with OAuth class methods" do

0 comments on commit de1c0e8

Please sign in to comment.
Something went wrong with that request. Please try again.