oauth-plugin 0.4.0.pre4 → 0.4.0.pre5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. data/.gitignore +2 -0
  2. data/CHANGELOG +11 -0
  3. data/Gemfile.lock +66 -0
  4. data/Guardfile +8 -0
  5. data/README.rdoc +50 -4
  6. data/generators/oauth_consumer/templates/controller.rb +8 -0
  7. data/generators/oauth_consumer/templates/oauth_config.rb +23 -1
  8. data/generators/oauth_provider/oauth_provider_generator.rb +0 -4
  9. data/generators/oauth_provider/templates/oauth2_authorize.html.erb +2 -2
  10. data/generators/oauth_provider/templates/oauth2_authorize.html.haml +1 -1
  11. data/generators/oauth_provider/templates/request_token.rb +2 -2
  12. data/lib/generators/active_record/oauth_provider_templates/request_token.rb +2 -2
  13. data/lib/generators/erb/oauth_provider_templates/oauth2_authorize.html.erb +1 -1
  14. data/lib/generators/haml/oauth_provider_templates/oauth2_authorize.html.haml +1 -1
  15. data/lib/generators/mongoid/oauth_consumer_templates/consumer_token.rb +10 -8
  16. data/lib/generators/mongoid/oauth_provider_templates/request_token.rb +2 -2
  17. data/lib/generators/oauth_consumer/oauth_consumer_generator.rb +5 -1
  18. data/lib/generators/oauth_consumer/templates/controller.rb +9 -0
  19. data/lib/generators/oauth_consumer/templates/oauth_config.rb +21 -0
  20. data/lib/generators/rspec/oauth_provider_generator.rb +0 -4
  21. data/lib/generators/test_unit/oauth_provider_generator.rb +0 -4
  22. data/lib/oauth-plugin/version.rb +1 -1
  23. data/lib/oauth/controllers/application_controller_methods.rb +24 -127
  24. data/lib/oauth/controllers/consumer_controller.rb +60 -8
  25. data/lib/oauth/controllers/provider_controller.rb +4 -7
  26. data/lib/oauth/models/consumers/service_loader.rb +3 -1
  27. data/lib/oauth/models/consumers/services/google_token.rb +7 -13
  28. data/lib/oauth/models/consumers/services/oauth2_token.rb +27 -0
  29. data/lib/oauth/models/consumers/services/twitter_token.rb +18 -11
  30. data/lib/oauth/models/consumers/token.rb +10 -6
  31. data/lib/oauth/rack/oauth_filter.rb +57 -12
  32. data/oauth-plugin.gemspec +11 -3
  33. data/spec/rack/oauth_filter_spec.rb +136 -0
  34. data/spec/spec_helper.rb +3 -0
  35. metadata +105 -38
  36. data/generators/oauth_provider/templates/controller_spec.rb +0 -838
  37. data/generators/oauth_provider/templates/controller_spec_helper.rb +0 -66
  38. data/generators/oauth_provider/templates/controller_test.rb +0 -310
  39. data/generators/oauth_provider/templates/controller_test_helper.rb +0 -115
  40. data/lib/generators/rspec/templates/controller_spec.rb +0 -838
  41. data/lib/generators/rspec/templates/controller_spec_helper.rb +0 -66
  42. data/lib/generators/test_unit/templates/controller_test.rb +0 -310
  43. data/lib/generators/test_unit/templates/controller_test_helper.rb +0 -115
data/.gitignore CHANGED
@@ -6,3 +6,5 @@ pkg
6
6
  *.gem
7
7
  .bundle
8
8
  .swp
9
+ .idea
10
+ .rvmrc
data/CHANGELOG CHANGED
@@ -1,3 +1,14 @@
1
+ 0.4.0-pre5
2
+ - protect oauth consumer relay with :expose configuration option. It's off by default. [pelle]
3
+ - Reenable twitter client. It is now configurable for twitter tokens. :client=>:twitter_gem or :oauth_gem [pelle]
4
+ - fix issues with new consumer tokens [afeld]
5
+ - More forgiving about oob callback values[chrisrhoden]
6
+ - Update Twitter consumer to use latest Twitter Gem [afeld]
7
+ - removed portable_contacts client from Google Token [p8]
8
+ - Fixes various mongoid issues [3en]
9
+ - Adds oauth2 consumer support
10
+ - Fixes oauth2 provider. parameter should be redirect_uri not redirect_url [Kimtaro]
11
+ - Most core OAuth functionality is being put into OAuthFilter. This means Rails 2.3 and above only
1
12
  0.4.0-pre4
2
13
  - Fixed bug when creating a new user from a new consumer token
3
14
  - Fix typo in consumer token [krasio]
data/Gemfile.lock ADDED
@@ -0,0 +1,66 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ oauth-plugin (0.4.0.pre5)
5
+ multi_json
6
+ oauth (~> 0.4.4)
7
+ oauth2
8
+ rack
9
+
10
+ GEM
11
+ remote: http://rubygems.org/
12
+ specs:
13
+ addressable (2.2.6)
14
+ diff-lcs (1.1.2)
15
+ fakeweb (1.3.0)
16
+ faraday (0.6.1)
17
+ addressable (~> 2.2.4)
18
+ multipart-post (~> 1.1.0)
19
+ rack (>= 1.1.0, < 2)
20
+ fuubar (0.0.5)
21
+ rspec (~> 2.0)
22
+ rspec-instafail (~> 0.1.4)
23
+ ruby-progressbar (~> 0.0.10)
24
+ growl (1.0.3)
25
+ guard (0.3.4)
26
+ thor (~> 0.14.6)
27
+ guard-rspec (0.3.1)
28
+ guard (>= 0.2.2)
29
+ multi_json (1.0.3)
30
+ multi_xml (0.2.2)
31
+ multipart-post (1.1.2)
32
+ oauth (0.4.4)
33
+ oauth2 (0.4.1)
34
+ faraday (~> 0.6.1)
35
+ multi_json (>= 0.0.5)
36
+ opentransact (0.1.2)
37
+ multi_json
38
+ multi_xml
39
+ oauth (~> 0.4.4)
40
+ rack (1.3.0)
41
+ rack-test (0.6.0)
42
+ rack (>= 1.0)
43
+ rspec (2.4.0)
44
+ rspec-core (~> 2.4.0)
45
+ rspec-expectations (~> 2.4.0)
46
+ rspec-mocks (~> 2.4.0)
47
+ rspec-core (2.4.0)
48
+ rspec-expectations (2.4.0)
49
+ diff-lcs (~> 1.1.2)
50
+ rspec-instafail (0.1.7)
51
+ rspec-mocks (2.4.0)
52
+ ruby-progressbar (0.0.10)
53
+ thor (0.14.6)
54
+
55
+ PLATFORMS
56
+ ruby
57
+
58
+ DEPENDENCIES
59
+ fakeweb
60
+ fuubar
61
+ growl
62
+ guard-rspec
63
+ oauth-plugin!
64
+ opentransact
65
+ rack-test
66
+ rspec (~> 2.4.0)
data/Guardfile ADDED
@@ -0,0 +1,8 @@
1
+ # A sample Guardfile
2
+ # More info at http://github.com/guard/guard#readme
3
+
4
+ guard 'rspec', :version => 2 do
5
+ watch('^spec/(.*)_spec.rb')
6
+ watch('^lib/oauth/(.*)\.rb') { |m| "spec/#{m[1]}_spec.rb" }
7
+ watch('^spec/spec_helper.rb') { "spec" }
8
+ end
data/README.rdoc CHANGED
@@ -67,6 +67,14 @@ This generates OAuth and OAuth client controllers as well as the required models
67
67
 
68
68
  It requires an authentication framework such as acts_as_authenticated, restful_authentication or restful_open_id_authentication. It also requires Rails 2.0.
69
69
 
70
+ === INSTALL RACK FILTER (NEW)
71
+
72
+ A big change over previous versions is that we now use a rack filter. You have to install this in your application.rb file:
73
+
74
+ require 'oauth/rack/oauth_filter'
75
+ config.middleware.use OAuth::Rack::OAuthFilter
76
+
77
+
70
78
  === Generator Options
71
79
 
72
80
  The generator supports the defaults you have created in your application.rb file. eg:
@@ -325,11 +333,14 @@ Add entries to OAUTH_CREDENTIALS for all OAuth Applications you wish to connect
325
333
  OAUTH_CREDENTIALS={
326
334
  :twitter=>{
327
335
  :key=>"key",
328
- :secret=>"secret"
336
+ :secret=>"secret",
337
+ :client=>:twitter_gem, # :twitter_gem or :oauth_gem (defaults to :twitter_gem)
338
+ :expose => false, # set to true to expose client via the web
329
339
  },
330
340
  :agree2=>{
331
341
  :key=>"key",
332
- :secret=>"secret"
342
+ :secret=>"secret",
343
+ :expose => false, # set to true to expose client via the web
333
344
  },
334
345
  :hour_feed=>{
335
346
  :key=>"",
@@ -370,6 +381,10 @@ And you could do:
370
381
 
371
382
  The client method gives you a OAuth::AccessToken which you can use to perform rest operations on the client site - see http://oauth.rubyforge.org/rdoc/classes/OAuth/AccessToken.html
372
383
 
384
+ If you are using Mongoid you want to add an embeds_many association in your user model:
385
+
386
+ embeds_many :consumer_tokens
387
+
373
388
  === Custom ConsumerToken models
374
389
 
375
390
  Before creating the FireEagleToken model the plugin checks if a class already exists by that name or if we provide an api wrapper for it. This allows you to create a better token model that uses an existing ruby gem.
@@ -391,9 +406,33 @@ To connect a user to an external service link or redirect them to:
391
406
  Where SERVICE_NAME is the name you set in the OAUTH_CREDENTIALS hash. This will request the request token and redirect the user to the services authorization screen. When the user accepts the get redirected back to:
392
407
 
393
408
  /oauth_consumers/[SERVICE_NAME]/callback
394
-
409
+
395
410
  You can specify this url to the service you're calling when you register, but it will automatically be sent along anyway.
396
411
 
412
+ === Expose client
413
+
414
+ This is designed to let your local javascript apps access remote OAuth apis. You have to specifically enable this by adding the expose flag to your oauth config file. eg:
415
+
416
+ OAUTH_CREDENTIALS={
417
+ :twitter=>{
418
+ :key=>"key",
419
+ :secret=>"secret",
420
+ :client=>:oauth_gem, # :twitter_gem or :oauth_gem (defaults to :twitter_gem)
421
+ :expose => true # set to true to expose client via the web
422
+ }
423
+
424
+ Once the user has authorized your application, you can access the client APIs via:
425
+
426
+ /oauth_consumers/[SERVICE_NAME]/client/[ENDPOINT]
427
+
428
+ For example to get the user's Google Calendars in JSON (documented in their API as "https://www.google.com/calendar/feeds/default?alt=jsonc"), you would append that path as the ENDPOINT above, i.e.
429
+
430
+ /oauth_consumers/google/client/calendar/feeds/default?alt=jsonc
431
+
432
+ As another example, to get my Twitter info as XML (available at "https://api.twitter.com/1/users/show.xml?screen_name=pelleb"), use:
433
+
434
+ /oauth_consumers/twitter/client/1/users/show.xml?screen_name=pelleb
435
+
397
436
  === Migrate database
398
437
 
399
438
  The database is defined in:
@@ -404,6 +443,13 @@ Run them as any other normal migration in rails with:
404
443
 
405
444
  rake db:migrate
406
445
 
446
+ == Contribute and earn OAuth Karma
447
+
448
+ Anyone who has a commit accepted into the official oauth-plugin git repo is awarded OAuthKarma:
449
+
450
+ https://picomoney.com/oauth-karma/accounts
451
+
452
+
407
453
  == More
408
454
 
409
455
  The Mailing List for all things OAuth in Ruby is:
@@ -418,4 +464,4 @@ The OAuth Ruby Gem home page is http://oauth.rubyforge.org
418
464
 
419
465
  Please help documentation, patches and testing.
420
466
 
421
- Copyright (c) 2007-2010 Pelle Braendgaard and contributors, released under the MIT license
467
+ Copyright (c) 2007-2011 Pelle Braendgaard and contributors, released under the MIT license
@@ -7,6 +7,14 @@ class OauthConsumersController < ApplicationController
7
7
  @services=OAUTH_CREDENTIALS.keys-@consumer_tokens.collect{|c| c.class.service_name}
8
8
  end
9
9
 
10
+ def callback
11
+ super
12
+ end
13
+
14
+ def client
15
+ super
16
+ end
17
+
10
18
  protected
11
19
 
12
20
  # Change this to decide where you want to redirect user to after callback is finished.
@@ -6,13 +6,27 @@
6
6
  # OAUTH_CREDENTIALS={
7
7
  # :twitter=>{
8
8
  # :key=>"",
9
- # :secret=>""
9
+ # :secret=>"",
10
+ # :client=>:twitter_gem, # :twitter_gem or :oauth_gem (defaults to :twitter_gem)
11
+ # :expose => false, # expose client at /oauth_consumers/twitter/client see docs
12
+ # :allow_login => true # Use :allow_login => true to allow user to login to account
10
13
  # },
11
14
  # :google=>{
12
15
  # :key=>"",
13
16
  # :secret=>"",
17
+ # :expose => false, # expose client at /oauth_consumers/google/client see docs
14
18
  # :scope=>"" # see http://code.google.com/apis/gdata/faq.html#AuthScopes
15
19
  # },
20
+ # :github=>{
21
+ # :key => "",
22
+ # :secret => "",
23
+ # :expose => false, # expose client at /oauth_consumers/twitter/client see docs
24
+ #
25
+ # },
26
+ # :facebook=>{
27
+ # :key => "",
28
+ # :secret => ""
29
+ # },
16
30
  # :agree2=>{
17
31
  # :key=>"",
18
32
  # :secret=>""
@@ -21,6 +35,14 @@
21
35
  # :key=>"",
22
36
  # :secret=>""
23
37
  # },
38
+ # :oauth2_server => {
39
+ # :key=>"",
40
+ # :secret=>"",
41
+ # :oauth_version => 2
42
+ # :options=>{ # OAuth::Consumer options
43
+ # :site=>"http://hourfeed.com" # Remember to add a site for a generic OAuth site
44
+ # }
45
+ # },
24
46
  # :hour_feed=>{
25
47
  # :key=>"",
26
48
  # :secret=>"",
@@ -73,8 +73,6 @@ class OauthProviderGenerator < Rails::Generator::Base
73
73
  m.template 'client_applications.yml',File.join('spec/fixtures',"client_applications.yml")
74
74
  m.template 'oauth_tokens.yml', File.join('spec/fixtures',"oauth_tokens.yml")
75
75
  m.template 'oauth_nonces.yml', File.join('spec/fixtures',"oauth_nonces.yml")
76
- m.template 'controller_spec_helper.rb', File.join('spec/controllers', controller_class_path,"#{controller_file_name}_controller_spec_helper.rb")
77
- m.template 'controller_spec.rb',File.join('spec/controllers',controller_class_path,"#{controller_file_name}_controller_spec.rb")
78
76
  m.template 'clients_controller_spec.rb',File.join('spec/controllers',controller_class_path,"#{controller_file_name}_clients_controller_spec.rb")
79
77
  else
80
78
  m.directory File.join('test')
@@ -87,8 +85,6 @@ class OauthProviderGenerator < Rails::Generator::Base
87
85
  m.template 'client_applications.yml',File.join('test/fixtures',"client_applications.yml")
88
86
  m.template 'oauth_tokens.yml', File.join('test/fixtures',"oauth_tokens.yml")
89
87
  m.template 'oauth_nonces.yml', File.join('test/fixtures',"oauth_nonces.yml")
90
- m.template 'controller_test_helper.rb', File.join('test', controller_class_path,"#{controller_file_name}_controller_test_helper.rb")
91
- m.template 'controller_test.rb',File.join('test/functional',controller_class_path,"#{controller_file_name}_controller_test.rb")
92
88
  m.template 'clients_controller_test.rb',File.join('test/functional',controller_class_path,"#{controller_file_name}_clients_controller_test.rb")
93
89
  end
94
90
 
@@ -3,7 +3,7 @@
3
3
  <%% form_tag authorize_url do %>
4
4
  <%%= hidden_field_tag "response_type", params[:response_type]%>
5
5
  <%%= hidden_field_tag "client_id", params[:client_id]%>
6
- <%%= hidden_field_tag "redirect_url", params[:redirect_url]%>
6
+ <%%= hidden_field_tag "redirect_uri", params[:redirect_uri]%>
7
7
  <%%= hidden_field_tag "state", params[:state]%>
8
8
  <%%= hidden_field_tag "scope", params[:scope]%>
9
9
 
@@ -13,4 +13,4 @@
13
13
  <p>
14
14
  <%%= submit_tag %>
15
15
  </p>
16
- <%% end %>
16
+ <%% end %>
@@ -8,7 +8,7 @@
8
8
  - form_tag authorize_url do
9
9
  = hidden_field_tag "response_type", params[:response_type]
10
10
  = hidden_field_tag "client_id", params[:client_id]
11
- = hidden_field_tag "redirect_url", params[:redirect_url]
11
+ = hidden_field_tag "redirect_uri", params[:redirect_uri]
12
12
  = hidden_field_tag "state", params[:state]
13
13
  = hidden_field_tag "scope", params[:scope]
14
14
  = check_box_tag 'authorize'
@@ -30,11 +30,11 @@ class RequestToken < OauthToken
30
30
  end
31
31
 
32
32
  def oob?
33
- self.callback_url=='oob'
33
+ callback_url.nil? || callback_url.downcase == 'oob'
34
34
  end
35
35
 
36
36
  def oauth10?
37
37
  (defined? OAUTH_10_SUPPORT) && OAUTH_10_SUPPORT && self.callback_url.blank?
38
38
  end
39
39
 
40
- end
40
+ end
@@ -28,9 +28,9 @@ class RequestToken < OauthToken
28
28
  "#{super}&oauth_callback_confirmed=true"
29
29
  end
30
30
  end
31
-
31
+
32
32
  def oob?
33
- self.callback_url=='oob'
33
+ callback_url.nil? || callback_url.downcase == 'oob'
34
34
  end
35
35
 
36
36
  def oauth10?
@@ -3,7 +3,7 @@
3
3
  <%% form_tag authorize_url do %>
4
4
  <%%= hidden_field_tag "response_type", params[:response_type]%>
5
5
  <%%= hidden_field_tag "client_id", params[:client_id]%>
6
- <%%= hidden_field_tag "redirect_url", params[:redirect_url]%>
6
+ <%%= hidden_field_tag "redirect_uri", params[:redirect_uri]%>
7
7
  <%%= hidden_field_tag "state", params[:state]%>
8
8
  <%%= hidden_field_tag "scope", params[:scope]%>
9
9
 
@@ -8,7 +8,7 @@
8
8
  - form_tag authorize_url do
9
9
  = hidden_field_tag "response_type", params[:response_type]
10
10
  = hidden_field_tag "client_id", params[:client_id]
11
- = hidden_field_tag "redirect_url", params[:redirect_url]
11
+ = hidden_field_tag "redirect_uri", params[:redirect_uri]
12
12
  = hidden_field_tag "state", params[:state]
13
13
  = hidden_field_tag "scope", params[:scope]
14
14
  = check_box_tag 'authorize'
@@ -18,20 +18,22 @@ class ConsumerToken
18
18
  # index "consumer_tokens.token"
19
19
  #
20
20
  embedded_in :user, :inverse_of => :consumer_tokens
21
-
21
+
22
22
  def self.find_or_create_from_access_token(user,access_token)
23
+ secret = access_token.respond_to?(:secret) ? access_token.secret : nil
24
+
23
25
  if user
24
- user.consumer_tokens.first(:conditions=>{:_type=>self.to_s,:token=>access_token.token}) ||
25
- user.consumer_tokens.create!(:_type=>self.to_s,:token=>access_token.token, :secret=>access_token.secret)
26
+ user.consumer_tokens.where(:_type=>self.to_s,:token=>access_token.token).first ||
27
+ self.create!(:_type=>self.to_s,:token=>access_token.token, :secret=>secret, :user=>user)
26
28
  else
27
- # Is there a better way of doing this in mongoid?
28
- # Please submit a patch
29
- user = User.first(:conditions=>{:_type=>self.to_s,"consumer_tokens.token"=>access_token.token})
29
+ user = User.where("consumer_tokens._type"=>self.to_s,"consumer_tokens.token"=>access_token.token).first
30
30
  if user
31
31
  user.consumer_tokens.detect{|t| t.token==access_token.token && t.is_a?(self)}
32
32
  else
33
- user = User.create
34
- user.consumer_tokens.create!(:_type=>self.to_s,:token=>access_token.token, :secret=>access_token.secret)
33
+ user = User.new
34
+ self.create!(:_type=>self.to_s,:token=>access_token.token, :secret=>secret, :user=>user)
35
+ user.save!
36
+ user.consumer_tokens.last
35
37
  end
36
38
  end
37
39
  end
@@ -25,9 +25,9 @@ class RequestToken < OauthToken
25
25
  "#{super}&oauth_callback_confirmed=true"
26
26
  end
27
27
  end
28
-
28
+
29
29
  def oob?
30
- self.callback_url == 'oob'
30
+ callback_url.nil? || callback_url.downcase == 'oob'
31
31
  end
32
32
 
33
33
  def oauth10?
@@ -19,7 +19,11 @@ class OauthConsumerGenerator < Rails::Generators::Base
19
19
  def add_route
20
20
  route <<-ROUTE.strip
21
21
  resources :oauth_consumers do
22
- get :callback, :on => :member
22
+ member do
23
+ get :callback
24
+ get :callback2
25
+ match 'client/*endpoint' => 'oauth_consumers#client'
26
+ end
23
27
  end
24
28
  ROUTE
25
29
  end
@@ -12,6 +12,15 @@ class OauthConsumersController < ApplicationController
12
12
  @services=OAUTH_CREDENTIALS.keys-@consumer_tokens.collect{|c| c.class.service_name}
13
13
  end
14
14
 
15
+ def callback
16
+ super
17
+ end
18
+
19
+ def client
20
+ super
21
+ end
22
+
23
+
15
24
  protected
16
25
 
17
26
  # Change this to decide where you want to redirect user to after callback is finished.
@@ -7,13 +7,26 @@
7
7
  # :twitter=>{
8
8
  # :key=>"",
9
9
  # :secret=>"",
10
+ # :client=>:twitter_gem, # :twitter_gem or :oauth_gem (defaults to :twitter_gem)
11
+ # :expose => false, # expose client at /oauth_consumers/twitter/client see docs
10
12
  # :allow_login => true # Use :allow_login => true to allow user to login to account
11
13
  # },
12
14
  # :google=>{
13
15
  # :key=>"",
14
16
  # :secret=>"",
17
+ # :expose => false, # expose client at /oauth_consumers/google/client see docs
15
18
  # :scope=>"" # see http://code.google.com/apis/gdata/faq.html#AuthScopes
16
19
  # },
20
+ # :github=>{
21
+ # :key => "",
22
+ # :secret => "",
23
+ # :expose => false, # expose client at /oauth_consumers/twitter/client see docs
24
+ #
25
+ # },
26
+ # :facebook=>{
27
+ # :key => "",
28
+ # :secret => ""
29
+ # },
17
30
  # :agree2=>{
18
31
  # :key=>"",
19
32
  # :secret=>""
@@ -22,6 +35,14 @@
22
35
  # :key=>"",
23
36
  # :secret=>""
24
37
  # },
38
+ # :oauth2_server => {
39
+ # :key=>"",
40
+ # :secret=>"",
41
+ # :oauth_version => 2
42
+ # :options=>{ # OAuth::Consumer options
43
+ # :site=>"http://hourfeed.com" # Remember to add a site for a generic OAuth site
44
+ # }
45
+ # },
25
46
  # :hour_feed=>{
26
47
  # :key=>"",
27
48
  # :secret=>"",