Class: RFacebook::FacebookWebSession
- Inherits:
-
FacebookSession
- Object
- FacebookSession
- RFacebook::FacebookWebSession
- Defined in:
- lib/facebook_web_session.rb
Instance Attribute Summary
Attributes inherited from FacebookSession
#last_error_code, #last_error_message, #logger, #session_expires, #session_key, #session_user_id, #suppress_errors
Instance Method Summary collapse
-
#activate_with_previous_session(key, uid = nil, expires = nil) ⇒ Object
Function: activate_with_previous_session Sets the session key directly (for example, if you have an infinite session key).
-
#activate_with_token(auth_token) ⇒ Object
Function: activate_with_token Gets the session information available after current user logs in.
-
#get_fb_sig_params(originalParams) ⇒ Object
Function: get_fb_sig_params Returns the fb_sig params from Hash that has all request params.
-
#get_install_url(options = {}) ⇒ Object
Function: get_install_url Gets the installation URL for this application.
-
#get_login_url(options = {}) ⇒ Object
Function: get_login_url Gets the authentication URL.
-
#get_secret(params) ⇒ Object
Function: get_secret Used by super::signature to generate a signature Web sessions simply use their API secret.
-
#is_activated? ⇒ Boolean
Function: is_activated? Returns true when we have activated ourselves somehow.
Methods inherited from FacebookSession
#_dump, _load, #initialize, #is_expired?, #is_ready?, #is_valid?, #last_error, #session_expired?, #session_uid, #suppress_exceptions, #suppress_exceptions=
Constructor Details
This class inherits a constructor from RFacebook::FacebookSession
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class RFacebook::FacebookSession
Instance Method Details
#activate_with_previous_session(key, uid = nil, expires = nil) ⇒ Object
Function: activate_with_previous_session
Sets the session key directly (for example, if you have an infinite session key)
Parameters:
key - the session key to use
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/facebook_web_session.rb', line 114 def activate_with_previous_session(key, uid=nil, expires=nil) # set the expiration @session_expires = expires # set the session key @session_key = key # determine the current user's id if uid @session_user_id = uid else result = call_method("users.getLoggedInUser") @session_user_id = result.at("users_getLoggedInUser_response").inner_html end end |
#activate_with_token(auth_token) ⇒ Object
Function: activate_with_token
Gets the session information available after current user logs in.
Parameters:
auth_token - string token passed back by the callback URL
100 101 102 103 104 105 106 107 |
# File 'lib/facebook_web_session.rb', line 100 def activate_with_token(auth_token) result = call_method("auth.getSession", {:auth_token => auth_token}) if result != nil @session_user_id = result.at("uid").inner_html @session_key = result.at("session_key").inner_html @session_expires = result.at("expires").inner_html end end |
#get_fb_sig_params(originalParams) ⇒ Object
Function: get_fb_sig_params
Returns the fb_sig params from Hash that has all request params. Hash is empty if the
signature was invalid.
Parameters:
originalParams - a Hash that contains the fb_sig_* params (i.e. Rails params)
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/facebook_web_session.rb', line 144 def get_fb_sig_params(originalParams) # setup timeout = 48*3600 prefix = "fb_sig_" # get the params prefixed by "fb_sig_" (and remove the prefix) sigParams = {} originalParams.each do |k,v| oldLen = k.length newK = k.sub(prefix, "") if oldLen != newK.length sigParams[newK] = v end end # handle invalidation if (timeout and (sigParams["time"].nil? or (Time.now.to_i - sigParams["time"].to_i > timeout.to_i))) # invalidate if the timeout has been reached #log_debug "** RFACEBOOK(GEM) - fbparams is empty because the signature was timed out" sigParams = {} end # check that the signatures match expectedSig = originalParams["fb_sig"] if !(sigParams and expectedSig and generate_signature(sigParams, @api_secret) == expectedSig) # didn't match, empty out the params #log_debug "** RFACEBOOK(GEM) - fbparams is empty because the signature did not match" sigParams = {} end return sigParams end |
#get_install_url(options = {}) ⇒ Object
Function: get_install_url
Gets the installation URL for this application
Parameters:
options.next - the page to redirect to after installation
77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/facebook_web_session.rb', line 77 def get_install_url(={}) # handle options nextPage = [:next] ||= nil # url pieces optionalNext = (nextPage == nil) ? "" : "&next=#{CGI.escape(nextPage.to_s)}" # build and return URL return "http://#{WWW_SERVER_BASE_URL}#{WWW_PATH_INSTALL}?api_key=#{@api_key}#{optionalNext}" end |
#get_login_url(options = {}) ⇒ Object
Function: get_login_url
Gets the authentication URL
Parameters:
options.next - the page to redirect to after login
options.popup - boolean, whether or not to use the popup style (defaults to false)
options.skipcookie - boolean, whether to force new Facebook login (defaults to false)
options.hidecheckbox - boolean, whether to show the "infinite session" option checkbox
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/facebook_web_session.rb', line 49 def get_login_url(={}) # handle options nextPage = [:next] ||= nil popup = ([:popup] == nil) ? false : true = ([:skipcookie] == nil) ? false : true hidecheckbox = ([:hidecheckbox] == nil) ? false : true frame = ([:frame] == nil) ? false : true canvas = ([:canvas] == nil) ? false : true # url pieces optionalNext = (nextPage == nil) ? "" : "&next=#{CGI.escape(nextPage.to_s)}" optionalPopup = (popup == true) ? "&popup=true" : "" optionalSkipCookie = ( == true) ? "&skipcookie=true" : "" optionalHideCheckbox = (hidecheckbox == true) ? "&hide_checkbox=true" : "" optionalFrame = (frame == true) ? "&fbframe=true" : "" optionalCanvas = (canvas == true) ? "&canvas=true" : "" # build and return URL return "http://#{WWW_SERVER_BASE_URL}#{WWW_PATH_LOGIN}?v=1.0&api_key=#{@api_key}#{optionalPopup}#{optionalNext}#{optionalSkipCookie}#{optionalHideCheckbox}#{optionalFrame}#{optionalCanvas}" end |
#get_secret(params) ⇒ Object
Function: get_secret
Used by super::signature to generate a signature
Web sessions simply use their API secret.
193 194 195 |
# File 'lib/facebook_web_session.rb', line 193 def get_secret(params) # :nodoc: return @api_secret end |
#is_activated? ⇒ Boolean
Function: is_activated?
Returns true when we have activated ourselves somehow
186 187 188 |
# File 'lib/facebook_web_session.rb', line 186 def is_activated? return (@session_key != nil) end |