oa-more 0.2.6 → 0.3.0.rc3

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,5 +1,9 @@
1
+ require File.expand_path('../lib/omniauth/version', __FILE__)
2
+
1
3
  source 'http://rubygems.org'
2
4
 
5
+ gem 'oa-core', OmniAuth::Version::STRING, :path => '../oa-core'
6
+
3
7
  platforms :jruby do
4
8
  gem 'jruby-openssl', '~> 0.7'
5
9
  end
data/lib/omniauth/more.rb CHANGED
@@ -2,10 +2,10 @@ require 'omniauth/core'
2
2
 
3
3
  module OmniAuth
4
4
  module Strategies
5
+ autoload :Draugiem, 'omniauth/strategies/draugiem'
6
+ autoload :Ign, 'omniauth/strategies/ign'
7
+ autoload :LastFm, 'omniauth/strategies/last_fm'
5
8
  autoload :WindowsLive, 'omniauth/strategies/windows_live'
6
- autoload :Flickr, 'omniauth/strategies/flickr'
7
- autoload :Yupoo, 'omniauth/strategies/yupoo'
8
- autoload :Ign, 'omniauth/strategies/ign'
9
- autoload :Draugiem, 'omniauth/strategies/draugiem'
9
+ autoload :Yupoo, 'omniauth/strategies/yupoo'
10
10
  end
11
11
  end
@@ -0,0 +1,93 @@
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 LastFM
10
+ #
11
+ # @example Basic Usage
12
+ #
13
+ # use OmniAuth::Strategies::LastFm, 'API Key', 'Secret Key'
14
+ class LastFm
15
+ include OmniAuth::Strategy
16
+ attr_accessor :api_key, :secret_key, :options
17
+
18
+ # error catching, based on OAuth2 callback
19
+ class CallbackError < StandardError
20
+ attr_accessor :error, :error_reason
21
+ def initialize(error, error_reason)
22
+ self.error = error
23
+ self.error_reason = error_reason
24
+ end
25
+ end
26
+
27
+ # @param [Rack Application] app standard middleware application parameter
28
+ # @param [String] api_key the application id as [registered on LastFM](http://www.last.fm/api/account)
29
+ # @param [String] secret_key the application secret as [registered on LastFM](http://www.last.fm/api/account)
30
+ # @option options, You can optionally specify a callback URL that is different to your API Account callback url. Include this as a query param cb
31
+ def initialize(app, api_key, secret_key, options = {})
32
+ super(app, :last_fm)
33
+ @api_key = api_key
34
+ @secret_key = secret_key
35
+ @options = options
36
+ end
37
+
38
+ protected
39
+
40
+ def request_phase
41
+ params = { :api_key => api_key, :cb => options[:cb] }
42
+ query_string = params.collect{ |key,value| "#{key}=#{Rack::Utils.escape(value)}" }.join('&')
43
+ redirect "http://www.last.fm/api/auth/?#{query_string}"
44
+ end
45
+
46
+ def callback_phase
47
+ token = request.params['token']
48
+ params = { :api_key => api_key, :method => 'auth.getSession', :format => 'json' }
49
+ params[:token] = token
50
+ params[:api_sig] = signature(token)
51
+
52
+ response = RestClient.get('http://ws.audioscrobbler.com/2.0/', { :params => params })
53
+ @auth = MultiJson.decode(response.to_s)
54
+ raise CallbackError.new(@auth['error'],@auth['message']) if @auth['error']
55
+
56
+ user_params = { :method => "user.getInfo", :user => @auth['session']['name'], :api_key => api_key, :format => "json" }
57
+ user_response = RestClient.get('http://ws.audioscrobbler.com/2.0/', { :params => user_params })
58
+ @user_auth = MultiJson.decode(user_response.to_s)
59
+ raise CallbackError.new(@user_auth['error'],@user_auth['message']) if @user_auth['error']
60
+
61
+ super
62
+ rescue CallbackError => e
63
+ fail!(:invalid_response, e)
64
+ end
65
+
66
+ def auth_hash
67
+ OmniAuth::Utils.deep_merge(super, {
68
+ 'uid' => @user_auth['user']['id'],
69
+ 'credentials' => { 'token' => @auth['session']['key'] },
70
+ 'user_info' => user_info,
71
+ 'extra' => { 'user_hash' => @user_auth }
72
+ })
73
+ end
74
+
75
+ def user_info
76
+ {
77
+ 'name' => @user_auth['user']['realname'],
78
+ 'nickname' => @user_auth['user']['name'],
79
+ 'location' => @user_auth['user']['country'],
80
+ 'image' => @user_auth['user']['image'],
81
+ 'urls' => {
82
+ 'Profile' => @user_auth['user']['url']
83
+ }
84
+ }
85
+ end
86
+
87
+ def signature(token)
88
+ sign = "api_key#{api_key}methodauth.getSessiontoken#{token}#{secret_key}"
89
+ Digest::MD5.hexdigest(sign)
90
+ end
91
+ end
92
+ end
93
+ end
@@ -4,13 +4,13 @@ module OmniAuth
4
4
  MAJOR = 0
5
5
  end
6
6
  unless defined?(::OmniAuth::Version::MINOR)
7
- MINOR = 2
7
+ MINOR = 3
8
8
  end
9
9
  unless defined?(::OmniAuth::Version::PATCH)
10
- PATCH = 6
10
+ PATCH = 0
11
11
  end
12
12
  unless defined?(::OmniAuth::Version::PRE)
13
- PRE = nil
13
+ PRE = "rc3"
14
14
  end
15
15
  unless defined?(::OmniAuth::Version::STRING)
16
16
  STRING = [MAJOR, MINOR, PATCH, PRE].compact.join('.')
data/oa-more.gemspec CHANGED
@@ -1,29 +1,27 @@
1
- # -*- encoding: utf-8 -*-
1
+ # encoding: utf-8
2
2
  require File.expand_path('../lib/omniauth/version', __FILE__)
3
3
 
4
4
  Gem::Specification.new do |gem|
5
- gem.add_runtime_dependency 'multi_json', '~> 1.0.0'
6
- gem.add_runtime_dependency 'oa-core', OmniAuth::Version::STRING
7
- gem.add_runtime_dependency 'rest-client', '~> 1.6.0'
5
+ gem.add_dependency 'multi_json', '~> 1.0.0'
6
+ gem.add_dependency 'oa-core', OmniAuth::Version::STRING
7
+ gem.add_dependency 'rest-client', '~> 1.6.0'
8
8
  gem.add_development_dependency 'json_pure', '~> 1.5'
9
- gem.add_development_dependency 'maruku', '~> 0.6'
10
- gem.add_development_dependency 'rake', '~> 0.8'
11
9
  gem.add_development_dependency 'rack-test', '~> 0.5'
10
+ gem.add_development_dependency 'rake', '~> 0.8'
11
+ gem.add_development_dependency 'rdiscount', '~> 1.6'
12
12
  gem.add_development_dependency 'rspec', '~> 2.5'
13
13
  gem.add_development_dependency 'simplecov', '~> 0.4'
14
- gem.add_development_dependency 'webmock', '~> 1.6'
14
+ gem.add_development_dependency 'webmock', '~> 1.7'
15
15
  gem.add_development_dependency 'yard', '~> 0.7'
16
- gem.add_development_dependency 'ZenTest', '~> 4.5'
17
- gem.name = 'oa-more'
18
- gem.version = OmniAuth::Version::STRING
16
+ gem.authors = ['Michael Bleigh', 'Erik Michaels-Ober']
19
17
  gem.description = %q{Additional strategies for OmniAuth.}
20
- gem.summary = gem.description
21
18
  gem.email = 'michael@intridea.com'
22
- gem.homepage = 'http://github.com/intridea/omniauth'
23
- gem.authors = ['Michael Bleigh', 'Erik Michaels-Ober']
24
- gem.executables = `git ls-files -- bin/*`.split("\n").map{|f| File.basename(f)}
25
19
  gem.files = `git ls-files`.split("\n")
26
- gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
20
+ gem.homepage = 'http://github.com/intridea/omniauth'
21
+ gem.name = 'oa-more'
27
22
  gem.require_paths = ['lib']
28
23
  gem.required_rubygems_version = Gem::Requirement.new('>= 1.3.6') if gem.respond_to? :required_rubygems_version=
24
+ gem.summary = gem.description
25
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
26
+ gem.version = OmniAuth::Version::STRING
29
27
  end
@@ -1,7 +1,7 @@
1
1
  require File.expand_path('../../../spec_helper', __FILE__)
2
2
 
3
- describe 'OmniAuth::Strategies::Flickr' do
3
+ describe 'OmniAuth::Strategies::LastFm' do
4
4
  it 'should initialize with a consumer key and secret' do
5
- lambda{OmniAuth::Strategies::Flickr.new({},'abc','def')}.should_not raise_error
5
+ lambda{OmniAuth::Strategies::LastFm.new({},'abc','def')}.should_not raise_error
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,8 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oa-more
3
3
  version: !ruby/object:Gem::Version
4
- prerelease:
5
- version: 0.2.6
4
+ hash: 15424035
5
+ prerelease: 6
6
+ segments:
7
+ - 0
8
+ - 3
9
+ - 0
10
+ - rc
11
+ - 3
12
+ version: 0.3.0.rc3
6
13
  platform: ruby
7
14
  authors:
8
15
  - Michael Bleigh
@@ -11,7 +18,7 @@ autorequire:
11
18
  bindir: bin
12
19
  cert_chain: []
13
20
 
14
- date: 2011-05-20 00:00:00 Z
21
+ date: 2011-09-03 00:00:00 Z
15
22
  dependencies:
16
23
  - !ruby/object:Gem::Dependency
17
24
  name: multi_json
@@ -21,6 +28,11 @@ dependencies:
21
28
  requirements:
22
29
  - - ~>
23
30
  - !ruby/object:Gem::Version
31
+ hash: 23
32
+ segments:
33
+ - 1
34
+ - 0
35
+ - 0
24
36
  version: 1.0.0
25
37
  type: :runtime
26
38
  version_requirements: *id001
@@ -32,7 +44,14 @@ dependencies:
32
44
  requirements:
33
45
  - - "="
34
46
  - !ruby/object:Gem::Version
35
- version: 0.2.6
47
+ hash: 15424035
48
+ segments:
49
+ - 0
50
+ - 3
51
+ - 0
52
+ - rc
53
+ - 3
54
+ version: 0.3.0.rc3
36
55
  type: :runtime
37
56
  version_requirements: *id002
38
57
  - !ruby/object:Gem::Dependency
@@ -43,6 +62,11 @@ dependencies:
43
62
  requirements:
44
63
  - - ~>
45
64
  - !ruby/object:Gem::Version
65
+ hash: 15
66
+ segments:
67
+ - 1
68
+ - 6
69
+ - 0
46
70
  version: 1.6.0
47
71
  type: :runtime
48
72
  version_requirements: *id003
@@ -54,18 +78,26 @@ dependencies:
54
78
  requirements:
55
79
  - - ~>
56
80
  - !ruby/object:Gem::Version
81
+ hash: 5
82
+ segments:
83
+ - 1
84
+ - 5
57
85
  version: "1.5"
58
86
  type: :development
59
87
  version_requirements: *id004
60
88
  - !ruby/object:Gem::Dependency
61
- name: maruku
89
+ name: rack-test
62
90
  prerelease: false
63
91
  requirement: &id005 !ruby/object:Gem::Requirement
64
92
  none: false
65
93
  requirements:
66
94
  - - ~>
67
95
  - !ruby/object:Gem::Version
68
- version: "0.6"
96
+ hash: 1
97
+ segments:
98
+ - 0
99
+ - 5
100
+ version: "0.5"
69
101
  type: :development
70
102
  version_requirements: *id005
71
103
  - !ruby/object:Gem::Dependency
@@ -76,18 +108,26 @@ dependencies:
76
108
  requirements:
77
109
  - - ~>
78
110
  - !ruby/object:Gem::Version
111
+ hash: 27
112
+ segments:
113
+ - 0
114
+ - 8
79
115
  version: "0.8"
80
116
  type: :development
81
117
  version_requirements: *id006
82
118
  - !ruby/object:Gem::Dependency
83
- name: rack-test
119
+ name: rdiscount
84
120
  prerelease: false
85
121
  requirement: &id007 !ruby/object:Gem::Requirement
86
122
  none: false
87
123
  requirements:
88
124
  - - ~>
89
125
  - !ruby/object:Gem::Version
90
- version: "0.5"
126
+ hash: 3
127
+ segments:
128
+ - 1
129
+ - 6
130
+ version: "1.6"
91
131
  type: :development
92
132
  version_requirements: *id007
93
133
  - !ruby/object:Gem::Dependency
@@ -98,6 +138,10 @@ dependencies:
98
138
  requirements:
99
139
  - - ~>
100
140
  - !ruby/object:Gem::Version
141
+ hash: 9
142
+ segments:
143
+ - 2
144
+ - 5
101
145
  version: "2.5"
102
146
  type: :development
103
147
  version_requirements: *id008
@@ -109,6 +153,10 @@ dependencies:
109
153
  requirements:
110
154
  - - ~>
111
155
  - !ruby/object:Gem::Version
156
+ hash: 3
157
+ segments:
158
+ - 0
159
+ - 4
112
160
  version: "0.4"
113
161
  type: :development
114
162
  version_requirements: *id009
@@ -120,7 +168,11 @@ dependencies:
120
168
  requirements:
121
169
  - - ~>
122
170
  - !ruby/object:Gem::Version
123
- version: "1.6"
171
+ hash: 1
172
+ segments:
173
+ - 1
174
+ - 7
175
+ version: "1.7"
124
176
  type: :development
125
177
  version_requirements: *id010
126
178
  - !ruby/object:Gem::Dependency
@@ -131,20 +183,13 @@ dependencies:
131
183
  requirements:
132
184
  - - ~>
133
185
  - !ruby/object:Gem::Version
186
+ hash: 5
187
+ segments:
188
+ - 0
189
+ - 7
134
190
  version: "0.7"
135
191
  type: :development
136
192
  version_requirements: *id011
137
- - !ruby/object:Gem::Dependency
138
- name: ZenTest
139
- prerelease: false
140
- requirement: &id012 !ruby/object:Gem::Requirement
141
- none: false
142
- requirements:
143
- - - ~>
144
- - !ruby/object:Gem::Version
145
- version: "4.5"
146
- type: :development
147
- version_requirements: *id012
148
193
  description: Additional strategies for OmniAuth.
149
194
  email: michael@intridea.com
150
195
  executables: []
@@ -164,15 +209,15 @@ files:
164
209
  - lib/oa-more.rb
165
210
  - lib/omniauth/more.rb
166
211
  - lib/omniauth/strategies/draugiem.rb
167
- - lib/omniauth/strategies/flickr.rb
168
212
  - lib/omniauth/strategies/ign.rb
213
+ - lib/omniauth/strategies/last_fm.rb
169
214
  - lib/omniauth/strategies/windows_live.rb
170
215
  - lib/omniauth/strategies/windows_live/windowslivelogin.rb
171
216
  - lib/omniauth/strategies/yupoo.rb
172
217
  - lib/omniauth/version.rb
173
218
  - oa-more.gemspec
174
219
  - spec/omniauth/strategies/draugiem_spec.rb
175
- - spec/omniauth/strategies/flickr_spec.rb
220
+ - spec/omniauth/strategies/last_fm_spec.rb
176
221
  - spec/spec_helper.rb
177
222
  homepage: http://github.com/intridea/omniauth
178
223
  licenses: []
@@ -187,21 +232,29 @@ required_ruby_version: !ruby/object:Gem::Requirement
187
232
  requirements:
188
233
  - - ">="
189
234
  - !ruby/object:Gem::Version
235
+ hash: 3
236
+ segments:
237
+ - 0
190
238
  version: "0"
191
239
  required_rubygems_version: !ruby/object:Gem::Requirement
192
240
  none: false
193
241
  requirements:
194
- - - ">="
242
+ - - ">"
195
243
  - !ruby/object:Gem::Version
196
- version: 1.3.6
244
+ hash: 25
245
+ segments:
246
+ - 1
247
+ - 3
248
+ - 1
249
+ version: 1.3.1
197
250
  requirements: []
198
251
 
199
252
  rubyforge_project:
200
- rubygems_version: 1.8.2
253
+ rubygems_version: 1.8.10
201
254
  signing_key:
202
255
  specification_version: 3
203
256
  summary: Additional strategies for OmniAuth.
204
257
  test_files:
205
258
  - spec/omniauth/strategies/draugiem_spec.rb
206
- - spec/omniauth/strategies/flickr_spec.rb
259
+ - spec/omniauth/strategies/last_fm_spec.rb
207
260
  - spec/spec_helper.rb
@@ -1,86 +0,0 @@
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 Flickr
10
- #
11
- # @example Basic Usage
12
- #
13
- # use OmniAuth::Strategies::Flickr, 'API Key', 'Secret Key', :scope => 'read'
14
- class Flickr
15
- include OmniAuth::Strategy
16
- attr_accessor :api_key, :secret_key, :options
17
-
18
- # error catching, based on OAuth2 callback
19
- class CallbackError < StandardError
20
- attr_accessor :error, :error_reason
21
- def initialize(error, error_reason)
22
- self.error = error
23
- self.error_reason = error_reason
24
- end
25
- end
26
-
27
- # @param [Rack Application] app standard middleware application parameter
28
- # @param [String] api_key the application id as [registered on Flickr](http://www.flickr.com/services/apps/)
29
- # @param [String] secret_key the application secret as [registered on Flickr](http://www.flickr.com/services/apps/)
30
- # @option options ['read','write','delete] :scope ('read') the scope of your authorization request; must be `read` or 'write' or 'delete'
31
- def initialize(app, api_key, secret_key, options = {})
32
- super(app, :flickr)
33
- @api_key = api_key
34
- @secret_key = secret_key
35
- @options = {:scope => 'read'}.merge(options)
36
- end
37
-
38
- protected
39
-
40
- def request_phase
41
- params = { :api_key => api_key, :perms => options[:scope] }
42
- params[:api_sig] = flickr_sign(params)
43
- query_string = params.collect{ |key,value| "#{key}=#{Rack::Utils.escape(value)}" }.join('&')
44
- redirect "http://flickr.com/services/auth/?#{query_string}"
45
- end
46
-
47
- def callback_phase
48
- params = { :api_key => api_key, :method => 'flickr.auth.getToken', :frob => request.params['frob'], :format => 'json', :nojsoncallback => '1' }
49
- params[:api_sig] = flickr_sign(params)
50
-
51
- response = RestClient.get('http://api.flickr.com/services/rest/', { :params => params })
52
- auth = MultiJson.decode(response.to_s)
53
- raise CallbackError.new(auth['code'],auth['message']) if auth['stat'] == 'fail'
54
-
55
- @user = auth['auth']['user']
56
- @access_token = auth['auth']['token']['_content']
57
-
58
- super
59
- rescue CallbackError => e
60
- fail!(:invalid_response, e)
61
- end
62
-
63
- def auth_hash
64
- OmniAuth::Utils.deep_merge(super, {
65
- 'uid' => @user['nsid'],
66
- 'credentials' => { 'token' => @access_token },
67
- 'user_info' => user_info,
68
- 'extra' => { 'user_hash' => @user }
69
- })
70
- end
71
-
72
- def user_info
73
- name = @user['fullname']
74
- name = @user['username'] if name.nil? || name.empty?
75
- {
76
- 'nickname' => @user['username'],
77
- 'name' => name,
78
- }
79
- end
80
-
81
- def flickr_sign(params)
82
- Digest::MD5.hexdigest(secret_key + params.sort{|a,b| a[0].to_s <=> b[0].to_s }.flatten.join)
83
- end
84
- end
85
- end
86
- end