Permalink
Browse files

Merge pull request #2 from ahmadeeva-su/standalone

Make it possible to use Facepalm with standalone apps
  • Loading branch information...
2 parents 16d8ea6 + 89ba146 commit 61ba6855e9a097d4b8fe9a7d1f8d37928b78585c @dekart committed Feb 28, 2012
Showing with 16 additions and 8 deletions.
  1. +2 −1 .gitignore
  2. +6 −1 lib/facepalm/rails/controller.rb
  3. +8 −6 lib/facepalm/rails/controller/oauth_access.rb
View
@@ -1,2 +1,3 @@
pkg
-*~
+*~
+.project
@@ -16,7 +16,7 @@ def self.included(base)
# Fix cookie permission issue in IE
before_filter :normal_cookies_for_ie_in_iframes!
- helper_method(:facepalm, :fb_signed_request, :current_facebook_user, :params_without_facebook_data)
+ helper_method(:facepalm, :fb_signed_request, :current_facebook_user, :params_without_facebook_data, :fb_canvas?)
helper Facepalm::Rails::Helpers
end
@@ -50,6 +50,11 @@ def fb_signed_request
def params_without_facebook_data
params.except(:signed_request)
end
+
+ # Did the request come from canvas app
+ def fb_canvas?
+ request.env['HTTP_SIGNED_REQUEST'].present?
+ end
private
@@ -74,23 +74,25 @@ def facepalm_require_authentication(*permissions)
if current_facebook_user.try(:authenticated?)
true
else
- # Encrypting return URL to pass it to Facebook
- return_code = facepalm_url_encryptor.encrypt(
- url_for(params_without_facebook_data.merge(:canvas => false, :only_path => true))
- )
-
redirect_from_iframe(
facepalm.oauth_client.url_for_oauth_code(
:permissions => permissions,
:callback => facepalm_endpoint_url(
- :fb_return_to => ::Rack::Utils.escape(return_code)
+ :fb_return_to => ::Rack::Utils.escape(facepalm_auth_return_code)
)
)
)
false
end
end
+
+ # Encrypting return URL to pass it to Facebook
+ def facepalm_auth_return_code
+ facepalm_url_encryptor.encrypt(
+ url_for(params_without_facebook_data.merge(:canvas => false, :only_path => true))
+ )
+ end
# Internally used to encrypt return URL for authentication endpoint
#

0 comments on commit 61ba685

Please sign in to comment.