oauth2_provider 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. data/CHANGELOG +306 -0
  2. data/HACKING.textile +45 -0
  3. data/NOTICE.textile +6 -0
  4. data/README.textile +11 -3
  5. data/WHAT_IS_OAUTH.textile +165 -0
  6. data/app/controllers/oauth_authorize_controller.rb +69 -0
  7. data/app/controllers/oauth_clients_controller.rb +79 -0
  8. data/app/controllers/oauth_token_controller.rb +59 -0
  9. data/app/controllers/oauth_user_tokens_controller.rb +61 -0
  10. data/app/models/oauth2/provider/oauth_authorization.rb +4 -0
  11. data/app/models/oauth2/provider/oauth_client.rb +14 -3
  12. data/app/views/{oauth2/provider/layouts → layouts}/oauth_clients.html.erb +0 -0
  13. data/app/views/oauth_authorize/index.html.erb +17 -0
  14. data/app/views/oauth_clients/_form.html.erb +27 -0
  15. data/app/views/oauth_clients/edit.html.erb +7 -0
  16. data/app/views/oauth_clients/index.html.erb +53 -0
  17. data/app/views/oauth_clients/new.html.erb +7 -0
  18. data/app/views/{oauth2/provider/oauth_clients → oauth_clients}/show.html.erb +0 -0
  19. data/app/views/oauth_user_tokens/index.html.erb +28 -0
  20. data/config/routes.rb +15 -9
  21. data/generators/oauth2_provider/USAGE +12 -0
  22. data/generators/oauth2_provider/templates/config/initializers/oauth2_provider.rb +3 -0
  23. data/lib/ext/validatable_ext.rb +27 -0
  24. data/lib/oauth2/provider/a_r_datasource.rb +13 -1
  25. data/lib/oauth2/provider/application_controller_methods.rb +32 -20
  26. data/lib/oauth2/provider/configuration.rb +39 -0
  27. data/lib/oauth2/provider/in_memory_datasource.rb +8 -0
  28. data/lib/oauth2/provider/model_base.rb +59 -10
  29. data/lib/oauth2/provider/ssl_helper.rb +42 -0
  30. data/lib/oauth2/provider/transaction_helper.rb +24 -0
  31. data/lib/oauth2/provider/url_parser.rb +17 -0
  32. data/lib/oauth2_provider.rb +3 -6
  33. data/oauth2_provider.gemspec +15 -6
  34. metadata +81 -26
  35. data/app/controllers/oauth2/provider/oauth_authorize_controller.rb +0 -68
  36. data/app/controllers/oauth2/provider/oauth_clients_controller.rb +0 -56
  37. data/app/controllers/oauth2/provider/oauth_token_controller.rb +0 -58
  38. data/app/controllers/oauth2/provider/oauth_user_tokens_controller.rb +0 -29
  39. data/app/views/oauth2/provider/oauth_authorize/index.html.erb +0 -8
  40. data/app/views/oauth2/provider/oauth_clients/edit.html.erb +0 -20
  41. data/app/views/oauth2/provider/oauth_clients/index.html.erb +0 -28
  42. data/app/views/oauth2/provider/oauth_clients/new.html.erb +0 -21
  43. data/app/views/oauth2/provider/oauth_user_tokens/index.html.erb +0 -14
  44. data/tasks/gem.rake +0 -88
data/CHANGELOG CHANGED
@@ -1,3 +1,309 @@
1
+ [d5cc143 | Mon Feb 21 22:13:01 UTC 2011] Ketan Padegaonkar <KetanPadegaonkar@gmail.com>
2
+
3
+ * Move some files out of the way so they are not packaged as part of the build.
4
+
5
+ [d82fa79 | Mon Feb 21 22:01:42 UTC 2011] Ketan Padegaonkar <KetanPadegaonkar@gmail.com>
6
+
7
+ * Add development dependencies in the gemspec.
8
+
9
+ [59f625d | Mon Feb 21 21:35:50 UTC 2011] Ketan Padegaonkar <KetanPadegaonkar@gmail.com>
10
+
11
+ * Issue #8 - add gem dependency in gemspec.
12
+
13
+ https://github.com/ThoughtWorksStudios/oauth2_provider/issues/8
14
+
15
+ [48205b0 | Mon Feb 21 21:34:08 UTC 2011] Ketan Padegaonkar <KetanPadegaonkar@gmail.com>
16
+
17
+ * Fix the initializer as per https://github.com/ThoughtWorksStudios/oauth2_provider/issues/6
18
+
19
+ [184421a | Tue Feb 08 23:31:19 UTC 2011] Badrinath Janakiraman <Admin@arvo.corporate.thoughtworks.com>
20
+
21
+ * added the ssl ignore flag to application_controller methods
22
+
23
+ [0ccb704 | Tue Feb 08 20:19:08 UTC 2011] Badrinath Janakiraman <Admin@arvo.corporate.thoughtworks.com>
24
+
25
+ * change the logic which determines whether ssl checks should be enforced to use an independent boolean flag
26
+
27
+ [05ed98a | Tue Feb 08 19:25:08 UTC 2011] Badrinath Janakiraman <Admin@arvo.corporate.thoughtworks.com>
28
+
29
+ * Monkey patch AP request class to return true for :ssl? if DISABLE_OAUTH_SSL environment variable is set
30
+
31
+ [f623329 | Thu Jan 06 23:41:36 UTC 2011] Luau <luaupair@luau-pair-02.corporate.thoughtworks.com>
32
+
33
+ * make transaction on model base return the block yield result
34
+
35
+ [9d02bb9 | Thu Jan 06 22:47:34 UTC 2011] Luau <luaupair@luau-pair-02.corporate.thoughtworks.com>
36
+
37
+ * update model_base to make it sync with gadeget rendering server plugin
38
+
39
+ [cfd06e9 | Tue Jan 04 20:46:35 UTC 2011] Ketan Padegaonkar <KetanPadegaonkar@gmail.com>
40
+
41
+ * #193 - make the oauth plugin transaction safe by adding an around filter on the controller that sets up a transaction.
42
+
43
+ [a8319df | Mon Dec 20 19:18:15 UTC 2010] Ketan Padegaonkar <KetanPadegaonkar@gmail.com>
44
+
45
+ * Fix for #147 - "Click in the 'Do you wish to allow ...' line on the authorize screen causes the browser to authorize the oauth request". This was regressed in rev ea0e2e77.
46
+
47
+ [6de7348 | Sat Dec 18 00:10:41 UTC 2010] David Rice <djrice@phydeaux3.corporate.thoughtworks.com>
48
+
49
+ * rename oauth client help link keyname to something sensible
50
+
51
+ [9a6cc65 | Fri Dec 17 19:48:54 UTC 2010] Luau <luaupair@luau-pair-01.corporate.thoughtworks.com>
52
+
53
+ * fix bug #128
54
+
55
+ [26bf9ce | Fri Dec 17 19:02:10 UTC 2010] Luau <luaupair@luau-pair-01.corporate.thoughtworks.com>
56
+
57
+ * #162 make oauth_allowed using class inherit attributes
58
+
59
+ [8cc8796 | Tue Dec 14 21:52:27 UTC 2010] Luau <luaupair@luau-pair-02.corporate.thoughtworks.com>
60
+
61
+ * Remove SSL requirement on the oauth user tokens page. Also remove the token from being displayed in the web page.
62
+
63
+ [2a35528 | Tue Dec 14 20:21:04 UTC 2010] Luau <luaupair@luau-pair-02.corporate.thoughtworks.com>
64
+
65
+ * Do not try to parse a blank url.
66
+
67
+ [433e388 | Tue Dec 14 20:20:43 UTC 2010] Luau <luaupair@luau-pair-02.corporate.thoughtworks.com>
68
+
69
+ * Render an error message ont he oauth provider page when accessing the page over ssl, but ssl_base_url is not set.
70
+
71
+ [cdbb55b | Tue Dec 14 19:31:43 UTC 2010] Luau <luaupair@luau-pair-02.corporate.thoughtworks.com>
72
+
73
+ * Fix all that were broken because of the change in the way the ssl helper works with respect to redirects.
74
+
75
+ [5adf33b | Tue Dec 14 19:02:28 UTC 2010] Luau <luaupair@luau-pair-02.corporate.thoughtworks.com>
76
+
77
+ * Show the correct urls on the oauth clients page. These urls are generated using the base ssl site url instead of guessing it from the request params.
78
+
79
+ [6a683d1 | Tue Dec 14 01:47:31 UTC 2010] Luau <luaupair@luau-pair-02.corporate.thoughtworks.com>
80
+
81
+ * Change the ssl url generation to explicitly use ssl_base_url instead of guessing it from the request hostname.
82
+
83
+ [ea75b58 | Sat Dec 11 01:20:02 UTC 2010] Ketan Padegaonkar <KetanPadegaonkar@gmail.com>
84
+
85
+ * #192 - Do not allow oauth requests(using Authorization header) over plain text protocol.
86
+
87
+ [fc70f28 | Thu Dec 09 20:29:34 UTC 2010] Luau <luaupair@luau-pair-02.corporate.thoughtworks.com>
88
+
89
+ * Handle leading and trailing slashes in routes admin and user prefixes.
90
+
91
+ [4b3e151 | Wed Oct 27 20:06:25 UTC 2010] Ketan Padegaonkar <KetanPadegaonkar@gmail.com>
92
+
93
+ * Change the name and ID of the hidden field.
94
+
95
+ [2c04217 | Thu Dec 09 01:39:03 UTC 2010] Luau <luaupair@luau-pair-02.corporate.thoughtworks.com>
96
+
97
+ * #190 - Do not allow creating multiple oauth authorization codes for a user and client combination.
98
+
99
+ [4a4904f | Thu Dec 09 01:28:14 UTC 2010] Luau <luaupair@luau-pair-02.corporate.thoughtworks.com>
100
+
101
+ * #185 - Do not allow creating multiple oauth access tokens for a user and client combination.
102
+
103
+ [2f8fa3f | Wed Dec 08 01:04:49 UTC 2010] Luau <luaupair@luau-pair-02.corporate.thoughtworks.com>
104
+
105
+ * Some metaprogramming foo to extract configuration properties into a helper.
106
+
107
+ [6273ae6 | Tue Dec 07 23:44:32 UTC 2010] Luau <luaupair@luau-pair-02.corporate.thoughtworks.com>
108
+
109
+ * Explicitly add the namespace to avoid any conflicts.
110
+
111
+ [ec59f83 | Tue Dec 07 23:26:38 UTC 2010] Luau <luaupair@luau-pair-02.corporate.thoughtworks.com>
112
+
113
+ * Hide the environment variable for ssl port behind a configuration object. This will allow for registering a proc that can be evaluated at a later time.
114
+
115
+ [e14d225 | Tue Dec 07 22:24:18 UTC 2010] Luau <luaupair@luau-pair-02.corporate.thoughtworks.com>
116
+
117
+ * Add some tests around redirecting to ssl port if ssl is enabled. The port number is not put in the url if the port is 443.
118
+
119
+ [6d9789d | Wed Dec 01 23:14:16 UTC 2010] Luau <luaupair@luau-pair-02.corporate.thoughtworks.com>
120
+
121
+ * add a missing period for user token revoke flash message
122
+
123
+ [96dca17 | Wed Dec 01 22:22:05 UTC 2010] Luau <luaupair@luau-pair-02.corporate.thoughtworks.com>
124
+
125
+ * flash message for revoke user tokens
126
+
127
+ [cc996f0 | Wed Dec 01 22:14:04 UTC 2010] Luau <luaupair@luau-pair-02.corporate.thoughtworks.com>
128
+
129
+ * revoke and revoke_by_admin actions support a passed in redirect url
130
+
131
+ [083a2a7 | Wed Dec 01 21:51:21 UTC 2010] Luau <luaupair@luau-pair-02.corporate.thoughtworks.com>
132
+
133
+ * require validatable explicitly because const_missing not work correctly in thread safe mode
134
+
135
+ [fedc33f | Wed Dec 01 00:02:13 UTC 2010] David Rice <djrice@phydeaux3.corporate.thoughtworks.com>
136
+
137
+ * finish #122; admins can now delete all tokens belonging to a particular user
138
+
139
+ [b9d9ff2 | Tue Nov 30 23:32:41 UTC 2010] David Rice <djrice@phydeaux3.corporate.thoughtworks.com>
140
+
141
+ * #122 (sorta); provide admin function for deleting any token regardless of whether it is owned by currently logged in user
142
+
143
+ [85b5d20 | Tue Oct 26 20:59:02 UTC 2010] Ketan Padegaonkar <KetanPadegaonkar@gmail.com>
144
+
145
+ * Change styling on the oauth authorize page. This also fixes #147
146
+
147
+ [6ac0a39 | Wed Oct 20 17:58:36 UTC 2010] Jen Marley <jen.marley@gmail.com>
148
+
149
+ * updated h1 title to make 'client' to be plural
150
+
151
+ [85acd26 | Thu Oct 14 21:58:23 UTC 2010] Ketan Padegaonkar <KetanPadegaonkar@gmail.com>
152
+
153
+ * Add some css layout into all pages.
154
+
155
+ [ea0e2e7 | Thu Oct 14 20:53:39 UTC 2010] Ketan Padegaonkar <KetanPadegaonkar@gmail.com>
156
+
157
+ * Add HTML IDs and labels on the authorize page.
158
+
159
+ [41db763 | Thu Oct 14 18:22:09 UTC 2010] Ketan Padegaonkar <KetanPadegaonkar@gmail.com>
160
+
161
+ * Change some UI/css bits.
162
+
163
+ [af62696 | Wed Oct 13 20:38:33 UTC 2010] Ketan Padegaonkar <KetanPadegaonkar@gmail.com>
164
+
165
+ * Change some styling bits.
166
+
167
+ [f216d85 | Thu Sep 30 18:33:16 UTC 2010] Ketan Padegaonkar <KetanPadegaonkar@gmail.com>
168
+
169
+ * Remove the word mingle from one of the forms.
170
+
171
+ [4eccf59 | Wed Sep 29 23:22:51 UTC 2010] Ketan Padegaonkar <KetanPadegaonkar@gmail.com>
172
+
173
+ * Update the notice file and the gem task to package the notice file.
174
+
175
+ [0a041b2 | Wed Sep 29 23:11:42 UTC 2010] Ketan Padegaonkar <KetanPadegaonkar@gmail.com>
176
+
177
+ * Remove the help link in the error message.
178
+
179
+ [98c24f5 | Wed Sep 29 23:11:19 UTC 2010] Ketan Padegaonkar <KetanPadegaonkar@gmail.com>
180
+
181
+ * Change some wording on the oauth clients page.
182
+
183
+ [5042141 | Tue Sep 28 23:36:19 UTC 2010] Ketan Padegaonkar <KetanPadegaonkar@gmail.com>
184
+
185
+ * Fixed some messages.
186
+
187
+ [a525c20 | Tue Sep 28 18:49:19 UTC 2010] Ketan Padegaonkar <KetanPadegaonkar@gmail.com>
188
+
189
+ * Strip the fields in the oauth client before saving them. Is is to sanitize inputs coming from the controllers.
190
+
191
+ [55a6258 | Tue Sep 28 18:44:42 UTC 2010] Ketan Padegaonkar <KetanPadegaonkar@gmail.com>
192
+
193
+ * Add a before_save hook into model base.
194
+
195
+ [409a595 | Tue Sep 28 18:01:20 UTC 2010] Ketan Padegaonkar <KetanPadegaonkar@gmail.com>
196
+
197
+ * Package all the files, there was one file that we missed during packaging.
198
+
199
+ [e76bc4e | Tue Sep 28 00:14:19 UTC 2010] Ketan Padegaonkar <KetanPadegaonkar@gmail.com>
200
+
201
+ * Add some styling around the summary information on the oauth clients page.
202
+
203
+ [75ee0e0 | Tue Sep 28 00:13:57 UTC 2010] Ketan Padegaonkar <KetanPadegaonkar@gmail.com>
204
+
205
+ * Add a line break for the buttons on the authorize pages.
206
+
207
+ [8e6ce06 | Mon Sep 27 22:10:22 UTC 2010] Ketan Padegaonkar <KetanPadegaonkar@gmail.com>
208
+
209
+ * Change order of table columns on the oauth_clients page. The redirect url comes after the provider name.
210
+
211
+ [1f8c818 | Mon Sep 27 22:05:52 UTC 2010] Ketan Padegaonkar <KetanPadegaonkar@gmail.com>
212
+
213
+ * HTML escape input fields on the oauth
214
+
215
+ [6284989 | Mon Sep 27 21:44:08 UTC 2010] Ketan Padegaonkar <KetanPadegaonkar@gmail.com>
216
+
217
+ * Provide additional information about OAuth endpoints on the clients page.
218
+
219
+ [a9266c2 | Mon Sep 27 21:25:04 UTC 2010] Ketan Padegaonkar <KetanPadegaonkar@gmail.com>
220
+
221
+ * Add ability to disable SSL validation on controllers.
222
+
223
+ [2d0391b | Mon Sep 27 21:22:23 UTC 2010] Ketan Padegaonkar <KetanPadegaonkar@gmail.com>
224
+
225
+ * Force SSL on all controllers.
226
+
227
+ [a5e0754 | Mon Sep 27 20:51:50 UTC 2010] Ketan Padegaonkar <KetanPadegaonkar@gmail.com>
228
+
229
+ * Add a sslhelper to force SSL access on controllers that include the ssl_helper.
230
+
231
+ [c9bb474 | Mon Sep 27 17:48:26 UTC 2010] Ketan Padegaonkar <KetanPadegaonkar@gmail.com>
232
+
233
+ * cosmetic changes:
234
+
235
+ * Add a span inside the delete link, so that apps can hide the text and use an icon for the link instead.
236
+
237
+ [8bacec5 | Fri Sep 24 23:08:10 UTC 2010] Ketan Padegaonkar <KetanPadegaonkar@gmail.com>
238
+
239
+ * Remove all namespaces from the controllers. This is done because rails routes do not play nice with the namespaces in controller classnames.
240
+
241
+ [1489d1c | Fri Sep 24 22:51:15 UTC 2010] Ketan Padegaonkar <KetanPadegaonkar@gmail.com>
242
+
243
+ * Remove all namespaces from the controllers. This is done because rails routes do not play nice with the namespaces in controller classnames.
244
+
245
+ [3aafe41 | Thu Sep 23 22:41:16 UTC 2010] joshuacronemeyer <jrc@thoughtworks.com>
246
+
247
+ * Fixed a bug with an object was not valid, but did not provide any validation errors.
248
+
249
+ Also removed some redundant code to improve readability.
250
+
251
+ [45a6e6a | Thu Sep 23 21:54:27 UTC 2010] joshuacronemeyer <jrc@thoughtworks.com>
252
+
253
+ * fixed bug where comparing ids not working because id wasn't being stored as an integer.
254
+
255
+ [4cf3b38 | Thu Sep 23 21:03:07 UTC 2010] joshuacronemeyer <jrc@thoughtworks.com>
256
+
257
+ * Redirect URI duplicates should be allowed.
258
+
259
+ [ec4c2e8 | Wed Sep 22 23:37:52 UTC 2010] joshuacronemeyer <jrc@thoughtworks.com>
260
+
261
+ * fixed issue with the oauth popup containing bad form submit params.
262
+
263
+ [b913d4d | Wed Sep 22 00:50:01 UTC 2010] Bill DePhillips <bill.dephillips@gmail.com>
264
+
265
+ * added ability to do validates_uniqueness_of checks for ModelBase and added unique fields to OauthClient
266
+
267
+ [3e43894 | Tue Sep 21 23:30:43 UTC 2010] Bill DePhillips <bill.dephillips@gmail.com>
268
+
269
+ * List OAuth clients by name.
270
+
271
+ [5fe8087 | Tue Sep 21 23:30:29 UTC 2010] Bill DePhillips <bill.dephillips@gmail.com>
272
+
273
+ * Changed help links in all pages.
274
+
275
+ [1100a00 | Tue Sep 21 18:25:44 UTC 2010] Bill DePhillips <bill.dephillips@gmail.com>
276
+
277
+ * Remove usage of all magical routes, use explicit controller and action names.
278
+
279
+ [a9464c4 | Tue Sep 21 00:41:50 UTC 2010] Bill DePhillips <bill.dephillips@gmail.com>
280
+
281
+ * Change the wording on the authorization page to make it an explicit 'yes' or 'no' answer, instead of a checkbox.
282
+
283
+ [22a91a4 | Tue Sep 21 00:33:11 UTC 2010] Bill DePhillips <bill.dephillips@gmail.com>
284
+
285
+ * Change some styling and rendering to match what mingle uses.
286
+
287
+ [154eff4 | Tue Sep 21 00:24:58 UTC 2010] Bill DePhillips <bill.dephillips@gmail.com>
288
+
289
+ * Change some styling and rendering to match what mingle uses.
290
+
291
+ [474fff9 | Mon Sep 20 23:06:55 UTC 2010] Bill DePhillips <bill.dephillips@gmail.com>
292
+
293
+ * removed datasource message
294
+
295
+ [8c596aa | Thu Sep 09 23:24:48 UTC 2010] wdephillips <ThoughtWorks@WD4382s-MacBook-Pro.local>
296
+
297
+ * Bill/WPC allow basic auth in host sample app, make host sample app ui more selenium friendly
298
+
299
+ [5f93768 | Wed Sep 08 04:20:30 UTC 2010] Ketan Padegaonkar <KetanPadegaonkar@gmail.com>
300
+
301
+ * Add RESTful API access for accessing oauth clients.
302
+
303
+ [df04fa5 | Wed Sep 01 00:35:47 UTC 2010] Ketan Padegaonkar <KetanPadegaonkar@gmail.com>
304
+
305
+ * Add a check for valid id when saving a new object. Postgres does not know how to cast a nil to an integer type.
306
+
1
307
  [f15eb88 | Tue Aug 31 23:25:50 UTC 2010] Ketan Padegaonkar <KetanPadegaonkar@gmail.com>
2
308
 
3
309
  * Bumping up version number for a 0.2.0 release!
@@ -0,0 +1,45 @@
1
+ h1. Hacking on the OAuth2 Provider
2
+
3
+ This plugin is tested with:
4
+ * Rails v2.3.4
5
+ * MRI 1.8.7 and JRuby 1.5.1
6
+
7
+ Dependencies:
8
+ * See the gemspec in "https://github.com/ThoughtWorksStudios/oauth2_provider/blob/master/provider/vendor/plugins/oauth2_provider/tasks/gem.rake":gem.rake a list of known dependencies
9
+
10
+ h2. Getting up and running
11
+
12
+ $ git clone git://github.com/ThoughtWorksStudios/oauth2_provider.git
13
+
14
+ For MRI:
15
+
16
+ $ [sudo] gem install rcov saikuro_treemap validatable --no-rdoc --no-ri
17
+
18
+ For JRuby, nothing more is needed, JRuby 1.5.1 and all necessary gems
19
+ are bundled in the /tools directory
20
+
21
+ h2. Structure of the code
22
+
23
+ /tools - contains JRuby + dependency gems
24
+ /provider - a sample rails app containing the plugin
25
+ /provider/test - contains the unit+functional tests
26
+ /provider/vendor/plugins/oauth2_provider - the actual plugin
27
+
28
+ h2. Hacking on code
29
+
30
+ $ cd provider
31
+ $ # muck around with code
32
+ $ rake #using MRI
33
+ $ script/jruby -S rake #using the bundled JRuby
34
+
35
+ h2. Metrics
36
+
37
+ $ cd provider
38
+ $ rake test:coverage
39
+ $ rake metrics:saikuro_treemap
40
+
41
+ h2. Pushing out gems
42
+
43
+ $ cd provider
44
+ $ script/jruby -S rake release:push # follow the instructions printed by the task
45
+ $ script/jruby -S gem push pkg/oauth2_provider-VERSION.gem
@@ -0,0 +1,6 @@
1
+ h2. List of 3rd party dependencies and their licenses
2
+
3
+ This project depends on the following 3rd party code:
4
+
5
+ | *Name* | *What it does* | *Version* | *Authors* | *URL* | *License* | *License URL* |
6
+ | validatable | Validation of inputs | 1.6.7 | Jay Fields | http://validatable.rubyforge.org | Ruby License | http://www.ruby-lang.org/en/LICENSE.txt |
@@ -44,8 +44,10 @@ h1. Supported Features
44
44
  * Endpoint for clients to request authorization 'code'
45
45
  * Endpoint to request an access token using the authorization 'code'
46
46
  * Admin screens for:
47
- * End users to manage/revoke access tokens given out to 3rd party OAuth2 clients
48
- * Admins to manage OAuth2 clients
47
+ ** End users to manage/revoke access tokens given out to 3rd party OAuth2 clients
48
+ ** Admins to manage OAuth2 clients
49
+ * Admin controller actions for:
50
+ ** Delete a single token belonging to any user
49
51
 
50
52
  h1. Available Endpoint URLs
51
53
 
@@ -58,9 +60,12 @@ See config/routes.rb in the plugin for more details.
58
60
  *Accessed from the browser*
59
61
  * /oauth/user_tokens (Oauth2::Provider::OauthUserTokensController) - used by end users to view and revoke access to 3rd party OAuth2 clients.
60
62
  * /oauth/clients (Oauth2::Provider::OauthClientsController) - to manage oauth clients (should be available only to admins)
63
+ * /oauth/user_tokens/revoke_by_admin (Oauth2::Provider::OauthUserTokensController) - used by users with admin privileges to revoke any one token (pass token_id param), or all tokens belonging to a single user (pass user_id param).
61
64
 
62
65
  It is the responsibility of the host application to avoid routing conflicts. The simplest thing to do is avoid defining any paths starting with /oauth
63
66
 
67
+ It is also the responsibility to restrict access to admin-only features such as /oauth/user_tokens/revoke_by_admin
68
+
64
69
  h1. Installation
65
70
 
66
71
  $ [sudo] gem install oauth2_provider
@@ -102,7 +107,7 @@ h3. Rails initializer
102
107
  Edit the file config/initializers/oauth2_provider.rb in which you
103
108
  * must call filter skipping methods on OauthTokenController, ensuring any authentication filters to not run for this controllers actions
104
109
  * must setup authorization for OauthClientsController, limiting access to only application administrators
105
- * must setup authorization for OauthUserTokensController, limiting access to logged in users (this step might not actually require you to write code, we're just putting it here to make sure you consider this issue)
110
+ * must setup authorization for OauthUserTokensController actions, limiting access to all actions to logged in users (this part might come for free), and access to revoke_by_admin to administrators.
106
111
  * might call filter skipping or similar methods on the other provided controllers should it be necessary for them to run
107
112
 
108
113
  A sample initializer:
@@ -117,6 +122,9 @@ module Oauth2
117
122
  # use host app's custom authorization filter to protect OauthClientsController
118
123
  OauthClientsController.before_filter(:ensure_admin_user)
119
124
 
125
+ # use host app's custom authorization filter to protect admin actions on OauthUserTokensController
126
+ OauthUserTokensController.before_filter(:ensure_admin_user, :only => [:revoke_by_admin])
127
+
120
128
  end
121
129
  end
122
130
  </pre>
@@ -0,0 +1,165 @@
1
+ h1. OAuth Provider
2
+
3
+ * Owns a (password) protected resource that belongs to a user.
4
+ * Generates keys(client_id, client_secret, redirect_uri) for OAuth clients.
5
+
6
+ h1. OAuth Client
7
+
8
+ * Wants to access the protected resource on any OAuth Provider.
9
+ * Knows its own client_id, and client_secret, redirect_uri
10
+
11
+ h1. The admin flow
12
+
13
+ h3. admin@oauth-client:
14
+
15
+ * Writes to admin@oauth-provider to request access, and sends a
16
+ redirect_uri and application_name as part of the process.
17
+
18
+ h3. admin@oauth-provider:
19
+
20
+ * Logs in into an admin screen to register an oauth client with the
21
+ redirect_uri and application_name.
22
+
23
+ * Sends back the the client_id and client_secret that the admin screen
24
+ generated to admin@oauth-client.
25
+
26
+ Now the oauth provider and oauth clients know about each other.
27
+
28
+ h1. The end user flow
29
+
30
+ NOTE: this flow is over-simplified, and omits a lot of headers for the sake
31
+ of simplicity. Also all URLs SHOULD be HTTPS, or security goes out the door,
32
+ anyone can sniff codes and tokens going over the wire.
33
+
34
+ * Bob(bob@gmail.com) has an account at an OAuth provider - flickr.com.
35
+ * Bob(bob@hotmail.com) also has an account on another service - printer.com.
36
+
37
+ Note that it's the same Bob, but he has a different username and identity
38
+ on flickr.com and printer.com.
39
+
40
+ Bob now wants his protected resources (pictures) on the flickr.com (OAuth
41
+ provider) to be accessible by printer.com(OAuth client) so that they can
42
+ print it.
43
+
44
+ * Bob logs in into printer.com and logs in using the browser.
45
+ * Bob clicks on a link that says "Print pictures from flickr.com"
46
+ * The link takes Bob's browser to
47
+
48
+ Location:
49
+
50
+ http://flickr.com/authorize?
51
+ client_id=PRINTER_DOT_COM_CLIENT_ID&
52
+ redirect_uri=PRINTER_DOT_COM_REDIRECT_URI
53
+
54
+
55
+
56
+ * The authorization step:
57
+
58
+ * flickr.com knows the application_name corresponding to the client_id and
59
+ redirect_uri and asks Bob to log in. Once Bob is logged in, flickr.com
60
+ asks Bob in the browser:
61
+
62
+ Do you wish to allow a service named 'printer.com' to access flickr.com
63
+ on your behalf? [Y/N]
64
+
65
+ [SUBMIT]
66
+
67
+ If Bob clicks yes and hits submit to allow printer.com to access his
68
+ private data on flickr.com on his behalf.
69
+
70
+ Note that Bob does not tell either his flickr.com username/password to
71
+ printer.com.
72
+
73
+ * Once Bob clicks yes and authorizes access, flickr.com generates a
74
+ ONE_TIME_AUTHORIZATION_CODE_FOR_BOB for printer.com to access
75
+ bob@gmail.com's data on bob@hotmail.com's behalf.
76
+
77
+ flickr.com now redirects Bob's browser to the redirect_uri with the
78
+ authorization_code:
79
+
80
+ Bob redirected to:
81
+
82
+ http://printer.com/callback?code=ONE_TIME_AUTHORIZATION_CODE_FOR_BOB
83
+
84
+
85
+
86
+ * Getting an access_token in exchange for ONE_TIME_AUTHORIZATION_CODE_FOR_BOB
87
+
88
+ * printer.com now gets a callback with the authorization code, and knows
89
+ that Bob is logged in, therefore ONE_TIME_AUTHORIZATION_CODE_FOR_BOB
90
+ belongs to bob@hotmail.com.
91
+
92
+ * Now that printer.com knows the authorization_code, it can request an
93
+ access_token from flickr.com to actually access the protected
94
+ resource.
95
+
96
+ * printer.com contacts flickr.com, gives the authorization_code to get
97
+ back an access_token.
98
+
99
+ printer.com identifies itself to flickr.com and requests an access_token
100
+ corresponding to ONE_TIME_AUTHORIZATION_CODE_FOR_BOB
101
+
102
+ http://flickr.com/oauth/token?
103
+ client_id=PRINTER_DOT_COM_CLIENT_ID&
104
+ client_secret=PRINTER_DOT_COM_CLIENT_SECRET&
105
+ code=ONE_TIME_AUTHORIZATION_CODE_FOR_BOB
106
+
107
+ * flickr.com reads the request, and verifies that the client_id,
108
+ client_secret, ONE_TIME_AUTHORIZATION_CODE_FOR_BOB are all consistent
109
+
110
+ It then generates an access_token for printer.com to be able to access
111
+ Bob's pictures, and renders a json containing the access_token:
112
+
113
+ {
114
+ access_token: ACCESS_TOKEN_FOR_PRINTER_TO_ACCESS_BOBS_PICTURES,
115
+ ...
116
+ ...
117
+ }
118
+
119
+ * once printer.com gets this response, it stores this access_token and knows
120
+ that it is used to access Bob's pictures. Alice will have her own access
121
+ token, once she goes through the same flow as Bob.
122
+
123
+
124
+
125
+ * printer.com accessing Bob's pictures now
126
+
127
+ * Bob says he wants to print sunset.jpg on flickr.com
128
+
129
+ * printer.com to flickr.com:
130
+
131
+ get: flickr.com/images/bob/sunset.jpg?
132
+ access_token=ACCESS_TOKEN_FOR_PRINTER_TO_ACCESS_BOBS_PICTURES
133
+
134
+ flickr.com verifies the access_token and knows it was given out to Bob,
135
+ the image belongs to Bob, all is well and it renders the sunset.jpg
136
+ image so that printer.com can print it.
137
+
138
+
139
+ Shown as a picture:
140
+
141
+ <pre>
142
+ +----------+ Client Identifier +---------------+
143
+ | -+----(A)--- & Redirect URI ------>| |
144
+ | End-user | | OAuth |
145
+ | at |<---(B)-- User authenticates --->| Provider |
146
+ | Browser | | |
147
+ | -+----(C)-- Authorization Code ---<| |
148
+ +-|----|---+ +---------------+
149
+ | | ^ v ^
150
+ (A) (C) | | |
151
+ | | | | |
152
+ ^ v | | |
153
+ +---------+ | | |
154
+ | |>---(D)-- Client Credentials, --------' | |
155
+ | OAuth2 | Authorization Code, | |
156
+ | Client | & Redirect URI | |
157
+ | | | |
158
+ | |<---(E)----- Access Token ----------------' |
159
+ | | (w/ Optional Refresh Token) |
160
+ | | |
161
+ | |>---(F)------ Send Access Token --------------'
162
+ | | Get back data
163
+ | | for end user
164
+ +---------+
165
+ </pre>