Class: OmniAuth::Strategies::Instagram

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

Instance Method Summary collapse

Instance Method Details

#authorize_paramsObject

You can pass scope 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/instagram?scope=likes+photos



59
60
61
62
63
64
65
66
67
68
# File 'lib/omniauth/strategies/instagram.rb', line 59

def authorize_params
  super.tap do |params|
    %w[scope].each do |v|
      params[v.to_sym] = request.params[v] if request.params[v]
      if params[v.to_sym]
        params[v.to_sym] = Array(params[v.to_sym]).join(' ')
      end
    end
  end
end

#callback_urlObject



10
11
12
# File 'lib/omniauth/strategies/instagram.rb', line 10

def callback_url
  full_host + script_name + callback_path
end

#generate_sig(endpoint, params) ⇒ Object



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

def generate_sig(endpoint, params)
  require 'openssl'
  require 'base64'
  sig = endpoint
  secret = options[:client_secret]
  params.sort.map do |key, val|
    sig += '|%s=%s' % [key, val]
  end
  digest = OpenSSL::Digest.new('sha256')
  OpenSSL::HMAC.hexdigest(digest, secret, sig)
end

#raw_infoObject



41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/omniauth/strategies/instagram.rb', line 41

def raw_info
  if options[:extra_data]
    endpoint = '/users/self'
    params = {}
    access_token.options[:mode] = :query
    access_token.options[:param_name] = 'access_token'
    params['sig'] = generate_sig(endpoint, 'access_token' => access_token.token) if options[:enforce_signed_requests]
    @data ||= access_token.get("/v1#{endpoint}", params: params).parsed['data'] || {}
  else
    @data ||= access_token.params['user']
  end
  @data
end

#request_phaseObject



14
15
16
17
18
19
20
# File 'lib/omniauth/strategies/instagram.rb', line 14

def request_phase
  options[:scope] ||= 'basic'
  options[:response_type] ||= 'code'
  options[:enforce_signed_requests] ||= false
  options[:extra_data] ||= false
  super
end