oauth-plugin 0.3.11 → 0.3.12

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,12 @@
1
+ 9/30/2009
2
+ - Added a simple PortableContacts adapter for GoogleToken
3
+ - Added a SimpleClient wrapper to provide really simple wrapper for OAuth based json web services
4
+ - Increased token size in consumer_tokens table because of Yahoo's oversized tokens
5
+ - Added support for Yahoo
6
+ - Added support for Google (Boon Low)
7
+ 9/26/2009
8
+ 0.3.11
9
+ - Moved twitter tokens dependency back to regular twitter gem
1
10
  7/29/2009
2
11
  0.3.10
3
12
  - Closed blocks in erb template (jcrosby) while pelle is hiding under his desk
data/README.rdoc CHANGED
@@ -330,7 +330,7 @@ Before creating the FireEagleToken model the plugin checks if a class already ex
330
330
  Currently we provide the following semi tested tokens wrappers:
331
331
 
332
332
  * FireEagle
333
- * Twitter (requires Paul Singh's version of twitter gem until main gem is updated to 0.3.5 - sudo gem install paulsingh-twitter)
333
+ * Twitter
334
334
  * Agree2
335
335
 
336
336
  These can be found in lib/oauth/models/consulers/services. Contributions will be warmly accepted for your favorite OAuth service.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.11
1
+ 0.3.12
@@ -4,7 +4,7 @@ class CreateOauthConsumerTokens < ActiveRecord::Migration
4
4
  create_table :consumer_tokens do |t|
5
5
  t.integer :user_id
6
6
  t.string :type, :limit => 30
7
- t.string :token
7
+ t.string :token, :limit => 1024 # This has to be huge because of Yahoo's excessively large tokens
8
8
  t.string :secret
9
9
  t.timestamps
10
10
  end
@@ -8,6 +8,15 @@
8
8
  # :key=>"",
9
9
  # :secret=>""
10
10
  # },
11
+ # :google=>{
12
+ # :key=>"",
13
+ # :secret=>"",
14
+ # :scope=>"" # see http://code.google.com/apis/gdata/faq.html#AuthScopes
15
+ # },
16
+ # :yahoo=>{
17
+ # :key=>"",
18
+ # :secret=>"",
19
+ # },
11
20
  # :agree2=>{
12
21
  # :key=>"",
13
22
  # :secret=>""
@@ -28,6 +28,7 @@ class ClientApplication < ActiveRecord::Base
28
28
  value = signature.verify
29
29
  value
30
30
  rescue OAuth::Signature::UnknownSignatureMethod => e
31
+ logger.info "ERROR"+e.to_s
31
32
  false
32
33
  end
33
34
  end
@@ -18,11 +18,6 @@ module OAuth
18
18
  return verified && current_token.is_a?(::AccessToken)
19
19
  end
20
20
 
21
- # Skip the authenticity filter if we have an oauth token
22
- def verify_authenticity_token
23
- super unless oauth?
24
- end
25
-
26
21
  def oauth?
27
22
  current_token!=nil
28
23
  end
@@ -74,7 +69,7 @@ module OAuth
74
69
  end
75
70
 
76
71
  def verify_oauth_request_token
77
- verify_oauth_signature && current_token.is_a?(RequestToken)
72
+ verify_oauth_signature && current_token.is_a?(::RequestToken)
78
73
  end
79
74
 
80
75
  def invalid_oauth_response(code=401,message="Invalid OAuth Request")
@@ -0,0 +1,41 @@
1
+ class GoogleToken < ConsumerToken
2
+ GOOGLE_SETTINGS={
3
+ :site=>"https://www.google.com",
4
+ :request_token_path => "/accounts/OAuthGetRequestToken",
5
+ :authorize_path => "/accounts/OAuthAuthorizeToken",
6
+ :access_token_path => "/accounts/OAuthGetAccessToken",
7
+ }
8
+
9
+ def self.consumer
10
+ @consumer||=create_consumer
11
+ end
12
+
13
+ def self.create_consumer(options={})
14
+ OAuth::Consumer.new credentials[:key],credentials[:secret],GOOGLE_SETTINGS.merge(options)
15
+ end
16
+
17
+ def self.portable_contacts_consumer
18
+ @portable_contacts_consumer||= create_consumer :site=>"http://www-opensocial.googleusercontent.com"
19
+ end
20
+
21
+
22
+ def self.get_request_token(callback_url, scope=nil)
23
+ consumer.get_request_token({:oauth_callback=>callback_url}, :scope=>scope||credentials[:scope]||"http://www-opensocial.googleusercontent.com/api/people")
24
+ end
25
+
26
+ def portable_contacts
27
+ @portable_contacts||= GooglePortableContacts.new(OAuth::AccessToken.new( self.class.portable_contacts_consumer, token, secret))
28
+ end
29
+
30
+ class GooglePortableContacts < Oauth::Models::Consumers::SimpleClient
31
+
32
+ def me
33
+ get("/api/people/@me/@self")
34
+ end
35
+
36
+ def all
37
+ get("/api/people/@me/@all")
38
+ end
39
+
40
+ end
41
+ end
@@ -1,4 +1,3 @@
1
- gem 'paulsingh-twitter' # go back to regular twitter gem when it is bumped to oauth 0.3.5
2
1
  require 'twitter'
3
2
  class TwitterToken < ConsumerToken
4
3
  TWITTER_SETTINGS={:site=>"http://twitter.com"}
@@ -0,0 +1,109 @@
1
+ class YahooToken < ConsumerToken
2
+ YAHOO_SETTINGS={
3
+ :site=>"https://www.yahoo.com",
4
+ :request_token_url => "https://api.login.yahoo.com/oauth/v2/get_request_token",
5
+ :authorize_url => "https://api.login.yahoo.com/oauth/v2/request_auth",
6
+ :access_token_url => "https://api.login.yahoo.com/oauth/v2/get_token"
7
+ }
8
+
9
+ def self.consumer
10
+ @consumer||=create_consumer
11
+ end
12
+
13
+ def self.create_consumer(options={})
14
+ OAuth::Consumer.new credentials[:key],credentials[:secret],YAHOO_SETTINGS.merge(options)
15
+ end
16
+
17
+ def self.social_apis_consumer
18
+ @social_api_consumer||=create_consumer :site=>"http://social.yahooapis.com/v1"
19
+ end
20
+
21
+ def self.get_request_token(callback_url, scope=nil)
22
+ YahooRequestToken.new consumer.get_request_token({:oauth_callback=>callback_url}, :scope=>scope||credentials[:scope])
23
+ end
24
+
25
+ # We need to do some special handling to handle this strange parameter:
26
+ #
27
+ class YahooRequestToken < OAuth::RequestToken
28
+ def initialize(real_token)
29
+ super real_token.consumer,real_token.token,real_token.secret
30
+ @params=real_token.params
31
+ end
32
+
33
+ # handle xoauth_request_auth_url
34
+ def authorize_url(params = nil)
35
+ if @params[:xoauth_request_auth_url]
36
+ return @params[:xoauth_request_auth_url]
37
+ else
38
+ super params
39
+ end
40
+ end
41
+ end
42
+
43
+ def social_api
44
+ @social_api ||= SocialAPI.new(OAuth::AccessToken.new( self.class.social_apis_consumer, token, secret))
45
+ end
46
+
47
+ class SocialAPI < Oauth::Models::Consumers::SimpleClient
48
+ # initial implementation of this
49
+ # http://developer.yahoo.com/social/rest_api_guide/index.html
50
+ # Please fork and submit improvements here
51
+ def guid
52
+ @guid||=get("/v1/me/guid")["guid"]["value"]
53
+ end
54
+
55
+ def usercard
56
+ get("/v1/user/#{guid}/profile/usercard")
57
+ end
58
+
59
+ def idcard
60
+ get("/v1/user/#{guid}/profile/idcard")
61
+ end
62
+
63
+ def tinyusercard
64
+ get("/v1/user/#{guid}/profile/tinyusercard")
65
+ end
66
+
67
+ def profile
68
+ get("/v1/user/#{guid}/profile")
69
+ end
70
+
71
+ def contacts
72
+ get("/v1/user/#{guid}/contacts")
73
+ end
74
+
75
+ end
76
+ end
77
+
78
+
79
+ # I have reported this as a bug to Yahoo, but on certain occassions their tokens are returned with spaces that confuse CGI.parse.
80
+ # The only change below is that it strips the response.body. Once Yahoo fixes this I will remove this whole section.
81
+ module OAuth
82
+ class Consumer
83
+
84
+ def token_request(http_method, path, token = nil, request_options = {}, *arguments)
85
+ response = request(http_method, path, token, request_options, *arguments)
86
+
87
+ case response.code.to_i
88
+
89
+ when (200..299)
90
+ # symbolize keys
91
+ # TODO this could be considered unexpected behavior; symbols or not?
92
+ # TODO this also drops subsequent values from multi-valued keys
93
+
94
+ CGI.parse(response.body.strip).inject({}) do |h,(k,v)|
95
+ h[k.to_sym] = v.first
96
+ h[k] = v.first
97
+ h
98
+ end
99
+ when (300..399)
100
+ # this is a redirect
101
+ response.error!
102
+ when (400..499)
103
+ raise OAuth::Unauthorized, response
104
+ else
105
+ response.error!
106
+ end
107
+ end
108
+ end
109
+ end
@@ -0,0 +1,50 @@
1
+ require 'json'
2
+ module Oauth
3
+ module Models
4
+ module Consumers
5
+ # This is just a simple
6
+ class SimpleClient
7
+ attr_reader :token
8
+
9
+ def initialize(token)
10
+ @token = token
11
+ end
12
+
13
+
14
+ def put(path,params={})
15
+ parse(token.put(path,params, {'Accept' => 'application/json'}))
16
+ end
17
+
18
+ def delete(path)
19
+ parse(token.delete(path, {'Accept' => 'application/json'}))
20
+ end
21
+
22
+ def post(path,params={})
23
+ parse(token.post(path,params, {'Accept' => 'application/json'}))
24
+ end
25
+
26
+ def get(path)
27
+ parse(token.get(path, {'Accept' => 'application/json'}))
28
+ end
29
+
30
+ protected
31
+
32
+ def parse(response)
33
+ return false unless response
34
+ if ["200","201"].include? response.code
35
+ unless response.body.blank?
36
+ JSON.parse(response.body)
37
+ else
38
+ true
39
+ end
40
+ else
41
+ logger.debug "Got Response code: #{response.code}"
42
+ false
43
+ end
44
+
45
+ end
46
+
47
+ end
48
+ end
49
+ end
50
+ end
@@ -1,4 +1,6 @@
1
1
  require 'oauth/consumer'
2
+ require File.join(File.dirname(__FILE__), 'simple_client')
3
+
2
4
  module Oauth
3
5
  module Models
4
6
  module Consumers
@@ -29,11 +31,10 @@ module Oauth
29
31
  end
30
32
 
31
33
  def create_from_request_token(user,token,secret,oauth_verifier)
32
- logger.info "create_from_request_token"
33
34
  request_token=OAuth::RequestToken.new consumer,token,secret
34
- access_token=request_token.get_access_token :oauth_verifier=>oauth_verifier
35
- logger.info self.inspect
36
- logger.info user.inspect
35
+ options={}
36
+ options[:oauth_verifier]=oauth_verifier if oauth_verifier
37
+ access_token=request_token.get_access_token options
37
38
  create :user_id=>user.id,:token=>access_token.token,:secret=>access_token.secret
38
39
  end
39
40
 
@@ -52,6 +53,10 @@ module Oauth
52
53
  def client
53
54
  @client||=OAuth::AccessToken.new self.class.consumer,token,secret
54
55
  end
56
+
57
+ def simple_client
58
+ @simple_client||=SimpleClient.new OAuth::AccessToken.new( self.class.consumer,token,secret)
59
+ end
55
60
 
56
61
  end
57
62
  end
data/oauth-plugin.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{oauth-plugin}
8
- s.version = "0.3.11"
8
+ s.version = "0.3.12"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Pelle Braendgaard"]
12
- s.date = %q{2009-09-10}
12
+ s.date = %q{2009-09-30}
13
13
  s.description = %q{Rails plugin for implementing an OAuth Provider or Consumer}
14
14
  s.email = %q{oauth-ruby@googlegroups.com}
15
15
  s.extra_rdoc_files = [
@@ -83,7 +83,10 @@ Gem::Specification.new do |s|
83
83
  "lib/oauth/models/consumers/service_loader.rb",
84
84
  "lib/oauth/models/consumers/services/agree2_token.rb",
85
85
  "lib/oauth/models/consumers/services/fireeagle_token.rb",
86
+ "lib/oauth/models/consumers/services/google_token.rb",
86
87
  "lib/oauth/models/consumers/services/twitter_token.rb",
88
+ "lib/oauth/models/consumers/services/yahoo_token.rb",
89
+ "lib/oauth/models/consumers/simple_client.rb",
87
90
  "lib/oauth/models/consumers/token.rb",
88
91
  "oauth-plugin.gemspec",
89
92
  "rails/init.rb",
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oauth-plugin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.11
4
+ version: 0.3.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pelle Braendgaard
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-09-10 00:00:00 -04:00
12
+ date: 2009-09-30 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -98,7 +98,10 @@ files:
98
98
  - lib/oauth/models/consumers/service_loader.rb
99
99
  - lib/oauth/models/consumers/services/agree2_token.rb
100
100
  - lib/oauth/models/consumers/services/fireeagle_token.rb
101
+ - lib/oauth/models/consumers/services/google_token.rb
101
102
  - lib/oauth/models/consumers/services/twitter_token.rb
103
+ - lib/oauth/models/consumers/services/yahoo_token.rb
104
+ - lib/oauth/models/consumers/simple_client.rb
102
105
  - lib/oauth/models/consumers/token.rb
103
106
  - oauth-plugin.gemspec
104
107
  - rails/init.rb