class Fb::Auth
Provides methods to authenticate a user with the Facebook OAuth flow. @see developers.facebook.com/docs/facebook-login
Constants
- VERSION
@return [String] the SemVer-compatible gem version. @see semver.org
Public Class Methods
new(options = {})
click to toggle source
@param [Hash] options the options to initialize an instance of Fb::Auth
. @option [String] :redirect_uri The URI to redirect users to
after they have completed the Facebook OAuth flow.
@option [String] :code A single-use authorization code provided
by Facebook OAuth to obtain an access token.
# File lib/fb/auth.rb, line 17 def initialize(options = {}) @redirect_uri = options[:redirect_uri] @code = options[:code] end
Public Instance Methods
access_token()
click to toggle source
@return [String] the non-expiring access token of an authenticated Facebook account.
# File lib/fb/auth.rb, line 28 def access_token response_body = Fb::Request.new(path: '/oauth/access_token', params: long_term_token_params).run response_body["access_token"] end
url()
click to toggle source
@return [String] a url to Facebook's account authentication.
# File lib/fb/auth.rb, line 23 def url Fb::Request.new(url_options).url end
Private Instance Methods
long_term_token_params()
click to toggle source
# File lib/fb/auth.rb, line 55 def long_term_token_params {}.tap do |params| params[:client_secret] = Fb.configuration.client_secret params[:grant_type] = :fb_exchange_token params[:fb_exchange_token] = short_term_access_token end end
short_term_access_token()
click to toggle source
# File lib/fb/auth.rb, line 36 def short_term_access_token response_body = Fb::Request.new(path: '/oauth/access_token', params: short_term_token_params).run response_body["access_token"] end
short_term_token_params()
click to toggle source
# File lib/fb/auth.rb, line 47 def short_term_token_params {}.tap do |params| params[:client_secret] = Fb.configuration.client_secret params[:redirect_uri] = @redirect_uri params[:code] = @code end end
url_options()
click to toggle source
# File lib/fb/auth.rb, line 42 def url_options url_params = {scope: 'email,manage_pages', redirect_uri: @redirect_uri} {host: 'www.facebook.com', path: '/dialog/oauth', params: url_params} end