oa-oauth 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -11,5 +11,6 @@ module OmniAuth
11
11
  autoload :GitHub, 'omniauth/strategies/github'
12
12
  autoload :ThirtySevenSignals, 'omniauth/strategies/thirty_seven_signals'
13
13
  autoload :Foursquare, 'omniauth/strategies/foursquare'
14
+ autoload :Gowalla, 'omniauth/strategies/gowalla'
14
15
  end
15
16
  end
@@ -0,0 +1,60 @@
1
+ require 'omniauth/oauth'
2
+ require 'multi_json'
3
+
4
+ module OmniAuth
5
+ module Strategies
6
+ #
7
+ # Authenticate to Gowalla utilizing OAuth 2.0 and retrieve
8
+ # basic user information.
9
+ #
10
+ # Usage:
11
+ #
12
+ # use OmniAuth::Strategies::Gowalla, 'API Key', 'Secret Key'
13
+ #
14
+ # Options:
15
+ #
16
+ # <tt>:scope</tt> :: Extended permissions such as <tt>email</tt> and <tt>offline_access</tt> (which are the defaults).
17
+ class Gowalla < OAuth2
18
+ def initialize(app, api_key, secret_key, options = {})
19
+ options[:site] = 'https://api.gowalla.com/api/oauth'
20
+ options[:authorize_url] = 'https://gowalla.com/api/oauth/new'
21
+ options[:access_token_url] = 'https://api.gowalla.com/api/oauth/token'
22
+ super(app, :gowalla, api_key, secret_key, options)
23
+ end
24
+
25
+ def user_data
26
+ @data ||= MultiJson.decode(@access_token.get("/users/me.json"))
27
+ end
28
+
29
+ def request_phase(options = {})
30
+ options[:scope] ||= "email,offline_access"
31
+ super(options)
32
+ end
33
+
34
+ def user_info
35
+ {
36
+ 'name' => "#{user_data['first_name']} #{user_data['last_name']}",
37
+ 'nickname' => user_data["username"],
38
+ 'first_name' => user_data["first_name"],
39
+ 'last_name' => user_data["last_name"],
40
+ 'location' => user_data["hometown"],
41
+ 'description' => user_data["bio"],
42
+ 'image' => user_data["image_url"],
43
+ 'phone' => nil,
44
+ 'urls' => {
45
+ 'Gowalla' => "http://www.gowalla.com#{user_data['url']}",
46
+ 'Website' => user_data["website"]
47
+ }
48
+ }
49
+ end
50
+
51
+ def auth_hash
52
+ OmniAuth::Utils.deep_merge(super, {
53
+ 'uid' => user_data["url"].split('/').last,
54
+ 'user_info' => user_info,
55
+ 'extra' => {'user_hash' => user_data}
56
+ })
57
+ end
58
+ end
59
+ end
60
+ end
@@ -24,8 +24,8 @@ module OmniAuth
24
24
  request_token = ::OAuth::RequestToken.new(consumer, session[:oauth][name.to_sym].delete(:request_token), session[:oauth][name.to_sym].delete(:request_secret))
25
25
  @access_token = request_token.get_access_token(:oauth_verifier => request.params['oauth_verifier'])
26
26
  super
27
- rescue ::OAuth::Unauthorized
28
- fail!(:invalid_credentials)
27
+ rescue ::OAuth::Unauthorized => e
28
+ fail!(:invalid_credentials, e)
29
29
  end
30
30
 
31
31
  def auth_hash
@@ -26,8 +26,8 @@ module OmniAuth
26
26
  verifier = request.params['code']
27
27
  @access_token = client.web_server.get_access_token(verifier, :redirect_uri => callback_url)
28
28
  super
29
- rescue ::OAuth2::HTTPError => e
30
- fail!(:invalid_credentials)
29
+ rescue ::OAuth2::HTTPError, ::OAuth2::AccessDenied => e
30
+ fail!(:invalid_credentials, e)
31
31
  end
32
32
 
33
33
  def auth_hash
@@ -14,7 +14,8 @@ module OmniAuth
14
14
  class Twitter < OmniAuth::Strategies::OAuth
15
15
  def initialize(app, consumer_key, consumer_secret)
16
16
  super(app, :twitter, consumer_key, consumer_secret,
17
- :site => 'https://api.twitter.com')
17
+ :site => 'https://api.twitter.com',
18
+ :authorize_path => '/oauth/authenticate')
18
19
  end
19
20
 
20
21
  def auth_hash
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oa-oauth
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
4
+ hash: 29
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 2
10
- version: 0.1.2
9
+ - 3
10
+ version: 0.1.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Michael Bleigh
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-10-06 00:00:00 -05:00
18
+ date: 2010-10-11 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -24,12 +24,12 @@ dependencies:
24
24
  requirements:
25
25
  - - "="
26
26
  - !ruby/object:Gem::Version
27
- hash: 31
27
+ hash: 29
28
28
  segments:
29
29
  - 0
30
30
  - 1
31
- - 2
32
- version: 0.1.2
31
+ - 3
32
+ version: 0.1.3
33
33
  requirement: *id001
34
34
  name: oa-core
35
35
  prerelease: false
@@ -205,6 +205,7 @@ files:
205
205
  - lib/omniauth/strategies/facebook.rb
206
206
  - lib/omniauth/strategies/foursquare.rb
207
207
  - lib/omniauth/strategies/github.rb
208
+ - lib/omniauth/strategies/gowalla.rb
208
209
  - lib/omniauth/strategies/linked_in.rb
209
210
  - lib/omniauth/strategies/oauth.rb
210
211
  - lib/omniauth/strategies/oauth2.rb