omniauth 0.2.5 → 0.2.6

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of omniauth might be problematic. Click here for more details.

Files changed (55) hide show
  1. data/.gitignore +49 -29
  2. data/.travis.yml +2 -0
  3. data/Gemfile +4 -0
  4. data/{LICENSE → LICENSE.md} +1 -1
  5. data/{README.markdown → README.md} +11 -5
  6. data/Rakefile +2 -1
  7. data/lib/omniauth/version.rb +1 -1
  8. data/oa-basic/Gemfile +7 -0
  9. data/oa-basic/lib/omniauth/version.rb +1 -1
  10. data/oa-basic/oa-basic.gemspec +1 -2
  11. data/oa-core/Gemfile +3 -0
  12. data/oa-core/lib/omniauth/form.rb +5 -3
  13. data/oa-core/lib/omniauth/strategy.rb +5 -5
  14. data/oa-core/lib/omniauth/version.rb +1 -1
  15. data/oa-core/oa-core.gemspec +1 -1
  16. data/oa-core/spec/omniauth/strategy_spec.rb +5 -0
  17. data/oa-enterprise/Gemfile +7 -0
  18. data/oa-enterprise/lib/omniauth/strategies/cas/service_ticket_validator.rb +13 -6
  19. data/oa-enterprise/lib/omniauth/version.rb +1 -1
  20. data/oa-enterprise/oa-enterprise.gemspec +1 -2
  21. data/oa-enterprise/spec/omniauth/strategies/ldap_spec.rb +41 -0
  22. data/oa-more/Gemfile +7 -0
  23. data/oa-more/lib/omniauth/more.rb +2 -0
  24. data/oa-more/lib/omniauth/strategies/draugiem.rb +104 -0
  25. data/oa-more/lib/omniauth/strategies/ign.rb +93 -0
  26. data/oa-more/lib/omniauth/strategies/yupoo.rb +8 -8
  27. data/oa-more/lib/omniauth/version.rb +1 -1
  28. data/oa-more/oa-more.gemspec +1 -2
  29. data/oa-more/spec/omniauth/strategies/draugiem_spec.rb +51 -0
  30. data/oa-more/spec/spec_helper.rb +1 -1
  31. data/oa-oauth/Gemfile +7 -0
  32. data/oa-oauth/lib/omniauth/oauth.rb +3 -0
  33. data/oa-oauth/lib/omniauth/strategies/facebook.rb +1 -1
  34. data/oa-oauth/lib/omniauth/strategies/google.rb +2 -2
  35. data/oa-oauth/lib/omniauth/strategies/gowalla.rb +9 -1
  36. data/oa-oauth/lib/omniauth/strategies/linked_in.rb +17 -16
  37. data/oa-oauth/lib/omniauth/strategies/mailru.rb +107 -0
  38. data/oa-oauth/lib/omniauth/strategies/oauth.rb +2 -4
  39. data/oa-oauth/lib/omniauth/strategies/oauth2.rb +5 -12
  40. data/oa-oauth/lib/omniauth/strategies/plurk.rb +58 -0
  41. data/oa-oauth/lib/omniauth/strategies/taobao.rb +79 -0
  42. data/oa-oauth/lib/omniauth/strategies/vkontakte.rb +7 -4
  43. data/oa-oauth/lib/omniauth/version.rb +1 -1
  44. data/oa-oauth/oa-oauth.gemspec +1 -2
  45. data/oa-oauth/spec/omniauth/strategies/mailru_spec.rb +5 -0
  46. data/oa-oauth/spec/omniauth/strategies/plurk_spec.rb +5 -0
  47. data/oa-oauth/spec/omniauth/strategies/taobao_spec.rb +5 -0
  48. data/oa-openid/Gemfile +7 -0
  49. data/oa-openid/lib/omniauth/openid.rb +1 -0
  50. data/oa-openid/lib/omniauth/strategies/steam.rb +55 -0
  51. data/oa-openid/lib/omniauth/version.rb +1 -1
  52. data/oa-openid/oa-openid.gemspec +1 -2
  53. data/omniauth.gemspec +8 -8
  54. data/tasks/all.rb +1 -1
  55. metadata +34 -18
@@ -0,0 +1,107 @@
1
+ require 'omniauth/oauth'
2
+ require 'multi_json'
3
+
4
+ module OmniAuth
5
+ module Strategies
6
+ #
7
+ # Authenticate to Vkontakte utilizing OAuth 2.0 and retrieve
8
+ # basic user information.
9
+ # documentation available here:
10
+ # http://api.mail.ru/docs/guides/oauth/sites/
11
+ #
12
+ # @example Basic Usage
13
+ # use OmniAuth::Strategies::Mailru, 'API Key', 'Secret Key', :private_key => 'Private Key'
14
+ class Mailru < OAuth2
15
+ # @param [Rack Application] app standard middleware application parameter
16
+ # @param [String] api_key the application id as [registered in Mailru]
17
+ # @param [String] secret_key the application secret as [registered in Mailru]
18
+ def initialize(app, api_key = nil, secret_key = nil, options = {}, &block)
19
+ client_options = {
20
+ :site => 'https://connect.mail.ru',
21
+ :authorize_path => '/oauth/authorize',
22
+ :access_token_path => '/oauth/token'
23
+ }
24
+
25
+ @private_key = options[:private_key]
26
+
27
+ super(app, :mailru, api_key, secret_key, client_options, options, &block)
28
+ end
29
+
30
+ protected
31
+
32
+ def request_phase
33
+ options[:response_type] ||= 'code'
34
+ super
35
+ end
36
+
37
+ def calculate_signature(params)
38
+ str = params['uids'] + (params.sort.collect { |c| "#{c[0]}=#{c[1]}" }).join('') + @private_key
39
+ Digest::MD5.hexdigest(str)
40
+ end
41
+
42
+ def user_data
43
+ request_params = {
44
+ 'method' => 'users.getInfo',
45
+ 'app_id' => client_id,
46
+ 'session_key' => @access_token.token,
47
+ 'uids' => @access_token['x_mailru_vid']
48
+ }
49
+
50
+ request_params.merge!('sig' => calculate_signature(request_params))
51
+ @data ||= MultiJson.decode(client.request(:get, 'http://www.appsmail.ru/platform/api', request_params))[0]
52
+ end
53
+
54
+ #"uid": "15410773191172635989",
55
+ #"first_name": "Евгений",
56
+ #"last_name": "Маслов",
57
+ #"nick": "maslov",
58
+ #"sex": 0,
59
+ #"birthday": "15.02.1980",
60
+ #"has_pic": 1,
61
+ #"pic": "http://avt.appsmail.ru/mail/emaslov/_avatar",
62
+ #"pic_small": "http://avt.appsmail.ru/mail/emaslov/_avatarsmall",
63
+ #"pic_big": "http://avt.appsmail.ru/mail/emaslov/_avatarbig",
64
+ #"link": "http://my.mail.ru/mail/emaslov/",
65
+ #"referer_type": "",
66
+ #"referer_id": "",
67
+ #"is_online": 1,
68
+ #"vip" : 1,
69
+ #"location": {
70
+ # "country": {
71
+ # "name": "Россия",
72
+ # "id": "24"
73
+ # },
74
+ # "city": {
75
+ # "name": "Москва",
76
+ # "id": "25"
77
+ # },
78
+ # "region": {
79
+ # "name": "Москва",
80
+ # "id": "999999"
81
+ # }
82
+ #}
83
+
84
+ def user_info
85
+ {
86
+ 'nickname' => user_data['nick'],
87
+ 'email' => user_data['email'],
88
+ 'first_name' => user_data["first_name"],
89
+ 'last_name' => user_data["last_name"],
90
+ 'name' => "#{user_data['first_name']} #{user_data['last_name']}",
91
+ 'image' => @data['pic'],
92
+ 'urls' => {
93
+ 'Mailru' => user_data["link"]
94
+ }
95
+ }
96
+ end
97
+
98
+ def auth_hash
99
+ OmniAuth::Utils.deep_merge(super, {
100
+ 'uid' => user_data['uid'],
101
+ 'user_info' => user_info,
102
+ 'extra' => {'user_hash' => user_data}
103
+ })
104
+ end
105
+ end
106
+ end
107
+ end
@@ -31,15 +31,13 @@ module OmniAuth
31
31
  request_token = consumer.get_request_token(:oauth_callback => callback_url)
32
32
  session['oauth'] ||= {}
33
33
  session['oauth'][name.to_s] = {'callback_confirmed' => request_token.callback_confirmed?, 'request_token' => request_token.token, 'request_secret' => request_token.secret}
34
- r = Rack::Response.new
35
34
 
36
35
  if request_token.callback_confirmed?
37
- r.redirect(request_token.authorize_url(options[:authorize_params]))
36
+ redirect request_token.authorize_url(options[:authorize_params])
38
37
  else
39
- r.redirect(request_token.authorize_url(options[:authorize_params].merge(:oauth_callback => callback_url)))
38
+ redirect request_token.authorize_url(options[:authorize_params].merge(:oauth_callback => callback_url))
40
39
  end
41
40
 
42
- r.finish
43
41
  rescue ::Timeout::Error => e
44
42
  fail!(:timeout, e)
45
43
  end
@@ -49,7 +49,7 @@ module OmniAuth
49
49
  end
50
50
 
51
51
  def callback_url
52
- full_host + callback_path
52
+ full_host + script_name + callback_path
53
53
  end
54
54
 
55
55
  protected
@@ -64,22 +64,15 @@ module OmniAuth
64
64
  end
65
65
 
66
66
  @access_token = build_access_token
67
-
68
- if @access_token.expires? && @access_token.expires_in <= 0
69
- client.request(:post, client.access_token_url, {
70
- 'client_id' => client_id,
71
- 'grant_type' => 'refresh_token',
72
- 'client_secret' => client_secret,
73
- 'refresh_token' => @access_token.refresh_token
74
- }.merge(options))
75
- @access_token = client.web_server.get_access_token(verifier, {:redirect_uri => callback_url}.merge(options))
76
- end
67
+ @access_token = client.web_server.refresh_access_token(@access_token.refresh_token) if @access_token.expired?
77
68
 
78
69
  super
79
70
  rescue ::OAuth2::HTTPError, ::OAuth2::AccessDenied, CallbackError => e
80
71
  fail!(:invalid_credentials, e)
81
72
  rescue ::MultiJson::DecodeError => e
82
73
  fail!(:invalid_response, e)
74
+ rescue ::Timeout::Error, ::Errno::ETIMEDOUT => e
75
+ fail!(:timeout, e)
83
76
  end
84
77
 
85
78
  def build_access_token
@@ -89,7 +82,7 @@ module OmniAuth
89
82
 
90
83
  def auth_hash
91
84
  credentials = {'token' => @access_token.token}
92
- credentials.merge('refresh_token' => @access_token.refresh_token) if @access_token.expires?
85
+ credentials.merge!('refresh_token' => @access_token.refresh_token) if @access_token.expires?
93
86
 
94
87
  OmniAuth::Utils.deep_merge(super, {'credentials' => credentials})
95
88
  end
@@ -0,0 +1,58 @@
1
+ require 'omniauth/oauth'
2
+ require 'multi_json'
3
+
4
+ module OmniAuth
5
+ module Strategies
6
+ #
7
+ # Authenticate to Plurk via OAuth and retrieve basic user info.
8
+ #
9
+ # Please note that this strategy relies on Plurk API 2.0,
10
+ # which is still in Beta.
11
+ #
12
+ # Usage:
13
+ # use OmniAuth::Strategies::Plurk
14
+ class Plurk < OmniAuth::Strategies::OAuth
15
+
16
+ # @param [Rack Application] app standard middleware application parameter
17
+ # @param [String] client_key App key [registered on plurk] (http://www.plurk.com/PlurkApp/register)
18
+ # @param [String] client_secret App secret registered on plurk
19
+ def initialize(app, client_key = nil, client_secret = nil, options = {}, &block)
20
+ client_options = { :site => 'http://www.plurk.com',
21
+ :request_token_path => '/OAuth/request_token',
22
+ :access_token_path => '/OAuth/access_token',
23
+ :authorize_path => '/OAuth/authorize' }
24
+
25
+ super(app, :plurk, client_key, client_secret, client_options, options)
26
+ end
27
+
28
+ def auth_hash
29
+ user = self.user_hash
30
+ OmniAuth::Utils.deep_merge(super, {
31
+ 'uid' => user['id'],
32
+ 'user_info' => user_info,
33
+ 'extra' => {'user_hash' => user_hash}
34
+ })
35
+ end
36
+
37
+ def user_info
38
+ user = self.user_hash
39
+ {
40
+ 'name' => user['full_name'],
41
+ 'nickname' => user['display_name'] || user['nick_name'],
42
+ 'location' => user['location'],
43
+ 'image' => if user['has_profile_image'] == 1
44
+ "http://avatars.plurk.com/#{user['id']}-medium#{user['avatar']}.gif"
45
+ else
46
+ "http://www.plurk.com/static/default_medium.gif"
47
+ end,
48
+ 'urls' => { 'Plurk' => 'http://plurk.com/' + user['nick_name']}
49
+ }
50
+ end
51
+
52
+ def user_hash
53
+ @user_hash ||= MultiJson.decode(@access_token.get('/APP/Profile/getOwnProfile').body)['user_info']
54
+ end
55
+
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,79 @@
1
+ require 'omniauth/oauth'
2
+ require 'multi_json'
3
+ require 'digest/md5'
4
+ require 'net/http'
5
+
6
+ module OmniAuth
7
+ module Strategies
8
+ # Authenticate to Renren utilizing OAuth 2.0 and retrieve
9
+ # basic user information.
10
+ #
11
+ # @example Basic Usage
12
+ # use OmniAuth::Strategies::TB, 'client_id', 'client_secret'
13
+ class TB < OAuth2
14
+ # @param [Rack Application] app standard middleware application parameter
15
+ # @param [String] client_id the app key at taobao open platform
16
+ # @param [String] client_secret the app secret at taobao open platform
17
+ # @option options [String]
18
+
19
+ def initialize(app, client_id = nil, client_secret = nil, options = {}, &block)
20
+ client_options = {
21
+ :site => "https://oauth.taobao.com/",
22
+ :authorize_url => "/authorize",
23
+ :access_token_url => "/token"
24
+ }
25
+
26
+ super(app, :tb, client_id, client_secret, client_options, options, &block)
27
+ end
28
+
29
+ def user_data
30
+ # TODO to be moved in options
31
+ url = 'http://gw.api.taobao.com/router/rest'
32
+
33
+ query_param = {
34
+ :app_key => client_id,
35
+
36
+ # TODO to be moved in options
37
+ # TODO add more default fields (http://my.open.taobao.com/apidoc/index.htm#categoryId:1-dataStructId:3)
38
+ :fields => 'user_id,uid,nick,sex,buyer_credit,seller_credit,location,created,last_visit,birthday,type,status,alipay_no,alipay_account,alipay_account,email,consumer_protection,alipay_bind',
39
+ :format => 'json',
40
+ :method => 'taobao.user.get',
41
+ :session => @access_token.token,
42
+ :sign_method => 'md5',
43
+ :timestamp => Time.now.strftime("%Y-%m-%d %H:%M:%S"),
44
+ :v => '2.0'
45
+ }
46
+ query_param = generate_sign(query_param)
47
+ res = Net::HTTP.post_form(URI.parse(url), query_param)
48
+ @data ||= MultiJson.decode(res.body)["user_get_response"]["user"]
49
+ end
50
+
51
+ def request_phase
52
+ options[:state] ||= '1'
53
+ super
54
+ end
55
+
56
+ def user_info
57
+ {
58
+ 'name' => user_data["nick"],
59
+ 'email' => (user_data["email"] if user_data["email"]),
60
+ }
61
+ end
62
+
63
+ def auth_hash
64
+ OmniAuth::Utils.deep_merge(super, {
65
+ 'uid' => user_data['uid'],
66
+ 'user_info' => user_info,
67
+ 'extra' => {'user_hash' => user_data}
68
+ })
69
+ end
70
+
71
+ def generate_sign(params)
72
+ str = client_secret + (params.sort.collect { |k, v| "#{k}#{v}" }).join + client_secret
73
+ params["sign"] = Digest::MD5.hexdigest(str).upcase!
74
+ params
75
+ end
76
+
77
+ end
78
+ end
79
+ end
@@ -29,17 +29,19 @@ module OmniAuth
29
29
 
30
30
  def user_data
31
31
  # http://vkontakte.ru/developers.php?o=-17680044&p=Description+of+Fields+of+the+fields+Parameter
32
- @fields ||= ['uid', 'first_name', 'last_name', 'nickname', 'domain', 'sex', 'city', 'country', 'timezone', 'photo', 'photo_big']
32
+ @fields ||= ['uid', 'first_name', 'last_name', 'nickname', 'domain', 'sex', 'bdate', 'city', 'country', 'timezone', 'photo', 'photo_big']
33
33
 
34
34
  # http://vkontakte.ru/developers.php?o=-1&p=getProfiles
35
35
  @data ||= MultiJson.decode(@access_token.get("https://api.vkontakte.ru/method/getProfiles?uid=#{@access_token['user_id']}&fields=#{@fields.join(',')}&access_token=#{@access_token.token}"))['response'][0]
36
36
 
37
37
  # we need these 2 additional requests since vkontakte returns only ids of the City and Country
38
38
  # http://vkontakte.ru/developers.php?o=-17680044&p=getCities
39
- @city ||= MultiJson.decode(@access_token.get("https://api.vkontakte.ru/method/getCities?cids=#{@data['city']}&access_token=#{@access_token.token}"))['response'][0]['name']
39
+ cities = MultiJson.decode(@access_token.get("https://api.vkontakte.ru/method/getCities?cids=#{@data['city']}&access_token=#{@access_token.token}"))['response']
40
+ @city ||= cities.first['name'] if cities && cities.first
40
41
 
41
42
  # http://vkontakte.ru/developers.php?o=-17680044&p=getCountries
42
- @country ||= MultiJson.decode(@access_token.get("https://api.vkontakte.ru/method/getCountries?cids=#{@data['country']}&access_token=#{@access_token}"))['response'][0]['name']
43
+ countries = MultiJson.decode(@access_token.get("https://api.vkontakte.ru/method/getCountries?cids=#{@data['country']}&access_token=#{@access_token}"))['response']
44
+ @country ||= countries.first['name'] if countries && countries.first
43
45
  end
44
46
 
45
47
  def request_phase
@@ -49,10 +51,11 @@ module OmniAuth
49
51
 
50
52
  def user_info
51
53
  {
52
- 'firstname' => @data['first_name'],
54
+ 'first_name' => @data['first_name'],
53
55
  'last_name' => @data['last_name'],
54
56
  'name' => "#{@data['first_name']} #{@data['last_name']}",
55
57
  'nickname' => @data['nickname'],
58
+ 'birth_date' => @data['bdate'],
56
59
  'image' => @data['photo'],
57
60
  'location' => "#{@country}, #{@city}",
58
61
  'urls' => {
@@ -7,7 +7,7 @@ module OmniAuth
7
7
  MINOR = 2
8
8
  end
9
9
  unless defined?(::OmniAuth::Version::PATCH)
10
- PATCH = 5
10
+ PATCH = 6
11
11
  end
12
12
  unless defined?(::OmniAuth::Version::PRE)
13
13
  PRE = nil
@@ -3,7 +3,6 @@ require File.expand_path('../lib/omniauth/version', __FILE__)
3
3
 
4
4
  Gem::Specification.new do |gem|
5
5
  gem.add_runtime_dependency 'faraday', '~> 0.6.1'
6
- gem.add_runtime_dependency 'jruby-openssl', '~> 0.7.3' if RUBY_PLATFORM == 'java'
7
6
  gem.add_runtime_dependency 'multi_json', '~> 1.0.0'
8
7
  gem.add_runtime_dependency 'multi_xml', '~> 0.2.2'
9
8
  gem.add_runtime_dependency 'oa-core', OmniAuth::Version::STRING
@@ -16,7 +15,7 @@ Gem::Specification.new do |gem|
16
15
  gem.add_development_dependency 'rspec', '~> 2.5'
17
16
  gem.add_development_dependency 'simplecov', '~> 0.4'
18
17
  gem.add_development_dependency 'webmock', '~> 1.6'
19
- gem.add_development_dependency 'yard', '~> 0.6'
18
+ gem.add_development_dependency 'yard', '~> 0.7'
20
19
  gem.add_development_dependency 'ZenTest', '~> 4.5'
21
20
  gem.name = 'oa-oauth'
22
21
  gem.version = OmniAuth::Version::STRING
@@ -0,0 +1,5 @@
1
+ require File.expand_path('../../../spec_helper', __FILE__)
2
+
3
+ describe OmniAuth::Strategies::Mailru do
4
+ it_should_behave_like "an oauth2 strategy"
5
+ end
@@ -0,0 +1,5 @@
1
+ require File.expand_path('../../../spec_helper', __FILE__)
2
+
3
+ describe OmniAuth::Strategies::Plurk do
4
+ it_should_behave_like 'an oauth strategy'
5
+ end
@@ -0,0 +1,5 @@
1
+ require File.expand_path('../../../spec_helper', __FILE__)
2
+
3
+ describe OmniAuth::Strategies::TB do
4
+ it_should_behave_like "an oauth2 strategy"
5
+ end
@@ -0,0 +1,7 @@
1
+ source 'http://rubygems.org'
2
+
3
+ platforms :jruby do
4
+ gem 'jruby-openssl', '~> 0.7'
5
+ end
6
+
7
+ gemspec
@@ -55,5 +55,6 @@ module OmniAuth
55
55
  module Strategies
56
56
  autoload :OpenID, 'omniauth/strategies/open_id'
57
57
  autoload :GoogleApps, 'omniauth/strategies/google_apps'
58
+ autoload :Steam, 'omniauth/strategies/steam'
58
59
  end
59
60
  end
@@ -0,0 +1,55 @@
1
+ require 'omniauth/openid'
2
+ module OmniAuth
3
+ module Strategies
4
+ class Steam < OmniAuth::Strategies::OpenID
5
+ def initialize(app, store = nil, api_key = nil, options = {}, &block)
6
+ options[:identifier] ||= "http://steamcommunity.com/openid"
7
+ options[:name] ||= 'steam'
8
+ @api_key = api_key
9
+ super(app, store, options, &block)
10
+ end
11
+
12
+ def user_info(response=nil)
13
+ player = user_hash['response']['players']['player'].first
14
+ nickname = player["personaname"]
15
+ name = player["realname"]
16
+ url = player["profileurl"]
17
+ country = player["loccountrycode"]
18
+ state = player["locstatecode"]
19
+ city = player["loccityid"]
20
+
21
+ {
22
+ 'nickname' => nickname,
23
+ 'name' => name,
24
+ 'url' => url,
25
+ 'location' => "#{city}, #{state}, #{country}"
26
+ }
27
+ end
28
+
29
+ def user_hash
30
+ # Steam provides no information back on a openid response other than a 64bit user id
31
+ # Need to use this information and make a API call to get user information from steam.
32
+ if @api_key
33
+ unless @user_hash
34
+ uri = URI.parse("http://api.steampowered.com/")
35
+ req = Net::HTTP::Get.new("#{uri.path}ISteamUser/GetPlayerSummaries/v0001/?key=#{@api_key}&steamids=#{@openid_response.display_identifier.split("/").last}")
36
+ res = Net::HTTP.start(uri.host, uri.port) {|http|
37
+ http.request(req)
38
+ }
39
+ end
40
+ @user_hash ||= MultiJson.decode(res.body)
41
+ else
42
+ {}
43
+ end
44
+ end
45
+
46
+ def auth_hash
47
+ OmniAuth::Utils.deep_merge(super, {
48
+ 'uid' => @openid_response.display_identifier.split("/").last,
49
+ 'user_info' => user_info,
50
+ 'extra' => {'user_hash' => user_hash}
51
+ })
52
+ end
53
+ end
54
+ end
55
+ end