panjiva-oauth-plugin 0.4.1

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