forked from omniauth/omniauth
/
instagram.rb
58 lines (52 loc) · 1.66 KB
/
instagram.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
require 'omniauth/oauth'
require 'multi_json'
module OmniAuth
module Strategies
# Authenticate to Facebook utilizing OAuth 2.0 and retrieve
# basic user information.
#
# @example Basic Usage
# use OmniAuth::Strategies::Instagram, 'client_id', 'client_secret'
class Instagram < OmniAuth::Strategies::OAuth2
# @option options [String] :scope separate the scopes by a space
def initialize(app, client_id=nil, client_secret=nil, options={}, &block)
client_options = {
:authorize_url => 'https://api.instagram.com/oauth/authorize',
:token_url => 'https://api.instagram.com/oauth/access_token',
}
super(app, :instagram, client_id, client_secret, client_options, options, &block)
end
def auth_hash
OmniAuth::Utils.deep_merge(
super, {
'uid' => user_data['data']['id'],
'user_info' => user_info,
'extra' => {
'user_hash' => user_data['data'],
}
}
)
end
def request_phase
options[:scope] ||= 'basic'
options[:response_type] ||= 'code'
super
end
def callback_phase
options[:grant_type] ||= 'authorization_code'
super
end
def user_data
@access_token.options.merge!({:param_name => 'access_token', :mode => :query})
@data ||= MultiJson.decode(@access_token.get('/v1/users/self'))
end
def user_info
{
'nickname' => user_data['data']['username'],
'name' => user_data['data']['full_name'],
'image' => user_data['data']['profile_picture'],
}
end
end
end
end