-
Notifications
You must be signed in to change notification settings - Fork 167
/
Copy pathtwitter.rb
102 lines (84 loc) · 2.74 KB
/
twitter.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
require 'omniauth-oauth'
require 'json'
module OmniAuth
module Strategies
class Twitter < OmniAuth::Strategies::OAuth
option :name, 'twitter'
option :client_options, {:authorize_path => '/oauth/authenticate',
:site => 'https://api.x.com',
:proxy => ENV['http_proxy'] ? URI(ENV['http_proxy']) : nil}
uid { access_token.params[:user_id] }
info do
{
:nickname => raw_info['screen_name'],
:name => raw_info['name'],
:email => raw_info["email"],
:location => raw_info['location'],
:image => image_url,
:description => raw_info['description'],
:urls => {
'Website' => raw_info['url'],
'Twitter' => "https://twitter.com/#{raw_info['screen_name']}",
}
}
end
extra do
skip_info? ? {} : { :raw_info => raw_info }
end
def raw_info
@raw_info ||= JSON.load(access_token.get('/1.1/account/verify_credentials.json?include_entities=false&skip_status=true&include_email=true').body)
rescue ::Errno::ETIMEDOUT
raise ::Timeout::Error
end
alias :old_request_phase :request_phase
def request_phase
%w[force_login lang screen_name].each do |v|
if request.params[v]
options[:authorize_params][v.to_sym] = request.params[v]
end
end
%w[x_auth_access_type].each do |v|
if request.params[v]
options[:request_params][v.to_sym] = request.params[v]
end
end
if options[:use_authorize] || request.params['use_authorize'] == 'true'
options[:client_options][:authorize_path] = '/oauth/authorize'
else
options[:client_options][:authorize_path] = '/oauth/authenticate'
end
old_request_phase
end
alias :old_callback_url :callback_url
def callback_url
if request.params['callback_url']
request.params['callback_url']
else
old_callback_url
end
end
def callback_path
params = session['omniauth.params']
if params.nil? || params['callback_url'].nil?
super
else
URI(params['callback_url']).path
end
end
private
def image_url
original_url = options[:secure_image_url] ? raw_info['profile_image_url_https'] : raw_info['profile_image_url']
case options[:image_size]
when 'mini'
original_url.sub('normal', 'mini')
when 'bigger'
original_url.sub('normal', 'bigger')
when 'original'
original_url.sub('_normal', '')
else
original_url
end
end
end
end
end