insrc-oauth-plugin 0.4.0.pre5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (164) hide show
  1. data/.gitignore +10 -0
  2. data/CHANGELOG +146 -0
  3. data/Gemfile +4 -0
  4. data/Gemfile.lock +86 -0
  5. data/Guardfile +8 -0
  6. data/MIT-LICENSE +20 -0
  7. data/README.rdoc +427 -0
  8. data/Rakefile +2 -0
  9. data/UPGRADE.rdoc +21 -0
  10. data/generators/oauth_consumer/USAGE +10 -0
  11. data/generators/oauth_consumer/oauth_consumer_generator.rb +50 -0
  12. data/generators/oauth_consumer/templates/consumer_token.rb +11 -0
  13. data/generators/oauth_consumer/templates/controller.rb +23 -0
  14. data/generators/oauth_consumer/templates/index.html.erb +29 -0
  15. data/generators/oauth_consumer/templates/index.html.haml +18 -0
  16. data/generators/oauth_consumer/templates/migration.rb +20 -0
  17. data/generators/oauth_consumer/templates/oauth_config.rb +63 -0
  18. data/generators/oauth_consumer/templates/show.html.erb +7 -0
  19. data/generators/oauth_consumer/templates/show.html.haml +8 -0
  20. data/generators/oauth_provider/USAGE +20 -0
  21. data/generators/oauth_provider/lib/insert_routes.rb +67 -0
  22. data/generators/oauth_provider/oauth_provider_generator.rb +127 -0
  23. data/generators/oauth_provider/templates/_form.html.erb +17 -0
  24. data/generators/oauth_provider/templates/_form.html.haml +21 -0
  25. data/generators/oauth_provider/templates/access_token.rb +16 -0
  26. data/generators/oauth_provider/templates/authorize.html.erb +14 -0
  27. data/generators/oauth_provider/templates/authorize.html.haml +16 -0
  28. data/generators/oauth_provider/templates/authorize_failure.html.erb +1 -0
  29. data/generators/oauth_provider/templates/authorize_failure.html.haml +1 -0
  30. data/generators/oauth_provider/templates/authorize_success.html.erb +1 -0
  31. data/generators/oauth_provider/templates/authorize_success.html.haml +1 -0
  32. data/generators/oauth_provider/templates/client_application.rb +57 -0
  33. data/generators/oauth_provider/templates/client_application_spec.rb +29 -0
  34. data/generators/oauth_provider/templates/client_application_test.rb +42 -0
  35. data/generators/oauth_provider/templates/client_applications.yml +23 -0
  36. data/generators/oauth_provider/templates/clients_controller.rb +52 -0
  37. data/generators/oauth_provider/templates/clients_controller_spec.rb +176 -0
  38. data/generators/oauth_provider/templates/clients_controller_test.rb +280 -0
  39. data/generators/oauth_provider/templates/controller.rb +23 -0
  40. data/generators/oauth_provider/templates/edit.html.erb +7 -0
  41. data/generators/oauth_provider/templates/edit.html.haml +4 -0
  42. data/generators/oauth_provider/templates/index.html.erb +43 -0
  43. data/generators/oauth_provider/templates/index.html.haml +39 -0
  44. data/generators/oauth_provider/templates/migration.rb +47 -0
  45. data/generators/oauth_provider/templates/new.html.erb +5 -0
  46. data/generators/oauth_provider/templates/new.html.haml +5 -0
  47. data/generators/oauth_provider/templates/oauth2_authorize.html.erb +16 -0
  48. data/generators/oauth_provider/templates/oauth2_authorize.html.haml +17 -0
  49. data/generators/oauth_provider/templates/oauth2_token.rb +6 -0
  50. data/generators/oauth_provider/templates/oauth2_token_spec.rb +29 -0
  51. data/generators/oauth_provider/templates/oauth2_verifier.rb +28 -0
  52. data/generators/oauth_provider/templates/oauth2_verifier_spec.rb +54 -0
  53. data/generators/oauth_provider/templates/oauth_nonce.rb +13 -0
  54. data/generators/oauth_provider/templates/oauth_nonce_spec.rb +24 -0
  55. data/generators/oauth_provider/templates/oauth_nonce_test.rb +26 -0
  56. data/generators/oauth_provider/templates/oauth_nonces.yml +13 -0
  57. data/generators/oauth_provider/templates/oauth_token.rb +30 -0
  58. data/generators/oauth_provider/templates/oauth_token_spec.rb +309 -0
  59. data/generators/oauth_provider/templates/oauth_token_test.rb +57 -0
  60. data/generators/oauth_provider/templates/oauth_tokens.yml +17 -0
  61. data/generators/oauth_provider/templates/request_token.rb +40 -0
  62. data/generators/oauth_provider/templates/show.html.erb +27 -0
  63. data/generators/oauth_provider/templates/show.html.haml +30 -0
  64. data/init.rb +1 -0
  65. data/install.rb +2 -0
  66. data/lib/generators/active_record/oauth_consumer_generator.rb +33 -0
  67. data/lib/generators/active_record/oauth_consumer_templates/consumer_token.rb +11 -0
  68. data/lib/generators/active_record/oauth_consumer_templates/migration.rb +20 -0
  69. data/lib/generators/active_record/oauth_provider_generator.rb +39 -0
  70. data/lib/generators/active_record/oauth_provider_templates/access_token.rb +16 -0
  71. data/lib/generators/active_record/oauth_provider_templates/client_application.rb +57 -0
  72. data/lib/generators/active_record/oauth_provider_templates/migration.rb +47 -0
  73. data/lib/generators/active_record/oauth_provider_templates/oauth2_token.rb +5 -0
  74. data/lib/generators/active_record/oauth_provider_templates/oauth2_verifier.rb +28 -0
  75. data/lib/generators/active_record/oauth_provider_templates/oauth_nonce.rb +13 -0
  76. data/lib/generators/active_record/oauth_provider_templates/oauth_token.rb +30 -0
  77. data/lib/generators/active_record/oauth_provider_templates/request_token.rb +40 -0
  78. data/lib/generators/erb/oauth_consumer_generator.rb +14 -0
  79. data/lib/generators/erb/oauth_consumer_templates/index.html.erb +29 -0
  80. data/lib/generators/erb/oauth_consumer_templates/show.html.erb +7 -0
  81. data/lib/generators/erb/oauth_provider_generator.rb +21 -0
  82. data/lib/generators/erb/oauth_provider_templates/_form.html.erb +17 -0
  83. data/lib/generators/erb/oauth_provider_templates/authorize.html.erb +14 -0
  84. data/lib/generators/erb/oauth_provider_templates/authorize_failure.html.erb +1 -0
  85. data/lib/generators/erb/oauth_provider_templates/authorize_success.html.erb +1 -0
  86. data/lib/generators/erb/oauth_provider_templates/edit.html.erb +7 -0
  87. data/lib/generators/erb/oauth_provider_templates/index.html.erb +43 -0
  88. data/lib/generators/erb/oauth_provider_templates/new.html.erb +5 -0
  89. data/lib/generators/erb/oauth_provider_templates/oauth2_authorize.html.erb +16 -0
  90. data/lib/generators/erb/oauth_provider_templates/show.html.erb +27 -0
  91. data/lib/generators/haml/oauth_consumer_generator.rb +21 -0
  92. data/lib/generators/haml/oauth_consumer_templates/index.html.haml +18 -0
  93. data/lib/generators/haml/oauth_consumer_templates/show.html.haml +8 -0
  94. data/lib/generators/haml/oauth_provider_generator.rb +28 -0
  95. data/lib/generators/haml/oauth_provider_templates/_form.html.haml +21 -0
  96. data/lib/generators/haml/oauth_provider_templates/authorize.html.haml +16 -0
  97. data/lib/generators/haml/oauth_provider_templates/authorize_failure.html.haml +1 -0
  98. data/lib/generators/haml/oauth_provider_templates/authorize_success.html.haml +1 -0
  99. data/lib/generators/haml/oauth_provider_templates/edit.html.haml +4 -0
  100. data/lib/generators/haml/oauth_provider_templates/index.html.haml +39 -0
  101. data/lib/generators/haml/oauth_provider_templates/new.html.haml +5 -0
  102. data/lib/generators/haml/oauth_provider_templates/oauth2_authorize.html.haml +17 -0
  103. data/lib/generators/haml/oauth_provider_templates/show.html.haml +30 -0
  104. data/lib/generators/mongoid/oauth_consumer_generator.rb +15 -0
  105. data/lib/generators/mongoid/oauth_consumer_templates/consumer_token.rb +41 -0
  106. data/lib/generators/mongoid/oauth_provider_generator.rb +21 -0
  107. data/lib/generators/mongoid/oauth_provider_templates/access_token.rb +16 -0
  108. data/lib/generators/mongoid/oauth_provider_templates/client_application.rb +71 -0
  109. data/lib/generators/mongoid/oauth_provider_templates/oauth2_token.rb +5 -0
  110. data/lib/generators/mongoid/oauth_provider_templates/oauth2_verifier.rb +25 -0
  111. data/lib/generators/mongoid/oauth_provider_templates/oauth_nonce.rb +24 -0
  112. data/lib/generators/mongoid/oauth_provider_templates/oauth_token.rb +44 -0
  113. data/lib/generators/mongoid/oauth_provider_templates/request_token.rb +36 -0
  114. data/lib/generators/oauth_consumer/USAGE +11 -0
  115. data/lib/generators/oauth_consumer/oauth_consumer_generator.rb +30 -0
  116. data/lib/generators/oauth_consumer/templates/controller.rb +54 -0
  117. data/lib/generators/oauth_consumer/templates/oauth_config.rb +63 -0
  118. data/lib/generators/oauth_inflections.rb +6 -0
  119. data/lib/generators/oauth_plugin.rb +0 -0
  120. data/lib/generators/oauth_provider/USAGE +18 -0
  121. data/lib/generators/oauth_provider/oauth_provider_generator.rb +47 -0
  122. data/lib/generators/oauth_provider/templates/clients_controller.rb +52 -0
  123. data/lib/generators/oauth_provider/templates/controller.rb +23 -0
  124. data/lib/generators/rspec/oauth_provider_generator.rb +35 -0
  125. data/lib/generators/rspec/templates/client_application_spec.rb +29 -0
  126. data/lib/generators/rspec/templates/client_applications.yml +23 -0
  127. data/lib/generators/rspec/templates/clients_controller_spec.rb +176 -0
  128. data/lib/generators/rspec/templates/oauth2_token_spec.rb +29 -0
  129. data/lib/generators/rspec/templates/oauth2_verifier_spec.rb +54 -0
  130. data/lib/generators/rspec/templates/oauth_nonce_spec.rb +24 -0
  131. data/lib/generators/rspec/templates/oauth_nonces.yml +13 -0
  132. data/lib/generators/rspec/templates/oauth_token_spec.rb +309 -0
  133. data/lib/generators/rspec/templates/oauth_tokens.yml +17 -0
  134. data/lib/generators/test_unit/oauth_provider_generator.rb +33 -0
  135. data/lib/generators/test_unit/templates/client_application_test.rb +42 -0
  136. data/lib/generators/test_unit/templates/client_applications.yml +23 -0
  137. data/lib/generators/test_unit/templates/clients_controller_test.rb +280 -0
  138. data/lib/generators/test_unit/templates/oauth_nonce_test.rb +26 -0
  139. data/lib/generators/test_unit/templates/oauth_nonces.yml +13 -0
  140. data/lib/generators/test_unit/templates/oauth_token_test.rb +57 -0
  141. data/lib/generators/test_unit/templates/oauth_tokens.yml +17 -0
  142. data/lib/oauth/controllers/application_controller_methods.rb +136 -0
  143. data/lib/oauth/controllers/consumer_controller.rb +113 -0
  144. data/lib/oauth/controllers/provider_controller.rb +224 -0
  145. data/lib/oauth/models/consumers/service_loader.rb +28 -0
  146. data/lib/oauth/models/consumers/services/agree2_token.rb +15 -0
  147. data/lib/oauth/models/consumers/services/fireeagle_token.rb +39 -0
  148. data/lib/oauth/models/consumers/services/google_token.rb +27 -0
  149. data/lib/oauth/models/consumers/services/oauth2_token.rb +27 -0
  150. data/lib/oauth/models/consumers/services/opentransact_token.rb +15 -0
  151. data/lib/oauth/models/consumers/services/picomoney_token.rb +17 -0
  152. data/lib/oauth/models/consumers/services/twitter_token.rb +11 -0
  153. data/lib/oauth/models/consumers/simple_client.rb +50 -0
  154. data/lib/oauth/models/consumers/token.rb +93 -0
  155. data/lib/oauth/rack/oauth_filter.rb +95 -0
  156. data/lib/oauth-plugin/version.rb +5 -0
  157. data/lib/oauth-plugin.rb +22 -0
  158. data/oauth-plugin.gemspec +40 -0
  159. data/rails/init.rb +1 -0
  160. data/spec/rack/oauth_filter_spec.rb +136 -0
  161. data/spec/spec_helper.rb +3 -0
  162. data/tasks/oauth_tasks.rake +4 -0
  163. data/uninstall.rb +1 -0
  164. metadata +406 -0
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ doc
2
+ pkg
3
+ *.log
4
+ .DS_Store
5
+ .svn
6
+ *.gem
7
+ .bundle
8
+ .swp
9
+ .idea
10
+ .rvmrc
data/CHANGELOG ADDED
@@ -0,0 +1,146 @@
1
+ 0.4.0-pre5
2
+ - fix issues with new consumer tokens [afeld]
3
+ - More forgiving about oob callback values[chrisrhoden]
4
+ - Update Twitter consumer to use latest Twitter Gem [afeld]
5
+ - Fixes various mongoid issues [3en]
6
+ - Adds oauth2 consumer support
7
+ - Fixes oauth2 provider. parameter should be redirect_uri not redirect_url [Kimtaro]
8
+ - Most core OAuth functionality is being put into OAuthFilter. This means Rails 2.3 and above only
9
+ 0.4.0-pre4
10
+ - Fixed bug when creating a new user from a new consumer token
11
+ - Fix typo in consumer token [krasio]
12
+ - Fix issue with mongoid not supporting find_by_x style queries. [3en]
13
+ 0.4.0-pre3
14
+ - Experimental rack filter for OAuth 1.0a:
15
+ see lib/oauth/rack/oauth_filter.rb for details
16
+ 0.4.0-pre2
17
+ - mongoid defaults to being embedded
18
+ - new :auto_login option in oauth_config.rb which lets you use eg. twitter as a primary authentication method
19
+ 0.4.0-pre1
20
+ - mongoid support in rails 3 [Alexander Semyonov]
21
+ - OAUTH 2.0 authorization_code and password grant types
22
+ - Supports OAuth 2.0 draft 10 (Note this is incompatible with previous drafts)
23
+ - Refactored application_controller_methods to be a lot less intrusive
24
+ - Increased default token and key size in anticipation of OAuth2 support
25
+ - Rails 3 support
26
+ - Rails 3 generators [Paul Rosiana] and patches by [Alexander Flatter]
27
+ - Modularized Rails 3 generators [Alexander Semyonov]
28
+ - Callback urls now allow query parameters. Multiple patches but I used [Unk]'s.
29
+ 10/08/2009
30
+ 0.3.14
31
+ - Fixed the class generation when you have a custom token defined. [Brian Morearty]
32
+ 10/05/2009
33
+ 0.3.13
34
+ - Got rid of yahoo token. To support it correctly requires way too much work. Let them suffer the consequences of their decissions.
35
+ - GoogleToken now uses portablecontacts gem
36
+ 9/30/2009
37
+ 0.3.12
38
+ - Added a simple PortableContacts adapter for GoogleToken
39
+ - Added a SimpleClient wrapper to provide really simple wrapper for OAuth based json web services
40
+ - Increased token size in consumer_tokens table because of Yahoo's oversized tokens
41
+ - Added support for Yahoo
42
+ - Added support for Google (Boon Low)
43
+ 9/26/2009
44
+ 0.3.11
45
+ - Moved twitter tokens dependency back to regular twitter gem
46
+ 7/29/2009
47
+ 0.3.10
48
+ - Closed blocks in erb template (jcrosby) while pelle is hiding under his desk
49
+ - Handled error case on authorize with non existent token
50
+ - Fixed Agree2 token
51
+ - Security Fix: Only skip verify_authenticity_token for specific oauth token requests in provider controller
52
+ 7/25/2009
53
+ 0.3.9
54
+ - Added an Index to oauth consumers controller. Rerun generator to create index template
55
+ - Added invalidate action to provider, which allows a token to invalidate itself /oauth/invalidate
56
+ - Added capabilities action to provider. Lets you expand to allow auto discovery of permissions and services that token provides.
57
+ - Can override how authorize form indicates an authorization. To get around ugly checkbox
58
+
59
+ def user_authorizes_token?
60
+ params[:commit] == 'Authorize'
61
+ end
62
+
63
+ 7/23/2009
64
+ 0.3.8
65
+ - Fixed Gem Plugins Loading
66
+ 7/21/2009
67
+ 0.3.7
68
+ - A blushing Pelle adds a missing file
69
+ 0.3.6
70
+ - Twitter, Agree2 and FireEagle tokens are working in consumer.
71
+ 0.3.5
72
+ - made it a gem
73
+ - more thorough tests of OAuth 1.0 consumer
74
+ - Add support for a OAUTH_10_SUPPORT constant to switch on support for OAuth 1.0 in provider
75
+ 7/19/2009
76
+ - Added support for OAuth 1.0 consumers (nov)
77
+ 7/17/2009
78
+ - Added back support for OAuth 1.0 for providers (nov)
79
+ 7/14/2009
80
+ - Added OAuth Consumer generator
81
+ - Moved oauth controller code to a module to make it easier to upgrade in the future
82
+ 7/11/2009
83
+ - Added support for OAuth version 1.0a
84
+ - Added haml support
85
+ - Improved OAuth Client Controller gui (alec-c4)
86
+ 2/11/2009
87
+ - Fixed escaping error and file path error in the generator simultaneously reported and fixed by Ivan Valdes and Mike Demers thanks
88
+
89
+ 2/9/2009
90
+ - Fixed compatibility issue with OAuth Gem 3.1 (wr0ngway and aeden)
91
+ - Added Test:Unit tests to generator (Ed Hickey)
92
+ - added missing oauth_clients/edit.html.erb view template (Ed Hickey)
93
+ - added missing :oauth_clients resource route in USAGE (Ed Hickey)
94
+ - Don't throw NPE it token is not in db (Haruska)
95
+ - Cleaned up whitespace (bricolage, Nicholas Nam)
96
+ - Fixed bug in default verify_oauth_signature (igrigorik)
97
+ - Doc fixes (skippy)
98
+
99
+ 6/23/2008
100
+
101
+ - Split OAuth controller into two parts: OAuth and OAuth clients. [jcrosby]
102
+
103
+ revision 31
104
+
105
+ - patch that fixes a problem in oauth_required from Hannes Tyden and Sean Treadway from SoundCloud. Thanks.
106
+
107
+ revision 30
108
+
109
+ - updated to use oauth gem 0.2.1
110
+
111
+
112
+ revision 23
113
+
114
+ - removed all core libraries from plugin. They are now in the oauth gem.
115
+
116
+ # oauth-plugin-pre-gem Branch created
117
+
118
+ revision 18
119
+ - added a generator for creation oauth_providers
120
+
121
+ revision 12
122
+ - the bug with post and put has now been fixed.
123
+ - better documentation
124
+
125
+ revision 9
126
+ - added a test helper. Include OAuth::TestHelper in your tests or specs to mock incoming requests
127
+
128
+ revision: 8
129
+ - moved tests into oauth folder and renamed them to make them work with autotest by default
130
+ - Refactored the request methods to make them more flexible and ready for integrating with ActiveResource
131
+ - There are a few tests that fail. All of them to do with put and post requests with payload data. I decided to commit anyway, to get the new api out.
132
+
133
+ revision: 7
134
+
135
+ - Done a lot of work on the Server side of things. The Server class has changed a lot and is likely to be incompatible with previous versions
136
+
137
+ revision: 6
138
+
139
+ - Throws InsecureSignatureMethod exception if attempting to use straight sha1 or md5.
140
+ - Disables plaintext signature over http (throws an InsecureSignatureMethod)
141
+ - Better testing of signature methods - the prior tests were seriously flawed.
142
+
143
+ revision: 5
144
+
145
+ - Removed support for sha1 and md5
146
+ - Implemented draft 6 support of OAuth removing secrets from base string
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in oauth-plugin.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,86 @@
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
+ twitter (~> 1.0)
10
+
11
+ GEM
12
+ remote: http://rubygems.org/
13
+ specs:
14
+ addressable (2.2.4)
15
+ configuration (1.2.0)
16
+ diff-lcs (1.1.2)
17
+ fakeweb (1.3.0)
18
+ faraday (0.5.7)
19
+ addressable (~> 2.2.4)
20
+ multipart-post (~> 1.1.0)
21
+ rack (< 2, >= 1.1.0)
22
+ faraday_middleware (0.3.2)
23
+ faraday (~> 0.5.4)
24
+ fuubar (0.0.3)
25
+ rspec (~> 2.0)
26
+ rspec-instafail (~> 0.1.4)
27
+ ruby-progressbar (~> 0.0.9)
28
+ growl (1.0.3)
29
+ guard (0.2.2)
30
+ open_gem (~> 1.4.2)
31
+ thor (~> 0.14.3)
32
+ guard-rspec (0.1.9)
33
+ guard (>= 0.2.2)
34
+ hashie (1.0.0)
35
+ launchy (0.3.7)
36
+ configuration (>= 0.0.5)
37
+ rake (>= 0.8.1)
38
+ multi_json (0.0.5)
39
+ multi_xml (0.2.0)
40
+ multipart-post (1.1.0)
41
+ oauth (0.4.4)
42
+ oauth2 (0.1.1)
43
+ faraday (~> 0.5.0)
44
+ multi_json (~> 0.0.4)
45
+ open_gem (1.4.2)
46
+ launchy (~> 0.3.5)
47
+ opentransact (0.1.0)
48
+ multi_json
49
+ multi_xml
50
+ oauth (~> 0.4.4)
51
+ rack (1.2.1)
52
+ rack-test (0.5.6)
53
+ rack (>= 1.0)
54
+ rake (0.8.7)
55
+ rspec (2.4.0)
56
+ rspec-core (~> 2.4.0)
57
+ rspec-expectations (~> 2.4.0)
58
+ rspec-mocks (~> 2.4.0)
59
+ rspec-core (2.4.0)
60
+ rspec-expectations (2.4.0)
61
+ diff-lcs (~> 1.1.2)
62
+ rspec-instafail (0.1.5)
63
+ rspec-mocks (2.4.0)
64
+ ruby-progressbar (0.0.9)
65
+ simple_oauth (0.1.4)
66
+ thor (0.14.6)
67
+ twitter (1.2.0)
68
+ faraday (~> 0.5.4)
69
+ faraday_middleware (~> 0.3.2)
70
+ hashie (~> 1.0.0)
71
+ multi_json (~> 0.0.5)
72
+ multi_xml (~> 0.2.0)
73
+ simple_oauth (~> 0.1.4)
74
+
75
+ PLATFORMS
76
+ ruby
77
+
78
+ DEPENDENCIES
79
+ fakeweb
80
+ fuubar
81
+ growl
82
+ guard-rspec
83
+ oauth-plugin!
84
+ opentransact
85
+ rack-test
86
+ 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/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2007 Pelle Braendgaard
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,427 @@
1
+ = MAJOR NEW VERSION NOT READY FOR USE YET
2
+
3
+ = OAuth Plugin
4
+
5
+ This is a plugin for implementing OAuth Providers and Consumers in Rails applications.
6
+
7
+ We support the revised OAuth 1.0a specs at:
8
+
9
+ http://oauth.net/core/1.0a
10
+
11
+ As well as support for OAuth 2.0:
12
+
13
+ http://tools.ietf.org/html/draft-ietf-oauth-v2-10
14
+
15
+ and the OAuth site at:
16
+
17
+ http://oauth.net
18
+
19
+ For more about the changes made to OAuth1.0a please see Seth's Idiot's Guide to OAuth 1.0a.
20
+
21
+ http://mojodna.net/2009/05/20/an-idiots-guide-to-oauth-10a.html
22
+
23
+ == Requirements
24
+
25
+ You need to install the oauth gem (0.4.4) which is the core OAuth ruby library. It will likely NOT work on any previous version of the gem.
26
+
27
+ gem install oauth
28
+
29
+ == Installation (Rails 3.0)
30
+
31
+ Add the plugin to your Gemfile:
32
+
33
+ gem "oauth-plugin", ">=0.4.0.pre1"
34
+
35
+ And install it:
36
+
37
+ bundle install
38
+
39
+ == Installation (Rails 2.x)
40
+
41
+ The plugin can now be installed as an gem from github, which is the easiest way to keep it up to date.
42
+
43
+ gem install oauth-plugin --pre
44
+
45
+ You should add the following in the gem dependency section of environment.rb
46
+
47
+ config.gem "oauth"
48
+ config.gem "oauth-plugin"
49
+
50
+ Alternatively you can install it in vendors/plugin:
51
+
52
+ script/plugin install git://github.com/pelle/oauth-plugin.git
53
+
54
+ The Generator currently creates code (in particular views) that only work in Rails 2 and 3.
55
+
56
+ It should not be difficult to manually modify the code to work on Rails 1.2.x
57
+
58
+ I think the only real issue is that the views have .html.erb extensions. So these could theoretically just be renamed to .rhtml.
59
+
60
+ Please let me know if this works and I will see if I can make the generator conditionally create .rhtml for pre 2.0 versions of RAILS.
61
+
62
+ == OAuth Provider generator (Rails 3)
63
+
64
+ This currently supports rspec, test_unit, haml, erb, active_record and mongoid:
65
+
66
+ rails g oauth_provider
67
+
68
+ This generates OAuth and OAuth client controllers as well as the required models.
69
+
70
+ It requires an authentication framework such as acts_as_authenticated, restful_authentication or restful_open_id_authentication. It also requires Rails 2.0.
71
+
72
+ === Generator Options
73
+
74
+ The generator supports the defaults you have created in your application.rb file. eg:
75
+
76
+ config.generators do |g|
77
+ g.orm :mongoid
78
+ g.template_engine :haml
79
+ g.test_framework :rspec
80
+ end
81
+
82
+ === User Model
83
+
84
+ Add the following lines to your user model:
85
+
86
+ has_many :client_applications
87
+ has_many :tokens, :class_name=>"OauthToken",:order=>"authorized_at desc",:include=>[:client_application]
88
+
89
+ == OAuth Provider generator (Rails 2)
90
+
91
+ While it isn't very flexible at the moment there is an oauth_provider generator which you can use like this:
92
+
93
+ ./script/generate oauth_provider
94
+
95
+ This generates OAuth and OAuth client controllers as well as the required models.
96
+
97
+ It requires an authentication framework such as acts_as_authenticated, restful_authentication or restful_open_id_authentication. It also requires Rails 2.0.
98
+
99
+ === Generator Options
100
+
101
+ By default the generator generates RSpec and ERB templates. The generator can instead create Test::Unit and/or HAML templates. To do this use the following options:
102
+
103
+ ./script/generate oauth_provider --test-unit --haml
104
+
105
+ These can of course be used individually as well.
106
+
107
+ === User Model
108
+
109
+ Add the following lines to your user model:
110
+
111
+ has_many :client_applications
112
+ has_many :tokens, :class_name=>"OauthToken",:order=>"authorized_at desc",:include=>[:client_application]
113
+
114
+ === Migrate database
115
+
116
+ The database is defined in:
117
+
118
+ db/migrate/XXX_create_oauth_tables.rb
119
+
120
+ Run them as any other normal migration in rails with:
121
+
122
+ rake db:migrate
123
+
124
+ == Upgrading from OAuth 1.0 to OAuth 1.0a
125
+
126
+ As the flow has changed slightly and there are a couple of database changes it isn't as simple as just updating the plugin. Please follow these steps closely:
127
+
128
+ === Add a migration
129
+
130
+ You need to add a migration:
131
+
132
+ script/generate migration upgrade_oauth
133
+
134
+ Make it look like this:
135
+
136
+ class UpgradeOauth < ActiveRecord::Migration
137
+ def self.up
138
+ add_column :oauth_tokens,:callback_url,:string
139
+ add_column :oauth_tokens,:verifier,:string,:limit => 20
140
+ end
141
+
142
+ def self.down
143
+ remove_column :oauth_tokens,:callback_url
144
+ remove_column :oauth_tokens,:verifier
145
+ end
146
+ end
147
+
148
+ === Change code
149
+
150
+ There are changes to the following files:
151
+
152
+ app/models/client_application.rb
153
+ app/models/request_token.rb
154
+ app/controllers/oauth_controller.rb
155
+
156
+ === Changes in client_application.rb
157
+
158
+ Add the following towards the top of the model class
159
+
160
+ attr_accessor :token_callback_url
161
+
162
+ Then change the create_request_token method to the following:
163
+
164
+ def create_request_token
165
+ RequestToken.create :client_application =>self,:callback_url=>token_callback_url
166
+ end
167
+
168
+ === Changes in request_token.rb
169
+
170
+ The RequestToken contains the bulk of the changes so it's easiest to list it in it's entirety. Mainly we need to add support for the oauth_verifier parameter and also tell the client that we support OAuth 1.0a.
171
+
172
+ Make sure it looks like this:
173
+
174
+ class RequestToken < OauthToken
175
+
176
+ attr_accessor :provided_oauth_verifier
177
+
178
+ def authorize!(user)
179
+ return false if authorized?
180
+ self.user = user
181
+ self.authorized_at = Time.now
182
+ self.verifier=OAuth::Helper.generate_key(16)[0,20] unless oauth10?
183
+ self.save
184
+ end
185
+
186
+ def exchange!
187
+ return false unless authorized?
188
+ return false unless oauth10? || verifier==provided_oauth_verifier
189
+
190
+ RequestToken.transaction do
191
+ access_token = AccessToken.create(:user => user, :client_application => client_application)
192
+ invalidate!
193
+ access_token
194
+ end
195
+ end
196
+
197
+ def to_query
198
+ if oauth10?
199
+ super
200
+ else
201
+ "#{super}&oauth_callback_confirmed=true"
202
+ end
203
+ end
204
+
205
+ def oob?
206
+ self.callback_url=='oob'
207
+ end
208
+
209
+ def oauth10?
210
+ (defined? OAUTH_10_SUPPORT) && OAUTH_10_SUPPORT && self.callback_url.blank?
211
+ end
212
+
213
+ end
214
+
215
+ === Changes in oauth_controller
216
+
217
+ All you need to do here is the change the authorize action to use the request_token callback url and add the oauth_verifier to the callback url.
218
+
219
+ def authorize
220
+ @token = ::RequestToken.find_by_token params[:oauth_token]
221
+ unless @token.invalidated?
222
+ if request.post?
223
+ if params[:authorize] == '1'
224
+ @token.authorize!(current_user)
225
+ if @token.oauth10?
226
+ @redirect_url = params[:oauth_callback] || @token.client_application.callback_url
227
+ else
228
+ @redirect_url = @token.oob? ? @token.client_application.callback_url : @token.callback_url
229
+ end
230
+
231
+ if @redirect_url
232
+ if @token.oauth10?
233
+ redirect_to "#{@redirect_url}?oauth_token=#{@token.token}"
234
+ else
235
+ redirect_to "#{@redirect_url}?oauth_token=#{@token.token}&oauth_verifier=#{@token.verifier}"
236
+ end
237
+ else
238
+ render :action => "authorize_success"
239
+ end
240
+ elsif params[:authorize] == "0"
241
+ @token.invalidate!
242
+ render :action => "authorize_failure"
243
+ end
244
+ end
245
+ else
246
+ render :action => "authorize_failure"
247
+ end
248
+ end
249
+
250
+ Alternatively if you haven't customized your controller you can replace the full controller with this:
251
+
252
+ require 'oauth/controllers/provider_controller'
253
+ class OauthController < ApplicationController
254
+ include OAuth::Controllers::ProviderController
255
+ end
256
+
257
+ This way the controller will automatically include bug fixes in future versions of the plugin.
258
+
259
+ The rest of the changes are in the plugin and will be automatically be included.
260
+
261
+ *Note* OAuth 1.0a removes support for callback url's passed to the authorize page, clients must either define a callback url in their client application or pass one on the token request page.
262
+
263
+ === Supporting old OAuth 1.0 clients
264
+
265
+ If you absolutely have to support older OAuth 1.0 clients on an optional basis, we now include a switch to turn it back on.
266
+
267
+ For legacy OAUTH 1.0 support add the following constant in your environment.rb
268
+
269
+ OAUTH_10_SUPPORT = true
270
+
271
+ Note, you should only do this if you really positively require to support old OAuth1.0 clients. There is a serious security issue with this.
272
+
273
+ == Protecting your actions
274
+
275
+ I recommend that you think about what your users would want to provide access to and limit oauth for those only. For example in a CRUD controller you may think about if you want to let consumer applications do the create, update or delete actions. For your application this might make sense, but for others maybe not.
276
+
277
+ If you want to give oauth access to everything a registered user can do, just replace the filter you have in your controllers with:
278
+
279
+ before_filter :login_or_oauth_required
280
+
281
+ If you want to restrict consumers to the index and show methods of your controller do the following:
282
+
283
+ before_filter :login_required,:except=>[:show,:index]
284
+ before_filter :login_or_oauth_required,:only=>[:show,:index]
285
+
286
+ If you have an action you only want used via oauth:
287
+
288
+ before_filter :oauth_required
289
+
290
+ All of these places the tokens user in current_user as you would expect. It also exposes the following methods:
291
+
292
+ * current_token - for accessing the token used to authorize the current request
293
+ * current_client_application - for accessing information about which consumer is currently accessing your request
294
+
295
+ You could add application specific information to the OauthToken and ClientApplication model for such things as object level access control, billing, expiry etc. Be creative and you can create some really cool applications here.
296
+
297
+ == OAuth Consumer generator
298
+
299
+ The oauth_consumer generator creates a controller to manage the authentication flow between your application and any number of external OAuth secured applications that you wish to connect to.
300
+
301
+ To run it in Rails 3 simply run:
302
+
303
+ rails g oauth_consumer
304
+
305
+ In previous versions:
306
+
307
+ ./script/generate oauth_consumer
308
+
309
+ This generates the OauthConsumerController as well as the ConsumerToken model.
310
+
311
+ === Generator Options (Rails 2)
312
+
313
+ By default the generator generates ERB templates. The generator can instead create HAML templates. To do this use the following options:
314
+
315
+ ./script/generate oauth_consumer --haml
316
+
317
+ Rails 3 respects your application defaults, see the oauth provider generator section above for more info.
318
+
319
+ === Configuration
320
+
321
+ All configuration of applications is done in
322
+
323
+ config/initializers/oauth_consumers.rb
324
+
325
+ Add entries to OAUTH_CREDENTIALS for all OAuth Applications you wish to connect to. Get this information by registering your application at the particular applications developer page.
326
+
327
+ OAUTH_CREDENTIALS={
328
+ :twitter=>{
329
+ :key=>"key",
330
+ :secret=>"secret"
331
+ },
332
+ :agree2=>{
333
+ :key=>"key",
334
+ :secret=>"secret"
335
+ },
336
+ :hour_feed=>{
337
+ :key=>"",
338
+ :secret=>"",
339
+ :options={
340
+ :site=>"http://hourfeed.com"
341
+ }
342
+ },
343
+ :nu_bux=>{
344
+ :key=>"",
345
+ :secret=>"",
346
+ :super_class=>"OpenTransactToken", # if a OAuth service follows a particular standard
347
+ # with a token implementation you can set the superclass
348
+ # to use
349
+ :options=>{
350
+ :site=>"http://nubux.heroku.com"
351
+ }
352
+ }
353
+ }
354
+
355
+ You can add any of the options that the OAuth::Consumer.new accepts to the options hash: http://oauth.rubyforge.org/rdoc/classes/OAuth/Consumer.html
356
+
357
+ :key, :secret are required as well as :options[:site] etc. for non custom ConsumerToken services.
358
+
359
+ === ConsumerToken models
360
+
361
+ For each site setup in the OAUTH_CREDENTIALS hash the plugin goes through and loads or creates a new model class that subclasses ConsumerToken.
362
+
363
+ eg. If you connect to Yahoo's FireEagle you would add the :fire_eagle entry to OAUTH_CREDENTIALS and a new FireEagleToken model class will be created on the fly.
364
+
365
+ This allows you to add a has_one association in your user model:
366
+
367
+ has_one :fire_eagle, :class_name=>"FireEagleToken", :dependent=>:destroy
368
+
369
+ And you could do:
370
+
371
+ @location=@user.fire_eagle.client.location
372
+
373
+ 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
374
+
375
+ If you are using Mongoid you want to add an embeds_many association in your user model:
376
+
377
+ embeds_many :consumer_tokens
378
+
379
+ === Custom ConsumerToken models
380
+
381
+ 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.
382
+
383
+ Currently we provide the following semi tested tokens wrappers:
384
+
385
+ * FireEagle
386
+ * Twitter
387
+ * Agree2
388
+
389
+ These can be found in lib/oauth/models/consulers/services. Contributions will be warmly accepted for your favorite OAuth service.
390
+
391
+ === The OauthConsumerController
392
+
393
+ To connect a user to an external service link or redirect them to:
394
+
395
+ /oauth_consumers/[SERVICE_NAME]
396
+
397
+ 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:
398
+
399
+ /oauth_consumers/[SERVICE_NAME]/callback
400
+
401
+ You can specify this url to the service you're calling when you register, but it will automatically be sent along anyway.
402
+
403
+ === Migrate database
404
+
405
+ The database is defined in:
406
+
407
+ db/migrate/XXX_create_oauth_consumer_tokens.rb
408
+
409
+ Run them as any other normal migration in rails with:
410
+
411
+ rake db:migrate
412
+
413
+ == More
414
+
415
+ The Mailing List for all things OAuth in Ruby is:
416
+
417
+ http://groups.google.com/group/oauth-ruby
418
+
419
+ The Mailing list for everything else OAuth is:
420
+
421
+ http://groups.google.com/group/oauth
422
+
423
+ The OAuth Ruby Gem home page is http://oauth.rubyforge.org
424
+
425
+ Please help documentation, patches and testing.
426
+
427
+ Copyright (c) 2007-2010 Pelle Braendgaard and contributors, released under the MIT license