oa-more 0.2.5 → 0.2.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Gemfile ADDED
@@ -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
@@ -5,5 +5,7 @@ module OmniAuth
5
5
  autoload :WindowsLive, 'omniauth/strategies/windows_live'
6
6
  autoload :Flickr, 'omniauth/strategies/flickr'
7
7
  autoload :Yupoo, 'omniauth/strategies/yupoo'
8
+ autoload :Ign, 'omniauth/strategies/ign'
9
+ autoload :Draugiem, 'omniauth/strategies/draugiem'
8
10
  end
9
11
  end
@@ -0,0 +1,104 @@
1
+ require 'omniauth/core'
2
+ require 'digest/md5'
3
+ require 'rest-client'
4
+ require 'multi_json'
5
+
6
+ module OmniAuth
7
+ module Strategies
8
+ #
9
+ # Authenticate to draugiem.lv and frype.com and others.
10
+ #
11
+ # @example Basic Rails Usage
12
+ #
13
+ # Add this to config/initializers/omniauth.rb
14
+ #
15
+ # Rails.application.config.middleware.use OmniAuth::Builder do
16
+ # provider :draugiem, 'App id', 'API Key'
17
+ # end
18
+ #
19
+ # @example Basic Rack example
20
+ #
21
+ # use Rack::Session::Cookie
22
+ # use OmniAuth::Strategies::Draugiem, 'App id', 'API Key'
23
+ #
24
+ class Draugiem
25
+ include OmniAuth::Strategy
26
+ attr_accessor :app_id, :api_key
27
+
28
+ def initialize(app, app_id, api_key)
29
+ super(app, :draugiem)
30
+ @app_id = app_id
31
+ @api_key = api_key
32
+ end
33
+
34
+ protected
35
+
36
+ def request_phase
37
+ params = {
38
+ :app => @app_id,
39
+ :redirect => callback_url,
40
+ :hash => Digest::MD5.hexdigest("#{@api_key}#{callback_url}")
41
+ }
42
+ query_string = params.collect{ |key,value| "#{key}=#{Rack::Utils.escape(value)}" }.join('&')
43
+ redirect "http://api.draugiem.lv/authorize/?#{query_string}"
44
+ end
45
+
46
+ def callback_phase
47
+ if request.params['dr_auth_status'] == 'ok' && request.params['dr_auth_code']
48
+ response = RestClient.get('http://api.draugiem.lv/json/', { :params => draugiem_authorize_params(request.params['dr_auth_code']) })
49
+ auth = MultiJson.decode(response.to_s)
50
+ unless auth['error']
51
+ @auth_data = auth
52
+ super
53
+ else
54
+ fail!(auth['error']['code'].to_s,auth["error"]["description"].to_s)
55
+ end
56
+ else
57
+ fail!(:invalid_request)
58
+ end
59
+ rescue Exception => e
60
+ fail!(:invalid_response, e)
61
+ end
62
+
63
+ def auth_hash
64
+ OmniAuth::Utils.deep_merge(super, {
65
+ 'uid' => @auth_data['uid'],
66
+ 'user_info' => get_user_info,
67
+ 'credentials' => {
68
+ 'apikey' => @auth_data['apikey']
69
+ },
70
+ 'extra' => { 'user_hash' => @auth_data }
71
+ })
72
+ end
73
+
74
+ private
75
+
76
+ def get_user_info
77
+ if @auth_data['users'] && @auth_data['users'][@auth_data['uid']]
78
+ user = @auth_data['users'][@auth_data['uid']]
79
+ {
80
+ 'name' => "#{user['name']} #{user['surname']}",
81
+ 'nickname' => user['nick'],
82
+ 'first_name' => user['name'],
83
+ 'last_name' => user['surname'],
84
+ 'location' => user['place'],
85
+ 'age' => user['age'] =~ /^0-9$/ ? user['age'] : nil,
86
+ 'adult' => user['adult'] == '1' ? true : false,
87
+ 'image' => user['img'],
88
+ 'sex' => user['sex']
89
+ }
90
+ else
91
+ {}
92
+ end
93
+ end
94
+
95
+ def draugiem_authorize_params code
96
+ {
97
+ :action => 'authorize',
98
+ :app => @api_key,
99
+ :code => code
100
+ }
101
+ end
102
+ end
103
+ end
104
+ end
@@ -0,0 +1,93 @@
1
+ require 'omniauth/core'
2
+ require 'openssl'
3
+
4
+ module OmniAuth
5
+ module Strategies
6
+ class Ign
7
+ include OmniAuth::Strategy
8
+ IDENTIFIER_URL_PARAMETER = ""
9
+
10
+ class CallbackError < StandardError
11
+ attr_accessor :error, :error_reason
12
+ def initialize(error, error_reason)
13
+ self.error = error
14
+ self.error_reason = error_reason
15
+ end
16
+ end
17
+
18
+ def initialize(app, api_key, hostname=nil, options = {})
19
+ options[:name] ||= "ign"
20
+ super(app, :ign)
21
+ @api_key = api_key
22
+ @hostname = hostname
23
+ end
24
+
25
+ protected
26
+
27
+ def request_phase
28
+ OmniAuth::Form.build(:title => 'IGN Authentication', :header_info=>js) do
29
+ label_field('Identifying you with the IGN server', IDENTIFIER_URL_PARAMETER)
30
+ end.to_response
31
+ end
32
+
33
+ def callback_phase
34
+ signature = OpenSSL::HMAC.hexdigest('sha1', @api_key, ("#{request.params["username"]}::#{request.params["timestamp"]}"))
35
+
36
+ raise CallbackError.new("Invalid Signature","The supplied and calculated signature did not match, user not approved.") if signature != request.params["signature"]
37
+
38
+ super
39
+ rescue CallbackError => e
40
+ fail!(:invalid_response, e)
41
+ end
42
+
43
+ def auth_hash
44
+ OmniAuth::Utils.deep_merge(super, {
45
+ 'uid' => "ign-" + request.params["username"],
46
+ 'credentials' => { 'token' => request.params["signature"] },
47
+ 'user_info' => user_info,
48
+ 'extra' => { 'user_hash' => request.params }
49
+ })
50
+ end
51
+
52
+ def user_info
53
+ {
54
+ 'nickname' => request.params["username"],
55
+ }
56
+ end
57
+
58
+ def js
59
+ @js = <<-JS
60
+ $(document).ready(function() {
61
+ $.ajax({
62
+ url: "http://#{@hostname}/users/current.json?callback=z33k",
63
+ type: "get",
64
+ dataType:"jsonp",
65
+ success: function(data) {
66
+ if(typeof data.error == 'undefined'){
67
+ // There is a current My IGN user
68
+ var username = data.my_ign_username;
69
+ var signature = data.signature;
70
+ var timestamp = data.timestamp;
71
+ window.location = "/auth/ign/callback?username=" +username+"&signature="+signature+"&timestamp=" + timestamp;
72
+ }
73
+ else{
74
+ nouser();
75
+ }
76
+ }
77
+ });
78
+ return false;
79
+ });
80
+ function nouser() {
81
+ var url = "http://my.ign.com/login?r="+window.location;
82
+ top.location = url;
83
+ window.location = url;
84
+ }
85
+ JS
86
+ "\n<script src='https://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js' type='text/javascript'></script>" +
87
+ "\n<script type='text/javascript'>#{@js}</script>" +
88
+ "\n<style type='text/css'>button {visibility:hidden;}</style>"
89
+ end
90
+
91
+ end
92
+ end
93
+ end
@@ -8,7 +8,7 @@ module OmniAuth
8
8
  class Yupoo
9
9
  include OmniAuth::Strategy
10
10
  attr_accessor :api_key, :secret_key, :options
11
-
11
+
12
12
 
13
13
  class CallbackError < StandardError
14
14
  attr_accessor :error, :error_reason
@@ -26,30 +26,30 @@ module OmniAuth
26
26
  end
27
27
 
28
28
  protected
29
-
29
+
30
30
  def request_phase
31
31
  params = { :api_key => api_key, :perms => options[:scope] }
32
32
  params[:api_sig] = yupoo_sign(params)
33
33
  query_string = params.collect{ |key,value| "#{key}=#{Rack::Utils.escape(value)}" }.join('&')
34
34
  redirect "http://www.yupoo.com/services/auth/?#{query_string}"
35
35
  end
36
-
36
+
37
37
  def callback_phase
38
38
  params = { :api_key => api_key, :method => 'yupoo.auth.getToken', :frob => request.params['frob'], :format => 'json', :nojsoncallback => '1' }
39
39
  params[:api_sig] = yupoo_sign(params)
40
-
40
+
41
41
  response = RestClient.get('http://www.yupoo.com/api/rest/', { :params => params })
42
42
  auth = MultiJson.decode(response.to_s)
43
43
  raise CallbackError.new(auth['code'],auth['message']) if auth['stat'] == 'fail'
44
-
44
+
45
45
  @user = auth['auth']['user']
46
46
  @access_token = auth['auth']['token']['_content']
47
-
47
+
48
48
  super
49
49
  rescue CallbackError => e
50
50
  fail!(:invalid_response, e)
51
51
  end
52
-
52
+
53
53
  def auth_hash
54
54
  OmniAuth::Utils.deep_merge(super, {
55
55
  'uid' => @user['nsid'],
@@ -58,7 +58,7 @@ module OmniAuth
58
58
  'extra' => { 'user_hash' => @user }
59
59
  })
60
60
  end
61
-
61
+
62
62
  def yupoo_sign(params)
63
63
  Digest::MD5.hexdigest(secret_key + params.sort{|a,b| a[0].to_s <=> b[0].to_s }.flatten.join)
64
64
  end
@@ -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
@@ -2,7 +2,6 @@
2
2
  require File.expand_path('../lib/omniauth/version', __FILE__)
3
3
 
4
4
  Gem::Specification.new do |gem|
5
- gem.add_runtime_dependency 'jruby-openssl', '~> 0.7.3' if RUBY_PLATFORM == 'java'
6
5
  gem.add_runtime_dependency 'multi_json', '~> 1.0.0'
7
6
  gem.add_runtime_dependency 'oa-core', OmniAuth::Version::STRING
8
7
  gem.add_runtime_dependency 'rest-client', '~> 1.6.0'
@@ -13,7 +12,7 @@ Gem::Specification.new do |gem|
13
12
  gem.add_development_dependency 'rspec', '~> 2.5'
14
13
  gem.add_development_dependency 'simplecov', '~> 0.4'
15
14
  gem.add_development_dependency 'webmock', '~> 1.6'
16
- gem.add_development_dependency 'yard', '~> 0.6'
15
+ gem.add_development_dependency 'yard', '~> 0.7'
17
16
  gem.add_development_dependency 'ZenTest', '~> 4.5'
18
17
  gem.name = 'oa-more'
19
18
  gem.version = OmniAuth::Version::STRING
@@ -0,0 +1,51 @@
1
+ require File.expand_path('../../../spec_helper', __FILE__)
2
+
3
+ describe 'OmniAuth::Strategies::Draugiem', :type => :strategy do
4
+
5
+ include OmniAuth::Test::StrategyTestCase
6
+
7
+ def strategy
8
+ [OmniAuth::Strategies::Draugiem, '123', "abc"]
9
+ end
10
+
11
+ it 'should initialize with api key and app id' do
12
+ lambda{OmniAuth::Strategies::Draugiem.new({},'123','abc')}.should_not raise_error
13
+ end
14
+
15
+ describe '/auth/draugiem' do
16
+
17
+ it 'should redirect to api.draugiem.lv' do
18
+ get '/auth/draugiem'
19
+ last_response.should be_redirect
20
+ last_response.headers['Location'].should match %r{http://api\.draugiem\.lv/authorize/}
21
+ end
22
+
23
+ it 'should gather user data after success authorization' do
24
+ stub_request(:get, "http://api.draugiem.lv/json/?action=authorize&app=abc&code=123456").
25
+ to_return(:body => MultiJson.encode({
26
+ 'apikey'=>"123456789",
27
+ 'uid'=>"100",
28
+ 'language'=>"lv",
29
+ 'users'=>{
30
+ '100'=>{
31
+ 'uid'=>"100",
32
+ 'name'=>"John",
33
+ 'surname'=>"Lenon",
34
+ 'nick'=>"johnybravo",
35
+ 'place'=>"Durbe",
36
+ 'age'=>"false",
37
+ 'adult'=>"1",
38
+ 'img'=>"http://4.bp.blogspot.com/_ZmXOoYjxXog/Sg2jby1RFSI/AAAAAAAAE_Q/1LpfjimAz50/s400/JohnnyBravo3.gif",
39
+ 'sex'=>"M"
40
+ }
41
+ }
42
+ }))
43
+ get '/auth/draugiem/callback?dr_auth_status=ok&dr_auth_code=123456'
44
+
45
+ last_request.env['omniauth.auth']['credentials']['apikey'].should == "123456789"
46
+ last_request.env['omniauth.auth']['user_info']['location'].should == "Durbe"
47
+ last_request.env['omniauth.auth']['user_info']['age'].should be_nil
48
+ last_request.env['omniauth.auth']['user_info']['adult'].should be_true
49
+ end
50
+ end
51
+ end
@@ -5,7 +5,7 @@ require 'rack/test'
5
5
  require 'webmock/rspec'
6
6
  require 'omniauth/more'
7
7
 
8
- Rspec.configure do |config|
8
+ RSpec.configure do |config|
9
9
  config.include Rack::Test::Methods
10
10
  config.include WebMock::API
11
11
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: oa-more
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.2.5
5
+ version: 0.2.6
6
6
  platform: ruby
7
7
  authors:
8
8
  - Michael Bleigh
@@ -11,7 +11,7 @@ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
13
 
14
- date: 2011-04-29 00:00:00 Z
14
+ date: 2011-05-20 00:00:00 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: multi_json
@@ -32,7 +32,7 @@ dependencies:
32
32
  requirements:
33
33
  - - "="
34
34
  - !ruby/object:Gem::Version
35
- version: 0.2.5
35
+ version: 0.2.6
36
36
  type: :runtime
37
37
  version_requirements: *id002
38
38
  - !ruby/object:Gem::Dependency
@@ -131,7 +131,7 @@ dependencies:
131
131
  requirements:
132
132
  - - ~>
133
133
  - !ruby/object:Gem::Version
134
- version: "0.6"
134
+ version: "0.7"
135
135
  type: :development
136
136
  version_requirements: *id011
137
137
  - !ruby/object:Gem::Dependency
@@ -157,17 +157,21 @@ files:
157
157
  - .gemtest
158
158
  - .rspec
159
159
  - .yardopts
160
+ - Gemfile
160
161
  - LICENSE
161
162
  - README.rdoc
162
163
  - Rakefile
163
164
  - lib/oa-more.rb
164
165
  - lib/omniauth/more.rb
166
+ - lib/omniauth/strategies/draugiem.rb
165
167
  - lib/omniauth/strategies/flickr.rb
168
+ - lib/omniauth/strategies/ign.rb
166
169
  - lib/omniauth/strategies/windows_live.rb
167
170
  - lib/omniauth/strategies/windows_live/windowslivelogin.rb
168
171
  - lib/omniauth/strategies/yupoo.rb
169
172
  - lib/omniauth/version.rb
170
173
  - oa-more.gemspec
174
+ - spec/omniauth/strategies/draugiem_spec.rb
171
175
  - spec/omniauth/strategies/flickr_spec.rb
172
176
  - spec/spec_helper.rb
173
177
  homepage: http://github.com/intridea/omniauth
@@ -193,11 +197,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
193
197
  requirements: []
194
198
 
195
199
  rubyforge_project:
196
- rubygems_version: 1.7.2
200
+ rubygems_version: 1.8.2
197
201
  signing_key:
198
202
  specification_version: 3
199
203
  summary: Additional strategies for OmniAuth.
200
204
  test_files:
205
+ - spec/omniauth/strategies/draugiem_spec.rb
201
206
  - spec/omniauth/strategies/flickr_spec.rb
202
207
  - spec/spec_helper.rb
203
- has_rdoc: