houston-oauth-plugin 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (172) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +12 -0
  3. data/CHANGELOG +187 -0
  4. data/Gemfile +27 -0
  5. data/Guardfile +8 -0
  6. data/MIT-LICENSE +20 -0
  7. data/README.rdoc +542 -0
  8. data/Rakefile +1 -0
  9. data/UPGRADE.rdoc +21 -0
  10. data/generators/oauth_consumer/USAGE +10 -0
  11. data/generators/oauth_consumer/oauth_consumer_generator.rb +52 -0
  12. data/generators/oauth_consumer/templates/consumer_token.rb +11 -0
  13. data/generators/oauth_consumer/templates/controller.rb +27 -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/index.html.slim +15 -0
  17. data/generators/oauth_consumer/templates/migration.rb +23 -0
  18. data/generators/oauth_consumer/templates/oauth_config.rb +73 -0
  19. data/generators/oauth_consumer/templates/show.html.erb +7 -0
  20. data/generators/oauth_consumer/templates/show.html.haml +8 -0
  21. data/generators/oauth_consumer/templates/show.html.slim +8 -0
  22. data/generators/oauth_provider/USAGE +20 -0
  23. data/generators/oauth_provider/lib/insert_routes.rb +67 -0
  24. data/generators/oauth_provider/oauth_provider_generator.rb +127 -0
  25. data/generators/oauth_provider/templates/_form.html.erb +17 -0
  26. data/generators/oauth_provider/templates/_form.html.haml +21 -0
  27. data/generators/oauth_provider/templates/access_token.rb +16 -0
  28. data/generators/oauth_provider/templates/authorize.html.erb +14 -0
  29. data/generators/oauth_provider/templates/authorize.html.haml +16 -0
  30. data/generators/oauth_provider/templates/authorize_failure.html.erb +1 -0
  31. data/generators/oauth_provider/templates/authorize_failure.html.haml +1 -0
  32. data/generators/oauth_provider/templates/authorize_success.html.erb +1 -0
  33. data/generators/oauth_provider/templates/authorize_success.html.haml +1 -0
  34. data/generators/oauth_provider/templates/client_application.rb +57 -0
  35. data/generators/oauth_provider/templates/client_application_spec.rb +29 -0
  36. data/generators/oauth_provider/templates/client_application_test.rb +42 -0
  37. data/generators/oauth_provider/templates/client_applications.yml +23 -0
  38. data/generators/oauth_provider/templates/clients_controller.rb +52 -0
  39. data/generators/oauth_provider/templates/clients_controller_spec.rb +176 -0
  40. data/generators/oauth_provider/templates/clients_controller_test.rb +280 -0
  41. data/generators/oauth_provider/templates/controller.rb +23 -0
  42. data/generators/oauth_provider/templates/edit.html.erb +7 -0
  43. data/generators/oauth_provider/templates/edit.html.haml +4 -0
  44. data/generators/oauth_provider/templates/index.html.erb +43 -0
  45. data/generators/oauth_provider/templates/index.html.haml +39 -0
  46. data/generators/oauth_provider/templates/migration.rb +47 -0
  47. data/generators/oauth_provider/templates/new.html.erb +5 -0
  48. data/generators/oauth_provider/templates/new.html.haml +5 -0
  49. data/generators/oauth_provider/templates/oauth2_authorize.html.erb +16 -0
  50. data/generators/oauth_provider/templates/oauth2_authorize.html.haml +17 -0
  51. data/generators/oauth_provider/templates/oauth2_token.rb +20 -0
  52. data/generators/oauth_provider/templates/oauth2_token_spec.rb +52 -0
  53. data/generators/oauth_provider/templates/oauth2_verifier.rb +35 -0
  54. data/generators/oauth_provider/templates/oauth2_verifier_spec.rb +44 -0
  55. data/generators/oauth_provider/templates/oauth_nonce.rb +13 -0
  56. data/generators/oauth_provider/templates/oauth_nonce_spec.rb +24 -0
  57. data/generators/oauth_provider/templates/oauth_nonce_test.rb +26 -0
  58. data/generators/oauth_provider/templates/oauth_nonces.yml +13 -0
  59. data/generators/oauth_provider/templates/oauth_token.rb +30 -0
  60. data/generators/oauth_provider/templates/oauth_token_spec.rb +309 -0
  61. data/generators/oauth_provider/templates/oauth_token_test.rb +57 -0
  62. data/generators/oauth_provider/templates/oauth_tokens.yml +17 -0
  63. data/generators/oauth_provider/templates/request_token.rb +40 -0
  64. data/generators/oauth_provider/templates/show.html.erb +27 -0
  65. data/generators/oauth_provider/templates/show.html.haml +30 -0
  66. data/init.rb +1 -0
  67. data/install.rb +2 -0
  68. data/lib/generators/active_record/oauth_consumer_generator.rb +33 -0
  69. data/lib/generators/active_record/oauth_consumer_templates/consumer_token.rb +11 -0
  70. data/lib/generators/active_record/oauth_consumer_templates/migration.rb +20 -0
  71. data/lib/generators/active_record/oauth_provider_generator.rb +39 -0
  72. data/lib/generators/active_record/oauth_provider_templates/access_token.rb +16 -0
  73. data/lib/generators/active_record/oauth_provider_templates/client_application.rb +57 -0
  74. data/lib/generators/active_record/oauth_provider_templates/migration.rb +47 -0
  75. data/lib/generators/active_record/oauth_provider_templates/oauth2_token.rb +20 -0
  76. data/lib/generators/active_record/oauth_provider_templates/oauth2_verifier.rb +35 -0
  77. data/lib/generators/active_record/oauth_provider_templates/oauth_nonce.rb +13 -0
  78. data/lib/generators/active_record/oauth_provider_templates/oauth_token.rb +30 -0
  79. data/lib/generators/active_record/oauth_provider_templates/request_token.rb +40 -0
  80. data/lib/generators/erb/oauth_consumer_generator.rb +14 -0
  81. data/lib/generators/erb/oauth_consumer_templates/index.html.erb +29 -0
  82. data/lib/generators/erb/oauth_consumer_templates/show.html.erb +7 -0
  83. data/lib/generators/erb/oauth_provider_generator.rb +23 -0
  84. data/lib/generators/erb/oauth_provider_templates/_form.html.erb +17 -0
  85. data/lib/generators/erb/oauth_provider_templates/authorize.html.erb +14 -0
  86. data/lib/generators/erb/oauth_provider_templates/authorize_failure.html.erb +1 -0
  87. data/lib/generators/erb/oauth_provider_templates/authorize_success.html.erb +1 -0
  88. data/lib/generators/erb/oauth_provider_templates/edit.html.erb +7 -0
  89. data/lib/generators/erb/oauth_provider_templates/index.html.erb +43 -0
  90. data/lib/generators/erb/oauth_provider_templates/new.html.erb +5 -0
  91. data/lib/generators/erb/oauth_provider_templates/oauth2_authorize.html.erb +16 -0
  92. data/lib/generators/erb/oauth_provider_templates/show.html.erb +27 -0
  93. data/lib/generators/haml/oauth_consumer_generator.rb +21 -0
  94. data/lib/generators/haml/oauth_consumer_templates/index.html.haml +18 -0
  95. data/lib/generators/haml/oauth_consumer_templates/show.html.haml +8 -0
  96. data/lib/generators/haml/oauth_provider_generator.rb +28 -0
  97. data/lib/generators/haml/oauth_provider_templates/_form.html.haml +21 -0
  98. data/lib/generators/haml/oauth_provider_templates/authorize.html.haml +16 -0
  99. data/lib/generators/haml/oauth_provider_templates/authorize_failure.html.haml +1 -0
  100. data/lib/generators/haml/oauth_provider_templates/authorize_success.html.haml +1 -0
  101. data/lib/generators/haml/oauth_provider_templates/edit.html.haml +4 -0
  102. data/lib/generators/haml/oauth_provider_templates/index.html.haml +39 -0
  103. data/lib/generators/haml/oauth_provider_templates/new.html.haml +5 -0
  104. data/lib/generators/haml/oauth_provider_templates/oauth2_authorize.html.haml +17 -0
  105. data/lib/generators/haml/oauth_provider_templates/show.html.haml +30 -0
  106. data/lib/generators/mongoid/oauth_consumer_generator.rb +15 -0
  107. data/lib/generators/mongoid/oauth_consumer_templates/consumer_token.rb +41 -0
  108. data/lib/generators/mongoid/oauth_provider_generator.rb +21 -0
  109. data/lib/generators/mongoid/oauth_provider_templates/access_token.rb +16 -0
  110. data/lib/generators/mongoid/oauth_provider_templates/client_application.rb +71 -0
  111. data/lib/generators/mongoid/oauth_provider_templates/oauth2_token.rb +20 -0
  112. data/lib/generators/mongoid/oauth_provider_templates/oauth2_verifier.rb +35 -0
  113. data/lib/generators/mongoid/oauth_provider_templates/oauth_nonce.rb +24 -0
  114. data/lib/generators/mongoid/oauth_provider_templates/oauth_token.rb +44 -0
  115. data/lib/generators/mongoid/oauth_provider_templates/request_token.rb +36 -0
  116. data/lib/generators/oauth_consumer/USAGE +11 -0
  117. data/lib/generators/oauth_consumer/oauth_consumer_generator.rb +31 -0
  118. data/lib/generators/oauth_consumer/templates/controller.rb +59 -0
  119. data/lib/generators/oauth_consumer/templates/oauth_config.rb +68 -0
  120. data/lib/generators/oauth_inflections.rb +6 -0
  121. data/lib/generators/oauth_plugin.rb +0 -0
  122. data/lib/generators/oauth_provider/USAGE +18 -0
  123. data/lib/generators/oauth_provider/oauth_provider_generator.rb +37 -0
  124. data/lib/generators/oauth_provider/templates/clients_controller.rb +52 -0
  125. data/lib/generators/oauth_provider/templates/controller.rb +23 -0
  126. data/lib/generators/rspec/oauth_provider_generator.rb +35 -0
  127. data/lib/generators/rspec/templates/client_application_spec.rb +29 -0
  128. data/lib/generators/rspec/templates/client_applications.yml +23 -0
  129. data/lib/generators/rspec/templates/clients_controller_spec.rb +176 -0
  130. data/lib/generators/rspec/templates/oauth2_token_spec.rb +52 -0
  131. data/lib/generators/rspec/templates/oauth2_verifier_spec.rb +44 -0
  132. data/lib/generators/rspec/templates/oauth_nonce_spec.rb +24 -0
  133. data/lib/generators/rspec/templates/oauth_nonces.yml +13 -0
  134. data/lib/generators/rspec/templates/oauth_token_spec.rb +309 -0
  135. data/lib/generators/rspec/templates/oauth_tokens.yml +17 -0
  136. data/lib/generators/slim/oauth_consumer_generator.rb +21 -0
  137. data/lib/generators/slim/oauth_consumer_templates/index.html.slim +15 -0
  138. data/lib/generators/slim/oauth_consumer_templates/show.html.slim +8 -0
  139. data/lib/generators/test_unit/oauth_provider_generator.rb +33 -0
  140. data/lib/generators/test_unit/templates/client_application_test.rb +42 -0
  141. data/lib/generators/test_unit/templates/client_applications.yml +23 -0
  142. data/lib/generators/test_unit/templates/clients_controller_test.rb +280 -0
  143. data/lib/generators/test_unit/templates/oauth_nonce_test.rb +26 -0
  144. data/lib/generators/test_unit/templates/oauth_nonces.yml +13 -0
  145. data/lib/generators/test_unit/templates/oauth_token_test.rb +57 -0
  146. data/lib/generators/test_unit/templates/oauth_tokens.yml +17 -0
  147. data/lib/oauth-plugin.rb +24 -0
  148. data/lib/oauth-plugin/version.rb +5 -0
  149. data/lib/oauth/controllers/application_controller_methods.rb +140 -0
  150. data/lib/oauth/controllers/consumer_controller.rb +153 -0
  151. data/lib/oauth/controllers/provider_controller.rb +181 -0
  152. data/lib/oauth/models/consumers/service_loader.rb +28 -0
  153. data/lib/oauth/models/consumers/services/agree2_token.rb +15 -0
  154. data/lib/oauth/models/consumers/services/fireeagle_token.rb +39 -0
  155. data/lib/oauth/models/consumers/services/google_token.rb +21 -0
  156. data/lib/oauth/models/consumers/services/oauth2_token.rb +49 -0
  157. data/lib/oauth/models/consumers/services/opentransact_token.rb +15 -0
  158. data/lib/oauth/models/consumers/services/picomoney_token.rb +17 -0
  159. data/lib/oauth/models/consumers/services/twitter_token.rb +24 -0
  160. data/lib/oauth/models/consumers/simple_client.rb +50 -0
  161. data/lib/oauth/models/consumers/token.rb +121 -0
  162. data/lib/oauth/provider/authorizer.rb +83 -0
  163. data/lib/oauth/rack/oauth_filter.rb +97 -0
  164. data/oauth-plugin.gemspec +40 -0
  165. data/rails/init.rb +1 -0
  166. data/spec/dummy_provider_models.rb +53 -0
  167. data/spec/oauth/provider/authorizer_spec.rb +202 -0
  168. data/spec/rack/oauth_filter_spec.rb +244 -0
  169. data/spec/spec_helper.rb +3 -0
  170. data/tasks/oauth_tasks.rake +4 -0
  171. data/uninstall.rb +1 -0
  172. metadata +373 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7a59ec2d81c1b9a493f85885c0b33615ce0e46f7
4
+ data.tar.gz: e6ed0f0f02d9db8b66c51bab808bb000f7744af3
5
+ SHA512:
6
+ metadata.gz: c5061e6bd05ae4e54964c10d34b999e77a365bccdec6e36f20cb8b8bbe272374b1519f34b3fc7bfe5c1459bdbfa9d842a3b5a1fd1a9b1313e1704e383cd3a920
7
+ data.tar.gz: 0a3b902aad77dc5959074926843b42ca9f6c21264761ee7e82b31b7bcabdfdcfecd9f726a33aa501a2404b050956935cf56d9328994ab5c934386c100b0735f2
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ doc
2
+ pkg
3
+ *.log
4
+ .DS_Store
5
+ .svn
6
+ *.gem
7
+ .bundle
8
+ .swp
9
+ .idea
10
+ .rvmrc
11
+
12
+ Gemfile.lock
data/CHANGELOG ADDED
@@ -0,0 +1,187 @@
1
+ 0.5.1
2
+ - Support slim templates for consumer [pelle]
3
+ - Add via argument to match routes to support 4.0 [pelle]
4
+ 0.5.0
5
+ - Make compatible with Rails 4 [tomhughes]
6
+ - Added support for RefreshTokens [RubenHoms]
7
+ - allow? should return false when token is not found [thetizzo]
8
+ - add license to gemspec [jordimassaguerpla]
9
+ - update documentation for Rails 2.x [yann]
10
+ 0.4.1
11
+ - Security fix for OAuth1 provider. Please upgrade if you're using any 0.4 version. Thanks to [tomhughes]
12
+ - Limit index size in ConsumerToken migration to deal with very large tokens [devainandor]
13
+ - Accept ancient OAuth2 Token token=asfavasd like tokens. Just for complete compatibility. [pelle]
14
+ - oauth2 errors should return http 400 [pelle]
15
+ 0.4.0
16
+ - fix migrations to use expires_at instead of valid_to [pelle]
17
+ - add force parameter for forcing token refresh [afeld]
18
+ - make it work in rails 2x [Kimtaro]
19
+ - Use 0.5+ OAuth2 gem [kookster]
20
+ - prevent addition of ? marks to callback url when not needed [kookster]
21
+ - make .credentials accessible to TwitterToken [afeld]
22
+ 0.4.0-rc2
23
+ - Better OAuth2 support.
24
+ - Refactored authorizer into a Authorizer object which is now better tested
25
+ 0.4.0-rc1
26
+ PLEASE help test this so we can mark it as final
27
+ - Update to OAuth2 draft 22 which is likely the final release. [pelle] ACTION REQUIRED BY YOU, see README.
28
+ - Update forms to work with rails 3.1 [morgz]
29
+ - Allow nil callbacks for oob in OAuth 1.0a [Shaliko Usubov]
30
+ - OAuthFilter:oauth2_token to rejects headers that explicitly state oauth_version="1.0" [KentonWhite]
31
+ 0.4.0-pre7
32
+ - OAuth 1 requests using query or form encoded parameters where being interpreted as OAuth2 [pelleb]
33
+ - OAuth 2 requests were not checking for invalidated tokens. Please upgrade for this if you offer OAuth 2 [rymai]
34
+ - Handle case where credentials[:options] in consumer plugin was nil [marnen]
35
+ - Better facebook example [marnen]
36
+ 0.4.0-pre6
37
+ - fixes issue with erb generator in rails 3 [pelleb]
38
+ - various cleanups in generators [akonan]
39
+ 0.4.0-pre5
40
+ - protect oauth consumer relay with :expose configuration option. It's off by default. [pelle]
41
+ - Reenable twitter client. It is now configurable for twitter tokens. :client=>:twitter_gem or :oauth_gem [pelle]
42
+ - fix issues with new consumer tokens [afeld]
43
+ - More forgiving about oob callback values[chrisrhoden]
44
+ - Update Twitter consumer to use latest Twitter Gem [afeld]
45
+ - removed portable_contacts client from Google Token [p8]
46
+ - Fixes various mongoid issues [3en]
47
+ - Adds oauth2 consumer support
48
+ - Fixes oauth2 provider. parameter should be redirect_uri not redirect_url [Kimtaro]
49
+ - Most core OAuth functionality is being put into OAuthFilter. This means Rails 2.3 and above only
50
+ 0.4.0-pre4
51
+ - Fixed bug when creating a new user from a new consumer token
52
+ - Fix typo in consumer token [krasio]
53
+ - Fix issue with mongoid not supporting find_by_x style queries. [3en]
54
+ 0.4.0-pre3
55
+ - Experimental rack filter for OAuth 1.0a:
56
+ see lib/oauth/rack/oauth_filter.rb for details
57
+ 0.4.0-pre2
58
+ - mongoid defaults to being embedded
59
+ - new :auto_login option in oauth_config.rb which lets you use eg. twitter as a primary authentication method
60
+ 0.4.0-pre1
61
+ - mongoid support in rails 3 [Alexander Semyonov]
62
+ - OAUTH 2.0 authorization_code and password grant types
63
+ - Supports OAuth 2.0 draft 10 (Note this is incompatible with previous drafts)
64
+ - Refactored application_controller_methods to be a lot less intrusive
65
+ - Increased default token and key size in anticipation of OAuth2 support
66
+ - Rails 3 support
67
+ - Rails 3 generators [Paul Rosiana] and patches by [Alexander Flatter]
68
+ - Modularized Rails 3 generators [Alexander Semyonov]
69
+ - Callback urls now allow query parameters. Multiple patches but I used [Unk]'s.
70
+ 10/08/2009
71
+ 0.3.14
72
+ - Fixed the class generation when you have a custom token defined. [Brian Morearty]
73
+ 10/05/2009
74
+ 0.3.13
75
+ - Got rid of yahoo token. To support it correctly requires way too much work. Let them suffer the consequences of their decissions.
76
+ - GoogleToken now uses portablecontacts gem
77
+ 9/30/2009
78
+ 0.3.12
79
+ - Added a simple PortableContacts adapter for GoogleToken
80
+ - Added a SimpleClient wrapper to provide really simple wrapper for OAuth based json web services
81
+ - Increased token size in consumer_tokens table because of Yahoo's oversized tokens
82
+ - Added support for Yahoo
83
+ - Added support for Google (Boon Low)
84
+ 9/26/2009
85
+ 0.3.11
86
+ - Moved twitter tokens dependency back to regular twitter gem
87
+ 7/29/2009
88
+ 0.3.10
89
+ - Closed blocks in erb template (jcrosby) while pelle is hiding under his desk
90
+ - Handled error case on authorize with non existent token
91
+ - Fixed Agree2 token
92
+ - Security Fix: Only skip verify_authenticity_token for specific oauth token requests in provider controller
93
+ 7/25/2009
94
+ 0.3.9
95
+ - Added an Index to oauth consumers controller. Rerun generator to create index template
96
+ - Added invalidate action to provider, which allows a token to invalidate itself /oauth/invalidate
97
+ - Added capabilities action to provider. Lets you expand to allow auto discovery of permissions and services that token provides.
98
+ - Can override how authorize form indicates an authorization. To get around ugly checkbox
99
+
100
+ def user_authorizes_token?
101
+ params[:commit] == 'Authorize'
102
+ end
103
+
104
+ 7/23/2009
105
+ 0.3.8
106
+ - Fixed Gem Plugins Loading
107
+ 7/21/2009
108
+ 0.3.7
109
+ - A blushing Pelle adds a missing file
110
+ 0.3.6
111
+ - Twitter, Agree2 and FireEagle tokens are working in consumer.
112
+ 0.3.5
113
+ - made it a gem
114
+ - more thorough tests of OAuth 1.0 consumer
115
+ - Add support for a OAUTH_10_SUPPORT constant to switch on support for OAuth 1.0 in provider
116
+ 7/19/2009
117
+ - Added support for OAuth 1.0 consumers (nov)
118
+ 7/17/2009
119
+ - Added back support for OAuth 1.0 for providers (nov)
120
+ 7/14/2009
121
+ - Added OAuth Consumer generator
122
+ - Moved oauth controller code to a module to make it easier to upgrade in the future
123
+ 7/11/2009
124
+ - Added support for OAuth version 1.0a
125
+ - Added haml support
126
+ - Improved OAuth Client Controller gui (alec-c4)
127
+ 2/11/2009
128
+ - Fixed escaping error and file path error in the generator simultaneously reported and fixed by Ivan Valdes and Mike Demers thanks
129
+
130
+ 2/9/2009
131
+ - Fixed compatibility issue with OAuth Gem 3.1 (wr0ngway and aeden)
132
+ - Added Test:Unit tests to generator (Ed Hickey)
133
+ - added missing oauth_clients/edit.html.erb view template (Ed Hickey)
134
+ - added missing :oauth_clients resource route in USAGE (Ed Hickey)
135
+ - Don't throw NPE it token is not in db (Haruska)
136
+ - Cleaned up whitespace (bricolage, Nicholas Nam)
137
+ - Fixed bug in default verify_oauth_signature (igrigorik)
138
+ - Doc fixes (skippy)
139
+
140
+ 6/23/2008
141
+
142
+ - Split OAuth controller into two parts: OAuth and OAuth clients. [jcrosby]
143
+
144
+ revision 31
145
+
146
+ - patch that fixes a problem in oauth_required from Hannes Tyden and Sean Treadway from SoundCloud. Thanks.
147
+
148
+ revision 30
149
+
150
+ - updated to use oauth gem 0.2.1
151
+
152
+
153
+ revision 23
154
+
155
+ - removed all core libraries from plugin. They are now in the oauth gem.
156
+
157
+ # oauth-plugin-pre-gem Branch created
158
+
159
+ revision 18
160
+ - added a generator for creation oauth_providers
161
+
162
+ revision 12
163
+ - the bug with post and put has now been fixed.
164
+ - better documentation
165
+
166
+ revision 9
167
+ - added a test helper. Include OAuth::TestHelper in your tests or specs to mock incoming requests
168
+
169
+ revision: 8
170
+ - moved tests into oauth folder and renamed them to make them work with autotest by default
171
+ - Refactored the request methods to make them more flexible and ready for integrating with ActiveResource
172
+ - 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.
173
+
174
+ revision: 7
175
+
176
+ - 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
177
+
178
+ revision: 6
179
+
180
+ - Throws InsecureSignatureMethod exception if attempting to use straight sha1 or md5.
181
+ - Disables plaintext signature over http (throws an InsecureSignatureMethod)
182
+ - Better testing of signature methods - the prior tests were seriously flawed.
183
+
184
+ revision: 5
185
+
186
+ - Removed support for sha1 and md5
187
+ - Implemented draft 6 support of OAuth removing secrets from base string
data/Gemfile ADDED
@@ -0,0 +1,27 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in oauth-plugin.gemspec
4
+ gemspec
5
+
6
+ require 'rbconfig'
7
+
8
+ platforms :ruby do
9
+ if RbConfig::CONFIG['target_os'] =~ /darwin/i
10
+ gem 'rb-fsevent'
11
+ gem 'growl'
12
+ end
13
+ if RbConfig::CONFIG['target_os'] =~ /linux/i
14
+ gem 'rb-inotify', '>= 0.5.1'
15
+ gem 'libnotify', '~> 0.1.3'
16
+ end
17
+ end
18
+
19
+ platforms :jruby do
20
+ if RbConfig::CONFIG['target_os'] =~ /darwin/i
21
+ gem 'growl'
22
+ end
23
+ if RbConfig::CONFIG['target_os'] =~ /linux/i
24
+ gem 'rb-inotify', '>= 0.5.1'
25
+ gem 'libnotify', '~> 0.1.3'
26
+ end
27
+ end
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, :cli => '-c' do
5
+ watch(%r{^spec/(.*)_spec.rb})
6
+ watch(%r{^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,542 @@
1
+ = OAuth Plugin
2
+
3
+ This is a plugin for implementing OAuth Providers and Consumers in Rails applications.
4
+
5
+ We support the revised OAuth 1.0a specs at:
6
+
7
+ http://tools.ietf.org/html/rfc5849
8
+
9
+ As well as support for OAuth 2.0:
10
+
11
+ http://tools.ietf.org/html/draft-ietf-oauth-v2-22
12
+
13
+ Find out more on the OAuth site at:
14
+
15
+ http://oauth.net
16
+
17
+ == IMPORTANT note for people upgrading the provider
18
+
19
+ There are several changes to the latest OAuth 2.0 spec which requires a couple of changes to 2 models which you are REQUIRED to update manually if you are supporting OAuth2.
20
+
21
+ https://github.com/pelle/oauth-plugin/blob/master/lib/generators/active_record/oauth_provider_templates/oauth2_token.rb
22
+
23
+ class Oauth2Token < AccessToken
24
+ attr_accessor :state
25
+ def as_json(options={})
26
+ d = {:access_token=>token, :token_type => 'bearer'}
27
+ d[:expires_in] = expires_in if expires_at
28
+ d
29
+ end
30
+
31
+ def to_query
32
+ q = "access_token=#{token}&token_type=bearer"
33
+ q << "&state=#{URI.escape(state)}" if @state
34
+ q << "&expires_in=#{expires_in}" if expires_at
35
+ q << "&scope=#{URI.escape(scope)}" if scope
36
+ q
37
+ end
38
+
39
+ def expires_in
40
+ expires_at.to_i - Time.now.to_i
41
+ end
42
+ end
43
+
44
+
45
+ https://github.com/pelle/oauth-plugin/blob/master/lib/generators/active_record/oauth_provider_templates/oauth2_verifier.rb
46
+
47
+ class Oauth2Verifier < OauthToken
48
+ validates_presence_of :user
49
+ attr_accessor :state
50
+
51
+ def exchange!(params={})
52
+ OauthToken.transaction do
53
+ token = Oauth2Token.create! :user=>user,:client_application=>client_application, :scope => scope
54
+ invalidate!
55
+ token
56
+ end
57
+ end
58
+
59
+ def code
60
+ token
61
+ end
62
+
63
+ def redirect_url
64
+ callback_url
65
+ end
66
+
67
+ def to_query
68
+ q = "code=#{token}"
69
+ q << "&state=#{URI.escape(state)}" if @state
70
+ q
71
+ end
72
+
73
+ protected
74
+
75
+ def generate_keys
76
+ self.token = OAuth::Helper.generate_key(20)[0,20]
77
+ self.expires_at = 10.minutes.from_now
78
+ self.authorized_at = Time.now
79
+ end
80
+
81
+ end
82
+
83
+ There are matching specs for these which you may want to move into your project as well.
84
+
85
+ == Requirements
86
+
87
+ 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.
88
+
89
+ gem install oauth
90
+
91
+ == Installation (Rails 3.0)
92
+
93
+ Add the plugin to your Gemfile:
94
+
95
+ gem "oauth-plugin", "~> 0.4.0"
96
+
97
+ And install it:
98
+
99
+ bundle install
100
+
101
+ == Installation (Rails 2.x)
102
+
103
+ The plugin can now be installed as an gem from github, which is the easiest way to keep it up to date.
104
+
105
+ gem install oauth-plugin --pre
106
+
107
+ You should add the following in the gem dependency section of environment.rb
108
+
109
+ config.gem "oauth"
110
+ config.gem "oauth-plugin"
111
+
112
+ Alternatively you can install it in vendors/plugin:
113
+
114
+ script/plugin install git://github.com/pelle/oauth-plugin.git
115
+
116
+ The Generator currently creates code (in particular views) that only work in Rails 2 and 3.
117
+
118
+ It should not be difficult to manually modify the code to work on Rails 1.2.x
119
+
120
+ I think the only real issue is that the views have .html.erb extensions. So these could theoretically just be renamed to .rhtml.
121
+
122
+ 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.
123
+
124
+ == OAuth Provider generator (Rails 3)
125
+
126
+ This currently supports rspec, test_unit, haml, erb, active_record and mongoid:
127
+
128
+ rails g oauth_provider
129
+
130
+ This generates OAuth and OAuth client controllers as well as the required models.
131
+
132
+ It requires an authentication framework such as acts_as_authenticated, restful_authentication or restful_open_id_authentication. It also requires Rails 2.0.
133
+
134
+ === INSTALL RACK FILTER (NEW)
135
+
136
+ A big change over previous versions is that we now use a rack filter. You have to install this in your application.rb file:
137
+
138
+ require 'oauth/rack/oauth_filter'
139
+ config.middleware.use OAuth::Rack::OAuthFilter
140
+
141
+
142
+ === Generator Options
143
+
144
+ The generator supports the defaults you have created in your application.rb file. eg:
145
+
146
+ config.generators do |g|
147
+ g.orm :mongoid
148
+ g.template_engine :haml
149
+ g.test_framework :rspec
150
+ end
151
+
152
+ === User Model
153
+
154
+ Add the following lines to your user model:
155
+
156
+ has_many :client_applications
157
+ has_many :tokens, :class_name => "OauthToken", :order => "authorized_at desc", :include => [:client_application]
158
+
159
+ == OAuth Provider generator (Rails 2)
160
+
161
+ While it isn't very flexible at the moment there is an oauth_provider generator which you can use like this:
162
+
163
+ ./script/generate oauth_provider
164
+
165
+ This generates OAuth and OAuth client controllers as well as the required models.
166
+
167
+ It requires an authentication framework such as acts_as_authenticated, restful_authentication or restful_open_id_authentication. It also requires Rails 2.0.
168
+
169
+ === INSTALL RACK FILTER (NEW)
170
+
171
+ A big change over previous versions is that we now use a rack filter. You have to install this in your config/environment.rb file:
172
+
173
+ require 'oauth/rack/oauth_filter'
174
+ config.middleware.use OAuth::Rack::OAuthFilter
175
+
176
+ === Generator Options
177
+
178
+ 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:
179
+
180
+ ./script/generate oauth_provider --test-unit --haml
181
+
182
+ These can of course be used individually as well.
183
+
184
+ === User Model
185
+
186
+ Add the following lines to your user model:
187
+
188
+ has_many :client_applications
189
+ has_many :tokens, :class_name => "OauthToken", :order => "authorized_at desc", :include => [:client_application]
190
+
191
+ === Migrate database
192
+
193
+ The database is defined in:
194
+
195
+ db/migrate/XXX_create_oauth_tables.rb
196
+
197
+ Run them as any other normal migration in rails with:
198
+
199
+ rake db:migrate
200
+
201
+ == Upgrading from OAuth 1.0 to OAuth 1.0a
202
+
203
+ 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:
204
+
205
+ === Add a migration
206
+
207
+ You need to add a migration:
208
+
209
+ script/generate migration upgrade_oauth
210
+
211
+ Make it look like this:
212
+
213
+ class UpgradeOauth < ActiveRecord::Migration
214
+ def self.up
215
+ add_column :oauth_tokens, :callback_url, :string
216
+ add_column :oauth_tokens, :verifier, :string, :limit => 20
217
+ end
218
+
219
+ def self.down
220
+ remove_column :oauth_tokens, :callback_url
221
+ remove_column :oauth_tokens, :verifier
222
+ end
223
+ end
224
+
225
+ === Change code
226
+
227
+ There are changes to the following files:
228
+
229
+ app/models/client_application.rb
230
+ app/models/request_token.rb
231
+ app/controllers/oauth_controller.rb
232
+
233
+ === Changes in client_application.rb
234
+
235
+ Add the following towards the top of the model class
236
+
237
+ attr_accessor :token_callback_url
238
+
239
+ Then change the create_request_token method to the following:
240
+
241
+ def create_request_token
242
+ RequestToken.create :client_application => self, :callback_url => token_callback_url
243
+ end
244
+
245
+ === Changes in request_token.rb
246
+
247
+ 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.
248
+
249
+ Make sure it looks like this:
250
+
251
+ class RequestToken < OauthToken
252
+
253
+ attr_accessor :provided_oauth_verifier
254
+
255
+ def authorize!(user)
256
+ return false if authorized?
257
+ self.user = user
258
+ self.authorized_at = Time.now
259
+ self.verifier=OAuth::Helper.generate_key(16)[0,20] unless oauth10?
260
+ self.save
261
+ end
262
+
263
+ def exchange!
264
+ return false unless authorized?
265
+ return false unless oauth10? || verifier == provided_oauth_verifier
266
+
267
+ RequestToken.transaction do
268
+ access_token = AccessToken.create(:user => user, :client_application => client_application)
269
+ invalidate!
270
+ access_token
271
+ end
272
+ end
273
+
274
+ def to_query
275
+ if oauth10?
276
+ super
277
+ else
278
+ "#{super}&oauth_callback_confirmed = true"
279
+ end
280
+ end
281
+
282
+ def oob?
283
+ self.callback_url == 'oob'
284
+ end
285
+
286
+ def oauth10?
287
+ (defined? OAUTH_10_SUPPORT) && OAUTH_10_SUPPORT && self.callback_url.blank?
288
+ end
289
+
290
+ end
291
+
292
+ === Changes in oauth_controller
293
+
294
+ 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.
295
+
296
+ def authorize
297
+ @token = ::RequestToken.find_by_token params[:oauth_token]
298
+ unless @token.invalidated?
299
+ if request.post?
300
+ if params[:authorize] == '1'
301
+ @token.authorize!(current_user)
302
+ if @token.oauth10?
303
+ @redirect_url = params[:oauth_callback] || @token.client_application.callback_url
304
+ else
305
+ @redirect_url = @token.oob? ? @token.client_application.callback_url : @token.callback_url
306
+ end
307
+
308
+ if @redirect_url
309
+ if @token.oauth10?
310
+ redirect_to "#{@redirect_url}?oauth_token=#{@token.token}"
311
+ else
312
+ redirect_to "#{@redirect_url}?oauth_token=#{@token.token}&oauth_verifier=#{@token.verifier}"
313
+ end
314
+ else
315
+ render :action => "authorize_success"
316
+ end
317
+ elsif params[:authorize] == "0"
318
+ @token.invalidate!
319
+ render :action => "authorize_failure"
320
+ end
321
+ end
322
+ else
323
+ render :action => "authorize_failure"
324
+ end
325
+ end
326
+
327
+ Alternatively if you haven't customized your controller you can replace the full controller with this:
328
+
329
+ require 'oauth/controllers/provider_controller'
330
+ class OauthController < ApplicationController
331
+ include OAuth::Controllers::ProviderController
332
+ end
333
+
334
+ This way the controller will automatically include bug fixes in future versions of the plugin.
335
+
336
+ The rest of the changes are in the plugin and will be automatically be included.
337
+
338
+ *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.
339
+
340
+ === Supporting old OAuth 1.0 clients
341
+
342
+ 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.
343
+
344
+ For legacy OAUTH 1.0 support add the following constant in your environment.rb
345
+
346
+ OAUTH_10_SUPPORT = true
347
+
348
+ 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.
349
+
350
+ == Protecting your actions
351
+
352
+ 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.
353
+
354
+ If you want to give oauth access to everything a registered user can do, just replace the filter you have in your controllers with:
355
+
356
+ before_filter :login_or_oauth_required
357
+
358
+ If you want to restrict consumers to the index and show methods of your controller do the following:
359
+
360
+ before_filter :login_required, :except => [:show,:index]
361
+ before_filter :login_or_oauth_required, :only => [:show,:index]
362
+
363
+ If you have an action you only want used via oauth:
364
+
365
+ before_filter :oauth_required
366
+
367
+ You can also use this method in your controller:
368
+
369
+ oauthenticate :strategies => :token , :interactive => false
370
+
371
+ All of these places the tokens user in current_user as you would expect. It also exposes the following methods:
372
+
373
+ * current_token - for accessing the token used to authorize the current request
374
+ * current_client_application - for accessing information about which consumer is currently accessing your request
375
+
376
+ 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.
377
+
378
+ == OAuth Consumer generator
379
+
380
+ 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.
381
+
382
+ To run it in Rails 3 simply run:
383
+
384
+ rails g oauth_consumer
385
+
386
+ In previous versions:
387
+
388
+ ./script/generate oauth_consumer
389
+
390
+ This generates the OauthConsumerController as well as the ConsumerToken model.
391
+
392
+ === Generator Options (Rails 2)
393
+
394
+ By default the generator generates ERB templates. The generator can instead create HAML templates. To do this use the following options:
395
+
396
+ ./script/generate oauth_consumer --haml
397
+
398
+ Rails 3 respects your application defaults, see the oauth provider generator section above for more info.
399
+
400
+ === Configuration
401
+
402
+ All configuration of applications is done in
403
+
404
+ config/initializers/oauth_consumers.rb
405
+
406
+ 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.
407
+
408
+ OAUTH_CREDENTIALS = {
409
+ :twitter => {
410
+ :key => "key",
411
+ :secret => "secret",
412
+ :client => :twitter_gem, # :twitter_gem or :oauth_gem (defaults to :twitter_gem)
413
+ :expose => false, # set to true to expose client via the web
414
+ },
415
+ :agree2 => {
416
+ :key => "key",
417
+ :secret => "secret",
418
+ :expose => false, # set to true to expose client via the web
419
+ },
420
+ :hour_feed => {
421
+ :key => "",
422
+ :secret => "",
423
+ :options = {
424
+ :site => "http://hourfeed.com"
425
+ }
426
+ },
427
+ :nu_bux => {
428
+ :key => "",
429
+ :secret => "",
430
+ :super_class => "OpenTransactToken", # if a OAuth service follows a particular standard
431
+ # with a token implementation you can set the superclass
432
+ # to use
433
+ :options => {
434
+ :site => "http://nubux.heroku.com"
435
+ }
436
+ }
437
+ }
438
+
439
+ 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
440
+
441
+ :key, :secret are required as well as :options[:site] etc. for non custom ConsumerToken services.
442
+
443
+ === ConsumerToken models
444
+
445
+ For each site setup in the OAUTH_CREDENTIALS hash the plugin goes through and loads or creates a new model class that subclasses ConsumerToken.
446
+
447
+ 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.
448
+
449
+ This allows you to add a has_one association in your user model:
450
+
451
+ has_one :fire_eagle, :class_name => "FireEagleToken", :dependent => :destroy
452
+
453
+ And you could do:
454
+
455
+ @location = @user.fire_eagle.client.location
456
+
457
+ 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
458
+
459
+ If you are using Mongoid you want to add an embeds_many association in your user model:
460
+
461
+ embeds_many :consumer_tokens
462
+
463
+ === Custom ConsumerToken models
464
+
465
+ 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.
466
+
467
+ Currently we provide the following semi tested tokens wrappers:
468
+
469
+ * FireEagle
470
+ * Twitter
471
+ * Agree2
472
+
473
+ These can be found in lib/oauth/models/consulers/services. Contributions will be warmly accepted for your favorite OAuth service.
474
+
475
+ === The OauthConsumerController
476
+
477
+ To connect a user to an external service link or redirect them to:
478
+
479
+ /oauth_consumers/[SERVICE_NAME]
480
+
481
+ 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:
482
+
483
+ /oauth_consumers/[SERVICE_NAME]/callback
484
+
485
+ You can specify this url to the service you're calling when you register, but it will automatically be sent along anyway.
486
+
487
+ === Expose client
488
+
489
+ 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:
490
+
491
+ OAUTH_CREDENTIALS = {
492
+ :twitter => {
493
+ :key => "key",
494
+ :secret => "secret",
495
+ :client => :oauth_gem, # :twitter_gem or :oauth_gem (defaults to :twitter_gem)
496
+ :expose => true # set to true to expose client via the web
497
+ }
498
+
499
+ Once the user has authorized your application, you can access the client APIs via:
500
+
501
+ /oauth_consumers/[SERVICE_NAME]/client/[ENDPOINT]
502
+
503
+ 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.
504
+
505
+ /oauth_consumers/google/client/calendar/feeds/default?alt=jsonc
506
+
507
+ As another example, to get my Twitter info as XML (available at "https://api.twitter.com/1/users/show.xml?screen_name=pelleb"), use:
508
+
509
+ /oauth_consumers/twitter/client/1/users/show.xml?screen_name=pelleb
510
+
511
+ === Migrate database
512
+
513
+ The database is defined in:
514
+
515
+ db/migrate/XXX_create_oauth_consumer_tokens.rb
516
+
517
+ Run them as any other normal migration in rails with:
518
+
519
+ rake db:migrate
520
+
521
+ == Contribute and earn OAuth Karma
522
+
523
+ Anyone who has a commit accepted into the official oauth-plugin git repo is awarded OAuthKarma:
524
+
525
+ https://picomoney.com/oauth-karma/accounts
526
+
527
+
528
+ == More
529
+
530
+ The Mailing List for all things OAuth in Ruby is:
531
+
532
+ http://groups.google.com/group/oauth-ruby
533
+
534
+ The Mailing list for everything else OAuth is:
535
+
536
+ http://groups.google.com/group/oauth
537
+
538
+ The OAuth Ruby Gem home page is http://oauth.rubyforge.org
539
+
540
+ Please help documentation, patches and testing.
541
+
542
+ Copyright (c) 2007-2011 Pelle Braendgaard and contributors, released under the MIT license