Class: OmniAuth::Strategies::Facebook

Inherits:
OAuth2
  • Object
show all
Defined in:
lib/omniauth/strategies/facebook.rb

Defined Under Namespace

Classes: NoAuthorizationCodeError

Constant Summary collapse

DEFAULT_SCOPE =
'email'
DEFAULT_FACEBOOK_API_VERSION =
'v19.0'.freeze

Instance Method Summary collapse

Instance Method Details

#access_token_optionsObject



92
93
94
# File 'lib/omniauth/strategies/facebook.rb', line 92

def access_token_options
  options.access_token_options.inject({}) { |h,(k,v)| h[k.to_sym] = v; h }
end

#authorize_paramsObject

You can pass display, scope, auth_type or config_id params to the auth request, if you need to set them dynamically. You can also set these options in the OmniAuth config :authorize_params option.

For example: /auth/facebook?display=popup



100
101
102
103
104
105
106
107
108
109
110
# File 'lib/omniauth/strategies/facebook.rb', line 100

def authorize_params
  super.tap do |params|
    %w[display scope auth_type config_id].each do |v|
      if request.params[v]
        params[v.to_sym] = request.params[v]
      end
    end

    params[:scope] ||= DEFAULT_SCOPE
  end
end

#callback_phaseObject



70
71
72
73
74
75
76
77
78
# File 'lib/omniauth/strategies/facebook.rb', line 70

def callback_phase
  with_authorization_code! do
    super
  end
rescue NoAuthorizationCodeError => e
  fail!(:no_authorization_code, e)
rescue OmniAuth::Facebook::SignedRequest::UnknownSignatureAlgorithmError => e
  fail!(:unknown_signature_algorithm, e)
end

#callback_urlObject

NOTE If we’re using code from the signed request then FB sets the redirect_uri to ” during the authorize

phase and it must match during the access_token phase:
https://github.com/facebook/facebook-php-sdk/blob/master/src/base_facebook.php#L477


83
84
85
86
87
88
89
90
# File 'lib/omniauth/strategies/facebook.rb', line 83

def callback_url
  if options.authorization_code_from_signed_request_in_cookie
    ''
  else
    # Fixes regression in omniauth-oauth2 v1.4.0 by https://github.com/intridea/omniauth-oauth2/commit/85fdbe117c2a4400d001a6368cc359d88f40abc7
    options[:callback_url] || (full_host + callback_path)
  end
end

#info_optionsObject



62
63
64
65
66
67
68
# File 'lib/omniauth/strategies/facebook.rb', line 62

def info_options
  params = {appsecret_proof: appsecret_proof}
  params.merge!({fields: (options[:info_fields] || 'name,email')})
  params.merge!({locale: options[:locale]}) if options[:locale]

  { params: params }
end

#raw_infoObject



58
59
60
# File 'lib/omniauth/strategies/facebook.rb', line 58

def raw_info
  @raw_info ||= access_token.get('me', info_options).parsed || {}
end