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



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

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



12
13
14
# File 'lib/omniauth/strategies/instagram.rb', line 12

def callback_url
  full_host + script_name + callback_path
end

#generate_sig(endpoint, params) ⇒ Object



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

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')
  return OpenSSL::HMAC.hexdigest(digest, secret, sig)
end

#raw_infoObject



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

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



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

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