Class: OmniAuth::Strategies::MVC

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

Defined Under Namespace

Classes: NoAuthorizationCodeError

Instance Method Summary collapse

Instance Method Details

#access_token_optionsObject



80
81
82
# File 'lib/omniauth/strategies/mvc.rb', line 80

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

#appsecret_proofObject



98
99
100
# File 'lib/omniauth/strategies/mvc.rb', line 98

def appsecret_proof
  @appsecret_proof ||= OpenSSL::HMAC.hexdigest(OpenSSL::Digest::SHA256.new, client.secret, access_token.token)
end

#authorize_paramsObject

You can pass display, scope, or auth_type 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



88
89
90
91
92
93
94
95
96
# File 'lib/omniauth/strategies/mvc.rb', line 88

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

#callback_urlObject



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

def callback_url
  if @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 + script_name + callback_path)
  end
end

#info_optionsObject



39
40
41
42
43
44
45
# File 'lib/omniauth/strategies/mvc.rb', line 39

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

#old_request_phaseObject



47
# File 'lib/omniauth/strategies/mvc.rb', line 47

alias :old_request_phase :request_phase

#raw_infoObject



33
34
35
36
37
# File 'lib/omniauth/strategies/mvc.rb', line 33

def raw_info
  @raw_info ||= access_token.get('api/me', info_options).parsed || {}
rescue ::Errno::ETIMEDOUT
  raise ::Timeout::Error
end

#request_phaseObject



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/omniauth/strategies/mvc.rb', line 49

def request_phase
  %w[force_login lang screen_name].each do |v|
    if request.params[v]
      options[:authorize_params][v.to_sym] = request.params[v]
    end
  end

  %w[x_auth_access_type].each do |v|
    if request.params[v]
      options[:request_params][v.to_sym] = request.params[v]
    end
  end

  if options[:use_authorize] || request.params['use_authorize'] == 'true'
    options[:client_options][:authorize_path] = '/oauth/authorize'
  else
    options[:client_options][:authorize_path] = '/oauth/authenticate'
  end

  old_request_phase
end