Class: Facepalm::EndpointController

Inherits:
ActionController::Base
  • Object
show all
Defined in:
app/controllers/facepalm/endpoint_controller.rb

Instance Method Summary collapse

Instance Method Details

#showObject

OAuth 2.0 endpoint action added to ApplicationController and mounted to /facebook_oauth



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/controllers/facepalm/endpoint_controller.rb', line 4

def show
  if params[:error]
    raise Facepalm::OAuthException.new(params[:error][:message])
  else
    # this is where you get a code for requesting an access_token to do additional OAuth requests
    # outside of using the FB JavaScript library (see Authenticating Users in a Web Application
    # under the Authentication docs at http://developers.facebook.com/docs/authentication/)
    if params[:code]
      begin
        # Decrypting return URL and redirecting to it
        redirect_to(facebook_canvas_page_url + facepalm_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 facebook_canvas_page_url
      end

      false
    else
      raise Facepalm::OAuthException.new('No code returned.')
    end
  end
end