Class: InstagramBasicDisplay::Auth

Inherits:
Object
  • Object
show all
Defined in:
lib/instagram_basic_display/auth.rb

Instance Method Summary collapse

Constructor Details

#initialize(configuration) ⇒ Auth

Returns a new instance of Auth.



23
24
25
# File 'lib/instagram_basic_display/auth.rb', line 23

def initialize(configuration)
  @configuration = configuration
end

Instance Method Details

#long_lived_token(short_lived_token: nil, access_code: nil) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/instagram_basic_display/auth.rb', line 40

def long_lived_token(short_lived_token: nil, access_code: nil)
  short_lived_token ||= short_lived_token(access_code: access_code).payload.access_token

  uri = URI('https://graph.instagram.com/access_token')
  params = {
    client_secret: configuration.client_secret,
    grant_type: 'ig_exchange_token',
    access_token: short_lived_token
  }
  uri.query = URI.encode_www_form(params)

  response = Net::HTTP.get_response(uri)
  InstagramBasicDisplay::Response.new(response)
end

#refresh_long_lived_token(token:) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
# File 'lib/instagram_basic_display/auth.rb', line 55

def refresh_long_lived_token(token:)
  uri = URI('https://graph.instagram.com/refresh_access_token')
  params = {
    grant_type: 'ig_refresh_token',
    access_token: token
  }
  uri.query = URI.encode_www_form(params)

  response = Net::HTTP.get_response(uri)
  InstagramBasicDisplay::Response.new(response)
end

#short_lived_token(access_code:) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/instagram_basic_display/auth.rb', line 27

def short_lived_token(access_code:)
  response = Net::HTTP.post_form(
    URI('https://api.instagram.com/oauth/access_token'),
    client_id: configuration.client_id,
    client_secret: configuration.client_secret,
    grant_type: 'authorization_code',
    redirect_uri: configuration.redirect_uri,
    code: access_code
  )

  InstagramBasicDisplay::Response.new(response)
end