Class: OmniAuth::Strategies::InstagramBasic

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

Constant Summary collapse

SITE_URL =
'https://api.instagram.com'.freeze
TOKEN_PATH =
'oauth/access_token'.freeze
TOKEN_OPTIONS =
["client_id", "client_secret"].freeze

Instance Method Summary collapse

Instance Method Details

#callback_urlObject



19
20
21
# File 'lib/omniauth/strategies/instagram_basic.rb', line 19

def callback_url
  options[:redirect_uri] || (full_host + script_name + callback_path)
end

#credentials_generatorObject



53
54
55
56
57
58
59
60
# File 'lib/omniauth/strategies/instagram_basic.rb', line 53

def credentials_generator
  {
    "token" => raw_token_info["access_token"],
    "short_lived_token" => access_token.token,
    "expires" => true,
    "expires_at" => raw_token_info["expires_in"]
  }
end

#info_generatorObject



44
45
46
47
48
49
50
51
# File 'lib/omniauth/strategies/instagram_basic.rb', line 44

def info_generator
  {
    id: raw_info["id"],
    account_type: raw_info["account_type"],
    media_count: raw_info["media_count"],
    username: raw_info["username"]
  }
end

#raw_infoObject



36
37
38
39
40
41
42
# File 'lib/omniauth/strategies/instagram_basic.rb', line 36

def raw_info
  url = "https://graph.instagram.com/me? \
          fields=id,account_type,media_count,username \
          &access_token=#{access_token.token}"
  
  @raw_info ||= access_token.get(url).parsed || {}
end

#raw_token_infoObject

Instagram provides a short lived token initial with the option to request a long lived token developers.facebook.com/docs/instagram-basic-display-api/guides/long-lived-access-tokens



25
26
27
28
29
30
31
32
# File 'lib/omniauth/strategies/instagram_basic.rb', line 25

def raw_token_info
  url = "https://graph.instagram.com/access_token? \
          grant_type=ig_exchange_token \
          &client_secret=#{token_params["client_secret"]} \
          &access_token=#{access_token.token}"

  @raw_token_info ||= access_token.get(url).parsed || {}
end