camping-oauth 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (102) hide show
  1. data/README +3 -0
  2. data/doc/classes/CampingOAuthConsumer.html +145 -0
  3. data/doc/classes/CampingOAuthConsumer.src/M000041.html +19 -0
  4. data/doc/classes/CampingOAuthConsumer/Controllers.html +116 -0
  5. data/doc/classes/CampingOAuthConsumer/Controllers/AccessToken.html +137 -0
  6. data/doc/classes/CampingOAuthConsumer/Controllers/AccessToken.src/M000051.html +32 -0
  7. data/doc/classes/CampingOAuthConsumer/Controllers/AccessTokenAuthorized.html +137 -0
  8. data/doc/classes/CampingOAuthConsumer/Controllers/AccessTokenAuthorized.src/M000050.html +20 -0
  9. data/doc/classes/CampingOAuthConsumer/Controllers/AuthorizeToken.html +137 -0
  10. data/doc/classes/CampingOAuthConsumer/Controllers/AuthorizeToken.src/M000048.html +24 -0
  11. data/doc/classes/CampingOAuthConsumer/Controllers/GetTimeNow.html +137 -0
  12. data/doc/classes/CampingOAuthConsumer/Controllers/GetTimeNow.src/M000049.html +28 -0
  13. data/doc/classes/CampingOAuthConsumer/Controllers/Index.html +137 -0
  14. data/doc/classes/CampingOAuthConsumer/Controllers/Index.src/M000046.html +18 -0
  15. data/doc/classes/CampingOAuthConsumer/Controllers/RequestToken.html +137 -0
  16. data/doc/classes/CampingOAuthConsumer/Controllers/RequestToken.src/M000047.html +24 -0
  17. data/doc/classes/CampingOAuthConsumer/Views.html +176 -0
  18. data/doc/classes/CampingOAuthConsumer/Views.src/M000042.html +42 -0
  19. data/doc/classes/CampingOAuthConsumer/Views.src/M000043.html +41 -0
  20. data/doc/classes/CampingOAuthConsumer/Views.src/M000044.html +18 -0
  21. data/doc/classes/CampingOAuthConsumer/Views.src/M000045.html +19 -0
  22. data/doc/classes/CampingOAuthProvider.html +149 -0
  23. data/doc/classes/CampingOAuthProvider.src/M000052.html +23 -0
  24. data/doc/classes/CampingOAuthProvider/Controllers.html +113 -0
  25. data/doc/classes/CampingOAuthProvider/Controllers/APITimeNow.html +137 -0
  26. data/doc/classes/CampingOAuthProvider/Controllers/APITimeNow.src/M000058.html +23 -0
  27. data/doc/classes/CampingOAuthProvider/Controllers/Index.html +137 -0
  28. data/doc/classes/CampingOAuthProvider/Controllers/Index.src/M000055.html +18 -0
  29. data/doc/classes/CampingOAuthProvider/Controllers/Login.html +152 -0
  30. data/doc/classes/CampingOAuthProvider/Controllers/Login.src/M000056.html +18 -0
  31. data/doc/classes/CampingOAuthProvider/Controllers/Login.src/M000057.html +33 -0
  32. data/doc/classes/CampingOAuthProvider/Helpers.html +112 -0
  33. data/doc/classes/CampingOAuthProvider/Models.html +119 -0
  34. data/doc/classes/CampingOAuthProvider/Models/CreateUserSchema.html +152 -0
  35. data/doc/classes/CampingOAuthProvider/Models/CreateUserSchema.src/M000059.html +26 -0
  36. data/doc/classes/CampingOAuthProvider/Models/CreateUserSchema.src/M000060.html +19 -0
  37. data/doc/classes/CampingOAuthProvider/Models/User.html +111 -0
  38. data/doc/classes/CampingOAuthProvider/Views.html +146 -0
  39. data/doc/classes/CampingOAuthProvider/Views.src/M000053.html +19 -0
  40. data/doc/classes/CampingOAuthProvider/Views.src/M000054.html +27 -0
  41. data/doc/classes/OAuth.html +107 -0
  42. data/doc/classes/OAuth/RequestProxy.html +112 -0
  43. data/doc/classes/OAuth/RequestProxy/Base.html +153 -0
  44. data/doc/classes/OAuth/RequestProxy/Base.src/M000039.html +28 -0
  45. data/doc/classes/OAuth/RequestProxy/Base.src/M000040.html +28 -0
  46. data/doc/classes/OAuth/RequestProxy/RackRequest.html +143 -0
  47. data/doc/classes/OAuth/RequestProxy/RackRequest.src/M000039.html +18 -0
  48. data/doc/classes/OAuthCampingPlugin.html +188 -0
  49. data/doc/classes/OAuthCampingPlugin.src/M000001.html +18 -0
  50. data/doc/classes/OAuthCampingPlugin.src/M000002.html +18 -0
  51. data/doc/classes/OAuthCampingPlugin.src/M000003.html +17 -0
  52. data/doc/classes/OAuthCampingPlugin/Controllers.html +191 -0
  53. data/doc/classes/OAuthCampingPlugin/Controllers.src/M000024.html +18 -0
  54. data/doc/classes/OAuthCampingPlugin/Controllers.src/M000025.html +26 -0
  55. data/doc/classes/OAuthCampingPlugin/Filters.html +161 -0
  56. data/doc/classes/OAuthCampingPlugin/Filters.src/M000034.html +34 -0
  57. data/doc/classes/OAuthCampingPlugin/Helpers.html +283 -0
  58. data/doc/classes/OAuthCampingPlugin/Helpers.src/M000026.html +18 -0
  59. data/doc/classes/OAuthCampingPlugin/Helpers.src/M000027.html +19 -0
  60. data/doc/classes/OAuthCampingPlugin/Helpers.src/M000028.html +20 -0
  61. data/doc/classes/OAuthCampingPlugin/Helpers.src/M000029.html +20 -0
  62. data/doc/classes/OAuthCampingPlugin/Helpers.src/M000030.html +18 -0
  63. data/doc/classes/OAuthCampingPlugin/Helpers.src/M000031.html +18 -0
  64. data/doc/classes/OAuthCampingPlugin/Helpers.src/M000032.html +20 -0
  65. data/doc/classes/OAuthCampingPlugin/Helpers.src/M000033.html +20 -0
  66. data/doc/classes/OAuthCampingPlugin/Models.html +219 -0
  67. data/doc/classes/OAuthCampingPlugin/Models.src/M000035.html +55 -0
  68. data/doc/classes/OAuthCampingPlugin/Models.src/M000036.html +31 -0
  69. data/doc/classes/OAuthCampingPlugin/Models.src/M000037.html +56 -0
  70. data/doc/classes/OAuthCampingPlugin/Models.src/M000038.html +22 -0
  71. data/doc/classes/OAuthCampingPlugin/OAuth.html +407 -0
  72. data/doc/classes/OAuthCampingPlugin/OAuth.src/M000004.html +18 -0
  73. data/doc/classes/OAuthCampingPlugin/OAuth.src/M000005.html +18 -0
  74. data/doc/classes/OAuthCampingPlugin/OAuth.src/M000006.html +20 -0
  75. data/doc/classes/OAuthCampingPlugin/OAuth.src/M000007.html +20 -0
  76. data/doc/classes/OAuthCampingPlugin/OAuth.src/M000008.html +20 -0
  77. data/doc/classes/OAuthCampingPlugin/OAuth.src/M000009.html +24 -0
  78. data/doc/classes/OAuthCampingPlugin/OAuth.src/M000010.html +20 -0
  79. data/doc/classes/OAuthCampingPlugin/OAuth.src/M000011.html +18 -0
  80. data/doc/classes/OAuthCampingPlugin/OAuth.src/M000012.html +19 -0
  81. data/doc/classes/OAuthCampingPlugin/OAuth.src/M000013.html +26 -0
  82. data/doc/classes/OAuthCampingPlugin/OAuth.src/M000014.html +26 -0
  83. data/doc/classes/OAuthCampingPlugin/OAuth.src/M000015.html +33 -0
  84. data/doc/classes/OAuthCampingPlugin/OAuth.src/M000016.html +18 -0
  85. data/doc/classes/OAuthCampingPlugin/OAuth.src/M000017.html +18 -0
  86. data/doc/classes/OAuthCampingPlugin/Views.html +257 -0
  87. data/doc/classes/OAuthCampingPlugin/Views.src/M000018.html +18 -0
  88. data/doc/classes/OAuthCampingPlugin/Views.src/M000019.html +18 -0
  89. data/doc/classes/OAuthCampingPlugin/Views.src/M000020.html +18 -0
  90. data/doc/classes/OAuthCampingPlugin/Views.src/M000021.html +18 -0
  91. data/doc/classes/OAuthCampingPlugin/Views.src/M000022.html +18 -0
  92. data/doc/classes/OAuthCampingPlugin/Views.src/M000023.html +41 -0
  93. data/doc/created.rid +1 -0
  94. data/doc/files/examples/camping-oauth-consumer/camping-oauth-consumer_rb.html +124 -0
  95. data/doc/files/examples/camping-oauth-provider/camping-oauth-provider_rb.html +101 -0
  96. data/doc/files/lib/camping-oauth_rb.html +576 -0
  97. data/doc/fr_class_index.html +56 -0
  98. data/doc/fr_file_index.html +29 -0
  99. data/doc/fr_method_index.html +86 -0
  100. data/doc/index.html +24 -0
  101. data/lib/camping-oauth.rb +1078 -0
  102. metadata +172 -0
@@ -0,0 +1,56 @@
1
+
2
+ <?xml version="1.0" encoding="iso-8859-1"?>
3
+ <!DOCTYPE html
4
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
5
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
6
+
7
+ <!--
8
+
9
+ Classes
10
+
11
+ -->
12
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
13
+ <head>
14
+ <title>Classes</title>
15
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
16
+ <link rel="stylesheet" href="rdoc-style.css" type="text/css" />
17
+ <base target="docwin" />
18
+ </head>
19
+ <body>
20
+ <div id="index">
21
+ <h1 class="section-bar">Classes</h1>
22
+ <div id="index-entries">
23
+ <a href="classes/CampingOAuthConsumer.html">CampingOAuthConsumer</a><br />
24
+ <a href="classes/CampingOAuthConsumer/Controllers.html">CampingOAuthConsumer::Controllers</a><br />
25
+ <a href="classes/CampingOAuthConsumer/Controllers/AccessToken.html">CampingOAuthConsumer::Controllers::AccessToken</a><br />
26
+ <a href="classes/CampingOAuthConsumer/Controllers/AccessTokenAuthorized.html">CampingOAuthConsumer::Controllers::AccessTokenAuthorized</a><br />
27
+ <a href="classes/CampingOAuthConsumer/Controllers/AuthorizeToken.html">CampingOAuthConsumer::Controllers::AuthorizeToken</a><br />
28
+ <a href="classes/CampingOAuthConsumer/Controllers/GetTimeNow.html">CampingOAuthConsumer::Controllers::GetTimeNow</a><br />
29
+ <a href="classes/CampingOAuthConsumer/Controllers/Index.html">CampingOAuthConsumer::Controllers::Index</a><br />
30
+ <a href="classes/CampingOAuthConsumer/Controllers/RequestToken.html">CampingOAuthConsumer::Controllers::RequestToken</a><br />
31
+ <a href="classes/CampingOAuthConsumer/Views.html">CampingOAuthConsumer::Views</a><br />
32
+ <a href="classes/CampingOAuthProvider.html">CampingOAuthProvider</a><br />
33
+ <a href="classes/CampingOAuthProvider/Controllers.html">CampingOAuthProvider::Controllers</a><br />
34
+ <a href="classes/CampingOAuthProvider/Controllers/APITimeNow.html">CampingOAuthProvider::Controllers::APITimeNow</a><br />
35
+ <a href="classes/CampingOAuthProvider/Controllers/Index.html">CampingOAuthProvider::Controllers::Index</a><br />
36
+ <a href="classes/CampingOAuthProvider/Controllers/Login.html">CampingOAuthProvider::Controllers::Login</a><br />
37
+ <a href="classes/CampingOAuthProvider/Helpers.html">CampingOAuthProvider::Helpers</a><br />
38
+ <a href="classes/CampingOAuthProvider/Models.html">CampingOAuthProvider::Models</a><br />
39
+ <a href="classes/CampingOAuthProvider/Models/CreateUserSchema.html">CampingOAuthProvider::Models::CreateUserSchema</a><br />
40
+ <a href="classes/CampingOAuthProvider/Models/User.html">CampingOAuthProvider::Models::User</a><br />
41
+ <a href="classes/CampingOAuthProvider/Views.html">CampingOAuthProvider::Views</a><br />
42
+ <a href="classes/OAuth.html">OAuth</a><br />
43
+ <a href="classes/OAuth/RequestProxy.html">OAuth::RequestProxy</a><br />
44
+ <a href="classes/OAuth/RequestProxy/Base.html">OAuth::RequestProxy::Base</a><br />
45
+ <a href="classes/OAuth/RequestProxy/RackRequest.html">OAuth::RequestProxy::RackRequest</a><br />
46
+ <a href="classes/OAuthCampingPlugin.html">OAuthCampingPlugin</a><br />
47
+ <a href="classes/OAuthCampingPlugin/Controllers.html">OAuthCampingPlugin::Controllers</a><br />
48
+ <a href="classes/OAuthCampingPlugin/Filters.html">OAuthCampingPlugin::Filters</a><br />
49
+ <a href="classes/OAuthCampingPlugin/Helpers.html">OAuthCampingPlugin::Helpers</a><br />
50
+ <a href="classes/OAuthCampingPlugin/Models.html">OAuthCampingPlugin::Models</a><br />
51
+ <a href="classes/OAuthCampingPlugin/OAuth.html">OAuthCampingPlugin::OAuth</a><br />
52
+ <a href="classes/OAuthCampingPlugin/Views.html">OAuthCampingPlugin::Views</a><br />
53
+ </div>
54
+ </div>
55
+ </body>
56
+ </html>
@@ -0,0 +1,29 @@
1
+
2
+ <?xml version="1.0" encoding="iso-8859-1"?>
3
+ <!DOCTYPE html
4
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
5
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
6
+
7
+ <!--
8
+
9
+ Files
10
+
11
+ -->
12
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
13
+ <head>
14
+ <title>Files</title>
15
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
16
+ <link rel="stylesheet" href="rdoc-style.css" type="text/css" />
17
+ <base target="docwin" />
18
+ </head>
19
+ <body>
20
+ <div id="index">
21
+ <h1 class="section-bar">Files</h1>
22
+ <div id="index-entries">
23
+ <a href="files/examples/camping-oauth-consumer/camping-oauth-consumer_rb.html">examples/camping-oauth-consumer/camping-oauth-consumer.rb</a><br />
24
+ <a href="files/examples/camping-oauth-provider/camping-oauth-provider_rb.html">examples/camping-oauth-provider/camping-oauth-provider.rb</a><br />
25
+ <a href="files/lib/camping-oauth_rb.html">lib/camping-oauth.rb</a><br />
26
+ </div>
27
+ </div>
28
+ </body>
29
+ </html>
@@ -0,0 +1,86 @@
1
+
2
+ <?xml version="1.0" encoding="iso-8859-1"?>
3
+ <!DOCTYPE html
4
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
5
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
6
+
7
+ <!--
8
+
9
+ Methods
10
+
11
+ -->
12
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
13
+ <head>
14
+ <title>Methods</title>
15
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
16
+ <link rel="stylesheet" href="rdoc-style.css" type="text/css" />
17
+ <base target="docwin" />
18
+ </head>
19
+ <body>
20
+ <div id="index">
21
+ <h1 class="section-bar">Methods</h1>
22
+ <div id="index-entries">
23
+ <a href="classes/OAuthCampingPlugin/Helpers.html#M000033">access_denied (OAuthCampingPlugin::Helpers)</a><br />
24
+ <a href="classes/OAuthCampingPlugin/OAuth.html#M000008">access_token_class (OAuthCampingPlugin::OAuth)</a><br />
25
+ <a href="classes/OAuthCampingPlugin/Helpers.html#M000027">app_module (OAuthCampingPlugin::Helpers)</a><br />
26
+ <a href="classes/OAuthCampingPlugin/Views.html#M000021">authorize_view (OAuthCampingPlugin::Views)</a><br />
27
+ <a href="classes/OAuthCampingPlugin/OAuth.html#M000012">authorized? (OAuthCampingPlugin::OAuth)</a><br />
28
+ <a href="classes/OAuthCampingPlugin/OAuth.html#M000006">client_application_class (OAuthCampingPlugin::OAuth)</a><br />
29
+ <a href="classes/OAuthCampingPlugin/Controllers.html#M000024">common_oauth_controllers (OAuthCampingPlugin::Controllers)</a><br />
30
+ <a href="classes/OAuthCampingPlugin/Views.html#M000018">common_oauth_views (OAuthCampingPlugin::Views)</a><br />
31
+ <a href="classes/CampingOAuthConsumer.html#M000041">create (CampingOAuthConsumer)</a><br />
32
+ <a href="classes/CampingOAuthProvider.html#M000052">create (CampingOAuthProvider)</a><br />
33
+ <a href="classes/OAuthCampingPlugin.html#M000003">create (OAuthCampingPlugin)</a><br />
34
+ <a href="classes/OAuthCampingPlugin/OAuth.html#M000005">current_client_application (OAuthCampingPlugin::OAuth)</a><br />
35
+ <a href="classes/OAuthCampingPlugin/OAuth.html#M000004">current_token (OAuthCampingPlugin::OAuth)</a><br />
36
+ <a href="classes/OAuthCampingPlugin/Helpers.html#M000031">current_user (OAuthCampingPlugin::Helpers)</a><br />
37
+ <a href="classes/OAuthCampingPlugin/Models.html#M000038">down (OAuthCampingPlugin::Models)</a><br />
38
+ <a href="classes/CampingOAuthProvider/Models/CreateUserSchema.html#M000060">down (CampingOAuthProvider::Models::CreateUserSchema)</a><br />
39
+ <a href="classes/CampingOAuthConsumer/Controllers/RequestToken.html#M000047">get (CampingOAuthConsumer::Controllers::RequestToken)</a><br />
40
+ <a href="classes/CampingOAuthConsumer/Controllers/AuthorizeToken.html#M000048">get (CampingOAuthConsumer::Controllers::AuthorizeToken)</a><br />
41
+ <a href="classes/CampingOAuthConsumer/Controllers/GetTimeNow.html#M000049">get (CampingOAuthConsumer::Controllers::GetTimeNow)</a><br />
42
+ <a href="classes/CampingOAuthConsumer/Controllers/AccessToken.html#M000051">get (CampingOAuthConsumer::Controllers::AccessToken)</a><br />
43
+ <a href="classes/CampingOAuthProvider/Controllers/Index.html#M000055">get (CampingOAuthProvider::Controllers::Index)</a><br />
44
+ <a href="classes/CampingOAuthProvider/Controllers/Login.html#M000056">get (CampingOAuthProvider::Controllers::Login)</a><br />
45
+ <a href="classes/CampingOAuthProvider/Controllers/APITimeNow.html#M000058">get (CampingOAuthProvider::Controllers::APITimeNow)</a><br />
46
+ <a href="classes/CampingOAuthConsumer/Controllers/AccessTokenAuthorized.html#M000050">get (CampingOAuthConsumer::Controllers::AccessTokenAuthorized)</a><br />
47
+ <a href="classes/CampingOAuthConsumer/Controllers/Index.html#M000046">get (CampingOAuthConsumer::Controllers::Index)</a><br />
48
+ <a href="classes/OAuth/RequestProxy/Base.html#M000040">header_params (OAuth::RequestProxy::Base)</a><br />
49
+ <a href="classes/OAuthCampingPlugin/Controllers.html#M000025">include_oauth_controllers (OAuthCampingPlugin::Controllers)</a><br />
50
+ <a href="classes/OAuthCampingPlugin/Views.html#M000023">include_oauth_views (OAuthCampingPlugin::Views)</a><br />
51
+ <a href="classes/OAuthCampingPlugin/Filters.html#M000034">included (OAuthCampingPlugin::Filters)</a><br />
52
+ <a href="classes/OAuthCampingPlugin/Models.html#M000035">included (OAuthCampingPlugin::Models)</a><br />
53
+ <a href="classes/CampingOAuthConsumer/Views.html#M000043">index (CampingOAuthConsumer::Views)</a><br />
54
+ <a href="classes/CampingOAuthProvider/Views.html#M000053">index (CampingOAuthProvider::Views)</a><br />
55
+ <a href="classes/CampingOAuthConsumer/Views.html#M000044">invalid_key_and_secret (CampingOAuthConsumer::Views)</a><br />
56
+ <a href="classes/OAuthCampingPlugin/OAuth.html#M000017">invalid_oauth_response (OAuthCampingPlugin::OAuth)</a><br />
57
+ <a href="classes/CampingOAuthConsumer/Views.html#M000042">layout (CampingOAuthConsumer::Views)</a><br />
58
+ <a href="classes/OAuthCampingPlugin/Helpers.html#M000026">log_debug (OAuthCampingPlugin::Helpers)</a><br />
59
+ <a href="classes/OAuthCampingPlugin.html#M000001">logger (OAuthCampingPlugin)</a><br />
60
+ <a href="classes/OAuthCampingPlugin.html#M000002">logger= (OAuthCampingPlugin)</a><br />
61
+ <a href="classes/CampingOAuthProvider/Views.html#M000054">login (CampingOAuthProvider::Views)</a><br />
62
+ <a href="classes/OAuthCampingPlugin/OAuth.html#M000014">login_or_oauth_required (OAuthCampingPlugin::OAuth)</a><br />
63
+ <a href="classes/OAuthCampingPlugin/Helpers.html#M000032">login_required (OAuthCampingPlugin::Helpers)</a><br />
64
+ <a href="classes/OAuthCampingPlugin/Helpers.html#M000029">nonce_class (OAuthCampingPlugin::Helpers)</a><br />
65
+ <a href="classes/OAuthCampingPlugin/OAuth.html#M000011">oauth? (OAuthCampingPlugin::OAuth)</a><br />
66
+ <a href="classes/OAuthCampingPlugin/OAuth.html#M000009">oauth_header_params (OAuthCampingPlugin::OAuth)</a><br />
67
+ <a href="classes/OAuthCampingPlugin/OAuth.html#M000013">oauth_required (OAuthCampingPlugin::OAuth)</a><br />
68
+ <a href="classes/OAuthCampingPlugin/OAuth.html#M000010">oauthenticate (OAuthCampingPlugin::OAuth)</a><br />
69
+ <a href="classes/CampingOAuthProvider/Controllers/Login.html#M000057">post (CampingOAuthProvider::Controllers::Login)</a><br />
70
+ <a href="classes/OAuthCampingPlugin/Views.html#M000019">register_view (OAuthCampingPlugin::Views)</a><br />
71
+ <a href="classes/OAuthCampingPlugin/Views.html#M000020">registration_view (OAuthCampingPlugin::Views)</a><br />
72
+ <a href="classes/OAuth/RequestProxy/RackRequest.html#M000039">request_params (OAuth::RequestProxy::RackRequest)</a><br />
73
+ <a href="classes/OAuthCampingPlugin/OAuth.html#M000007">request_token_class (OAuthCampingPlugin::OAuth)</a><br />
74
+ <a href="classes/OAuthCampingPlugin/Views.html#M000022">revoke_view (OAuthCampingPlugin::Views)</a><br />
75
+ <a href="classes/OAuthCampingPlugin/Helpers.html#M000030">set_user (OAuthCampingPlugin::Helpers)</a><br />
76
+ <a href="classes/CampingOAuthConsumer/Views.html#M000045">time_now (CampingOAuthConsumer::Views)</a><br />
77
+ <a href="classes/OAuthCampingPlugin/Models.html#M000037">up (OAuthCampingPlugin::Models)</a><br />
78
+ <a href="classes/CampingOAuthProvider/Models/CreateUserSchema.html#M000059">up (CampingOAuthProvider::Models::CreateUserSchema)</a><br />
79
+ <a href="classes/OAuthCampingPlugin/Helpers.html#M000028">user_class (OAuthCampingPlugin::Helpers)</a><br />
80
+ <a href="classes/OAuthCampingPlugin/OAuth.html#M000015">verify_oauth_consumer_signature (OAuthCampingPlugin::OAuth)</a><br />
81
+ <a href="classes/OAuthCampingPlugin/OAuth.html#M000016">verify_oauth_request_token (OAuthCampingPlugin::OAuth)</a><br />
82
+ <a href="classes/OAuthCampingPlugin/Models.html#M000036">verify_request (OAuthCampingPlugin::Models)</a><br />
83
+ </div>
84
+ </div>
85
+ </body>
86
+ </html>
data/doc/index.html ADDED
@@ -0,0 +1,24 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
5
+
6
+ <!--
7
+
8
+ RDoc Documentation
9
+
10
+ -->
11
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
12
+ <head>
13
+ <title>RDoc Documentation</title>
14
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
15
+ </head>
16
+ <frameset rows="20%, 80%">
17
+ <frameset cols="25%,35%,45%">
18
+ <frame src="fr_file_index.html" title="Files" name="Files" />
19
+ <frame src="fr_class_index.html" name="Classes" />
20
+ <frame src="fr_method_index.html" name="Methods" />
21
+ </frameset>
22
+ <frame src="files/examples/camping-oauth-consumer/camping-oauth-consumer_rb.html" name="docwin" />
23
+ </frameset>
24
+ </html>
@@ -0,0 +1,1078 @@
1
+ =begin rdoc
2
+ Author:: Philippe F. Monnet (mailto:pfmonnet@gmail.com)
3
+ Copyright:: Copyright (c) 2010 Philippe F. Monnet - OAuth Camping plugin
4
+ Copyright:: Copyright (c) 2009 Pelle Braendgaard - A subset of the Rails OAuth plugin reused in OAuth Camping
5
+ License:: Distributes under the same terms as Ruby
6
+ Version:: 0.0.1
7
+
8
+ :main: Camping-OAuth
9
+
10
+ =Installing Camping-OAuth
11
+ A lightweight OAuth plugin for Ruby Camping.
12
+ To install the library and its prerequisisites, type the following commands:
13
+
14
+ $ gem install filtering_camping
15
+ $ gem install oauth
16
+ $ gem install oauth-plugin
17
+ $ gem install camping-oauth
18
+
19
+ =Adding OAuth Provider Support To Your App
20
+
21
+
22
+ ===Add new gem and require statements
23
+ Add the following statements towards the top of your source file (before the Camping.goes statement):
24
+
25
+ gem 'camping' , '>= 2.0'
26
+ gem 'filtering_camping'
27
+ gem 'oauth'
28
+ gem 'oauth-plugin'
29
+
30
+ %w(rubygems active_record camping camping/session markaby json redcloth erb
31
+ oauth
32
+ oauth/server
33
+ oauth/request_proxy
34
+ oauth/request_proxy/rack_request
35
+ filtering_camping
36
+ camping-oauth
37
+ ).each { |lib| require lib }
38
+
39
+ ===Customizing the main module
40
+
41
+ First we'll make sure to include the Camping::Session and CampingFilters modules, and to extend the app module with OAuthCampingPlugin, like so:
42
+
43
+ module CampingOAuthProvider
44
+ include Camping::Session
45
+ include CampingFilters
46
+ extend OAuthCampingPlugin
47
+ include OAuthCampingPlugin::Filters
48
+
49
+ # ...
50
+ end
51
+
52
+ This gives us the ability to leverage a logger for the camping-oauth plugin.
53
+
54
+ OAuthCampingPlugin.logger = Logger.new(File.dirname(__FILE__) + '/yourmodule.log');
55
+ OAuthCampingPlugin.logger.level = Logger::DEBUG
56
+
57
+ Now let's customize the create method by adding a call to OAuthCampingPlugin.create, so we can give the plugin to run any needed initialization.
58
+
59
+ def CampingOAuthProvider.create
60
+ OAuthCampingPlugin.create
61
+ end
62
+
63
+ Ok, at this point we have a minimally configured application module. Our next step is to move on to the Models module.
64
+
65
+ ===Plugging in the OAuth models
66
+
67
+ First, we'll include the include OAuthCampingPlugin::Models module so we can get all the OAuth-specific models. Then we'll define a User model. The User will need to keep track of the applications it provided access to. It will also manage the tokens associated with these applications. Our model will look like this:
68
+
69
+ class User < Base;
70
+ has_many :client_applications
71
+ has_many :tokens,
72
+ :class_name=>"OauthToken",
73
+ :order=>"authorized_at desc",
74
+ :include=>[:client_application]
75
+
76
+ end
77
+
78
+ Now we need a CreateUserSchema migration class to define our database tables for User, and OAuth models. In the up and down methods we will plugin a call to the corresponding method from the OAuthCampingPlugin::Models module to create the tables for ClientApplication, OAuthToken, and OauthNonce.
79
+
80
+ class CreateUserSchema < V 1.0
81
+ def self.up
82
+ create_table :CampingOAuthProvider_users, :force => true do |t|
83
+ t.integer :id, :null => false
84
+ t.string :username
85
+ t.string :password
86
+ end
87
+
88
+ User.create :username => 'admin', :password => 'camping'
89
+
90
+ OAuthCampingPlugin::Models.up
91
+ end
92
+
93
+ def self.down
94
+ OAuthCampingPlugin::Models.down
95
+ drop_table :CampingOAuthProvider_users
96
+ end
97
+ end
98
+
99
+ At this point we can go back to the main module and add the code to configure the ActiveRecord connection and invoke our new schema migration if the User table does not exist yet. This code will be added to the create method:
100
+
101
+ module CampingOAuthProvider
102
+ # ...
103
+
104
+ def CampingOAuthProvider.create
105
+ dbconfig = YAML.load(File.read('config/database.yml'))
106
+ Camping::Models::Base.establish_connection dbconfig['development']
107
+
108
+ OAuthCampingPlugin.create
109
+
110
+ CampingOAuthProvider::Models.create_schema :assume => (CampingOAuthProvider::Models::User.table_exists? ? 1.1 : 0.0)
111
+ end
112
+ end
113
+
114
+ You probably noticed that the database configuration is loaded from a database.yml file. So let's create a subfolder named config and a file named database.yml, then let's configure the yaml file as follows:
115
+
116
+ development:
117
+ adapter: sqlite3
118
+ database: campingoauthprovider.db
119
+
120
+ Now if we restart the application, our migration should be executed.
121
+
122
+ ===Creating a common helpers module
123
+
124
+ The Helpers module is used in Camping to provide common utilities to both the Controllers and Views modules. Enhancing our Helpers module is very easy, we need to add both and extend and an include of the OAuthCampingPlugin::Helpers module so we can enhance both instance and class sides:
125
+
126
+ module CampingOAuthProvider::Helpers
127
+ extend OAuthCampingPlugin::Helpers
128
+ include OAuthCampingPlugin::Helpers
129
+ end
130
+
131
+ ===E.Plugging in the OAuth controllers
132
+
133
+ We will need to extend our app Controllers module with the OAuthCampingPlugin::Controllers module using the extend statement. Then just before the end of the Controllers module, we'll add a call to the include_oauth_controllers method. This is how camping-oauth will inject and plugin the common OAuth controllers and helpers. It is important that this call always remaining the last statement of the module, even when you add new controller classes. So the module should look like so:
134
+
135
+ module CampingOAuthProvider::Controllers
136
+ extend OAuthCampingPlugin::Controllers
137
+
138
+ # ...
139
+
140
+ include_oauth_controllers
141
+ end #Controllers
142
+
143
+ Before we continue fleshing out the logic of our controllers, let's finish hooking up the Views module.
144
+
145
+ ===Plugging in the OAuth common views
146
+
147
+ We will need to extend our app Views module with the OAuthCampingPlugin::Views module using the extend statement. Then just before the end of the Views module, we'll add a call to the include_oauth_views method. This is how camping-oauth will inject and plugin the common OAuth views. It is important that this call always remaining the last statement of the module, even when you add new view methods. So the module should look like so:
148
+
149
+ module CampingOAuthProvider::Views
150
+ extend OAuthCampingPlugin::Views
151
+
152
+ # ...
153
+
154
+ include_oauth_views
155
+ end
156
+
157
+ ===Adding basic login and registration capabilities
158
+
159
+ Let's add a Login controller class to our Controllers module:
160
+
161
+ class Login < R '/login'
162
+ def get
163
+ render :login
164
+ end
165
+
166
+ def post
167
+ @user = User.find_by_username_and_password(input.username, input.password)
168
+
169
+ if @user
170
+ @state.user_id = @user.id
171
+
172
+ if @state.return_to.nil?
173
+ redirect R(Index)
174
+ else
175
+ return_to = @state.return_to
176
+ @state.return_to = nil
177
+ redirect(return_to)
178
+ end
179
+ else
180
+ @info = 'Wrong username or password.'
181
+ end
182
+ render :login
183
+ end
184
+ end
185
+
186
+ And now add the corresponding login view in the Views module"
187
+
188
+ def login
189
+ div @info if @info
190
+ form :action => R(Login), :method => 'post' do
191
+ label 'Username', :for => 'username'; br
192
+ input :name => 'username', :type => 'text'; br
193
+
194
+ label 'Password', :for => 'password'; br
195
+ input :name => 'password', :type => 'text'; br
196
+
197
+ input :type => 'submit', :name => 'login', :value => 'Login'
198
+ end
199
+ end
200
+
201
+ Let's verify we can login by accessing the following url:
202
+ http://localhost:3301/login
203
+
204
+ Now that login support is in place you can test out one of the OAuth controllers by navigating to the following url:
205
+ http://localhost:3301/oauth/register
206
+
207
+ Since the camping-oauth plugin installed a :before filter on the OAuthRegisterApplication controller requiring user login, you should be redirected first to the login page. Since we created a default account when running the migration, login as admin with camping as the password. Once logged in you should be redirected back to the OAuth Application Registration page.
208
+
209
+ As a side note, you can style all common OAuth views later using CSS.
210
+ We'll let you add the SignUp controller and its signup view on your own.
211
+
212
+ ===Adding our custom API, protected by OAuth
213
+
214
+ Since the premise of this post was to make it easy for web apps to consume an OAuth-protected service, let's create a very simple controller (no view needed) to expose some data as JSON.
215
+
216
+ class APITimeNow < R '/api/timenow'
217
+ def get
218
+ @result = {:now=>Time.now.utc.to_s}
219
+ @result[:username] = @user.username if @user
220
+
221
+ @headers['Content-Type'] = "application/json"
222
+ log_debug @result.to_json
223
+ @result.to_json
224
+ end
225
+ end
226
+
227
+ Now we can test it by navigating to the following url (after installing the JSONview plugin for FireFox to make it easier to see the returned JSON data):
228
+ http://localhost:3301/api/timenow
229
+
230
+ Note that at this point this controller is NOT YET protected by OAuth. For that we need to declare a before filter for the APITimeNow controller requiring to be either logged in or OAuth-authenticated. So let's add this code snippet to our main module:
231
+
232
+ module GatedCampingSite
233
+ # ...
234
+
235
+ before [:APITimeNow] do
236
+ login_or_oauth_required
237
+ end
238
+
239
+ # ...
240
+ end
241
+
242
+ So now if we logged out (by deleting the session cookies since we have not implemented logoff) and refreshed our browser we would be redirected to the login page.
243
+
244
+ ==Testing And Troubleshooting
245
+
246
+ At this stage, we have a basic Camping OAuth provider, now let's test it! The first thing is to register a new OAuth consumer named camping-oauth-consumer. We'll assume that:
247
+
248
+ 1. it is located at http://localhost:3000/ (fictitious for now)
249
+ 2. it exposes a url: http://localhost:3000/callback to accept an OAuth token once authorized
250
+
251
+ Once you register you should see the a page with the registration results. The key and secret will be used by our consumer as credentials when accessing our OAuth provider, so copy/paste them into a notepad.
252
+
253
+ For our first test consumer will use IRB, so open up a session and let's define 3 variables for: url of our provider, key and secret (use your own values) of our registered consumer:
254
+
255
+ @site={:site=>"http://localhost:3301"}
256
+ @mykey="SQnIXDQyhFB5q3wfZyMY"
257
+ @mysecret="PmW02FNs7rXG97sAVXMWhFoJVZ98cnj21vv6p1ad"
258
+
259
+ Now let's require oauth and let's instantiate an OAuth consumer:
260
+
261
+ require 'oauth'
262
+ @consumer = OAuth::Consumer.new(@mykey,@mysecret,@site)
263
+
264
+ You should get an instance of a OAuth::Consumer back. Our next step is to request an OAuth RequestToken like so:
265
+
266
+ @request_token = @consumer.get_request_token
267
+
268
+ You should get an OAuth::RequestToken back. Let's see how and where we should authorize this request token:
269
+ http://localhost:3301/oauth/authorize?oauth_token=0Qd6g3SjWHQEM6sUTcd9
270
+
271
+ We should be prompted by the OAuth Authorization controller of our provider. If you click on the checkbox and the Authorize button, the provider will redirect you to the callback url we defined during registration passing back the Oauth token id and and a verifier code. Since we don't have a consumer web app up and running, we will get a navigation error. Here is what the target (redirection) url looks like:
272
+ http://localhost:3000/callback?oauth_token=0Qd6g3SjWHQEM6sUTcd9&oauth_verifier=71Jt3GhiwvHlZYO9zA8c
273
+
274
+ This verifier acts as a sort of session id we need to pass to get an OAuth Access Token. So from our IRB session, let's evaluate the following statement:
275
+
276
+ @verifier = '71Jt3GhiwvHlZYO9zA8c'
277
+ @access_token = @request_token.get_access_token(:oauth_verifier=>@verifier)
278
+
279
+ You should get an instance of OAuth::AccessToken back. So now let's call our provider api:
280
+
281
+ @response = @access_token.get('/api/timenow')
282
+ @info = @response.body
283
+
284
+ You should get back a JSON object. So this concludes our whirlwind tour of OAuth from a provider and consumer side.
285
+
286
+ ===Examples Source Code
287
+ Also if you look in the examples folder of the camping-oauth gem you will find the full source for both a provider (the one we have been working on) and a consumer app (to be run on port 3302).
288
+
289
+
290
+
291
+ =More information
292
+ Check for updates :
293
+ - http://blog.monnet-usa.com
294
+ =end
295
+
296
+ require 'oauth'
297
+
298
+ module OAuth::RequestProxy
299
+ class Base
300
+ alias :original_header_params :header_params
301
+
302
+ # Monkey-patched to provide an opportunity to add logging support
303
+ def header_params
304
+ logger = Logger.new(File.dirname(__FILE__) + '/camping-oauth.log')
305
+
306
+ begin
307
+ logger.debug "header_params> request[HTTP_AUTHORIZATION]=#{@request.env['HTTP_AUTHORIZATION']}"
308
+ hps = original_header_params
309
+ logger.debug "header_params> result=#{hps.inspect}"
310
+ hps
311
+ rescue
312
+ logger.debug "header_params> returning {}"
313
+ {}
314
+ end
315
+ end
316
+ end
317
+
318
+ class RackRequest < OAuth::RequestProxy::Base
319
+ protected
320
+ # as of oauth 0.4.0 this method needs to be patched to work with the latest version of Rack
321
+ def request_params
322
+ request.POST
323
+ end
324
+ end
325
+ end
326
+
327
+ gem 'oauth-plugin'
328
+
329
+ require 'activerecord'
330
+
331
+ # Main module for the OAuth Camping Plugin
332
+ #
333
+ module OAuthCampingPlugin
334
+ @@logger = nil
335
+
336
+ # Logger for the OAuthCampingPlugin - can be assigned the main logger for the main web app
337
+ def self.logger
338
+ @@logger
339
+ end
340
+
341
+ def self.logger=(a_logger)
342
+ @@logger = a_logger
343
+ end
344
+
345
+ # Provides a hook to initialize the plugin in the context of the main web app module
346
+ def self.create
347
+ end
348
+ end
349
+
350
+ # Helpers module for OAuth Camping Plugin.
351
+ # The module will be plugged in to the main app Helpers module.
352
+ # Its methods will be added to Controllers and Views.
353
+ # Example:
354
+ # module CampingOAuthProvider::Helpers
355
+ # extend OAuthCampingPlugin::Helpers
356
+ # include OAuthCampingPlugin::Helpers
357
+ # end
358
+ #
359
+ module OAuthCampingPlugin::Helpers
360
+
361
+ # Logs a specific message if in debug mode
362
+ def log_debug(msg)
363
+ OAuthCampingPlugin.logger.debug(msg) if OAuthCampingPlugin.logger && OAuthCampingPlugin.logger.debug?
364
+ end
365
+
366
+ # Reverse engineers the main app module
367
+ def app_module
368
+ app_module_name = self.class.to_s.split("::").first
369
+ app_module = app_module_name.constantize
370
+ end
371
+
372
+ # Reverse engineers the main User model class
373
+ def user_class
374
+ app_module_name = self.class.to_s.split("::").first
375
+ user_class_name = "#{app_module_name}::Models::User"
376
+ user_class_name.constantize
377
+ end
378
+
379
+ # Reverse engineers the main OauthNonce model class
380
+ def nonce_class
381
+ app_module_name = self.class.to_s.split("::").first
382
+ nonce_class_name = "#{app_module_name}::Models::OauthNonce"
383
+ nonce_class_name.constantize
384
+ end
385
+
386
+ # Looks up the user based on saved state (if any) and assigns it to the @user variable
387
+ def set_user
388
+ @user = user_class.find(@state.user_id) if @user.nil? && !@state.nil? && !@state.user_id.nil?
389
+ end
390
+
391
+ # Returns the current user model instance
392
+ def current_user
393
+ @user
394
+ end
395
+
396
+ # Returns whether or not the user is logged in
397
+ # Typically used within a controller before filter such as in:
398
+ # before :OAuthRegisterApplication do
399
+ # login_required
400
+ # end
401
+ def login_required
402
+ return true if @user
403
+ access_denied
404
+ return false
405
+ end
406
+
407
+ # Redirects to the login page with an access denied error message
408
+ def access_denied
409
+ @state.return_to = @request.url
410
+ @info = 'Oops. You need to login before you can view that page.'
411
+ redirect('/login')
412
+ end
413
+
414
+ end
415
+
416
+ # Filters module for OAuth Camping Plugin.
417
+ # The module will be plugged in to the main app Helpers module.
418
+ # Example:
419
+ # module CampingOAuthProvider
420
+ # include Camping::Session
421
+ # include CampingFilters
422
+ # extend OAuthCampingPlugin
423
+ # include OAuthCampingPlugin::Filters
424
+ #
425
+ # # ...
426
+ # end
427
+ #
428
+ module OAuthCampingPlugin::Filters
429
+ # Adds 3 before filters for the common OAuth controllers:
430
+ # - OAuthRegisterApplication
431
+ # - OAuthProvideRequestToken
432
+ # - OAuthProvideAccessToken
433
+ # Also adds a before filter on all controllers to ensure the user is set
434
+ def self.included(mod)
435
+ mod.module_eval do
436
+ before :all do
437
+ set_user
438
+ end
439
+
440
+ before :OAuthRegisterApplication do
441
+ login_required
442
+ end
443
+
444
+ before :OAuthProvideRequestToken do
445
+ verify_oauth_consumer_signature
446
+ end
447
+
448
+ before :OAuthProvideAccessToken do
449
+ verify_oauth_request_token
450
+ end
451
+ end
452
+ end
453
+ end
454
+
455
+ # OAuth module for OAuth Camping Plugin.
456
+ # The module will be plugged into all controllers either:
457
+ # - directly such as in the standard common OAuth controllers (e.g. OAuthProvideRequestToken)
458
+ # - or indirectly via the include_oauth_controllers of the OAuthCampingPlugin::Controllers module
459
+ # The module provides accessors, helper, authentication, signing, and authorization methods specific to OAuth
460
+ #
461
+ module OAuthCampingPlugin::OAuth
462
+
463
+ protected
464
+
465
+ # Returns the current token
466
+ def current_token
467
+ @current_token
468
+ end
469
+
470
+ # Returns the current client application
471
+ def current_client_application
472
+ @current_client_application
473
+ end
474
+
475
+ # Returns the class of the client application
476
+ def client_application_class
477
+ app_module_name = self.class.to_s.split("::").first
478
+ client_application_class_name = "#{app_module_name}::Models::ClientApplication"
479
+ client_application_class_name.constantize
480
+ end
481
+
482
+ # Returns the class of the current token
483
+ def request_token_class
484
+ app_module_name = self.class.to_s.split("::").first
485
+ request_token_class_name = "#{app_module_name}::Models::RequestToken"
486
+ request_token_class_name.constantize
487
+ end
488
+
489
+ # Returns the class of the access token
490
+ def access_token_class
491
+ app_module_name = self.class.to_s.split("::").first
492
+ access_token_class_name = "#{app_module_name}::Models::AccessToken"
493
+ access_token_class_name.constantize
494
+ end
495
+
496
+ # Parses the HTTP_AUTHORIZATION header for OAuth parameters
497
+ # and returns the params in a hash.
498
+ def oauth_header_params
499
+ oauth_header = @env['HTTP_AUTHORIZATION']
500
+ # parse the header into a Hash
501
+ oauth_params = OAuth::Helper.parse_header(oauth_header)
502
+
503
+ # remove non-OAuth parameters
504
+ oauth_params.reject! { |k,v| k !~ /^oauth_/ }
505
+ oauth_params
506
+ end
507
+
508
+ # Authenticates the current request by verifying the signature in the current token
509
+ # and ensuring that it is an access token
510
+ def oauthenticate
511
+ verified=verify_oauth_signature
512
+
513
+ return verified && current_token.is_a?(access_token_class)
514
+ end
515
+
516
+ # Returns whether or not the current request is authenticated
517
+ def oauth?
518
+ current_token!=nil
519
+ end
520
+
521
+ # Returns whether or not the current request is authorized
522
+ def authorized? # added by @techarch
523
+ return false unless current_token
524
+ current_token.authorized?
525
+ end
526
+
527
+ # Ensures that the current controller request is authorized via OAuth.
528
+ # This method is typically used as a precondition in a before_filter.
529
+ # Example:
530
+ # before [:APITimeNow] do
531
+ # login_or_oauth_required
532
+ # end
533
+ def oauth_required
534
+ if oauthenticate
535
+ if authorized?
536
+ return true
537
+ else
538
+ invalid_oauth_response
539
+ end
540
+ else
541
+ invalid_oauth_response
542
+ end
543
+ end
544
+
545
+ # Ensures that the current controller request is authorized either via:
546
+ # - the application login system
547
+ # - or via OAuth
548
+ # This method is typically used as a precondition in a before_filter.
549
+ # Example:
550
+ # before [:APITimeNow] do
551
+ # login_or_oauth_required
552
+ # end
553
+ def login_or_oauth_required
554
+ if oauthenticate
555
+ if authorized?
556
+ return true
557
+ else
558
+ invalid_oauth_response
559
+ end
560
+ else
561
+ login_required
562
+ end
563
+ end
564
+
565
+ # Verifies that a request token request (signature) is valid for a given consumer clien application
566
+ def verify_oauth_consumer_signature
567
+ begin
568
+ valid = client_application_class.verify_request(request) do |request_proxy|
569
+ @current_client_application = client_application_class.find_by_key(request_proxy.consumer_key)
570
+ # Store this temporarily in client_application object for use in request token generation
571
+ @current_client_application.token_callback_url=request_proxy.oauth_callback if request_proxy.oauth_callback
572
+
573
+ # return the token secret and the consumer secret
574
+ [nil, @current_client_application.secret]
575
+ end
576
+ rescue Exception => e
577
+ log_debug e.message
578
+ log_debug e.backtrace.inspect
579
+ valid=false
580
+ end
581
+
582
+ invalid_oauth_response unless valid
583
+ end
584
+
585
+ # Verifies that a request token request (signature) is valid
586
+ def verify_oauth_request_token
587
+ verify_oauth_signature && current_token.is_a?(request_token_class)
588
+ end
589
+
590
+ # Returns a 401 HTTP code if OAuth denied the request
591
+ def invalid_oauth_response(code=401,message="Invalid OAuth Request")
592
+ r(code, {}, message)
593
+ end
594
+
595
+ private
596
+
597
+ # Assigns the current token
598
+ def current_token=(token)
599
+ @current_token=token
600
+ if @current_token
601
+ @current_user=@current_token.user
602
+ @current_client_application=@current_token.client_application
603
+ end
604
+ @current_token
605
+ end
606
+
607
+ # Verifies the OAuth signature of the current request
608
+ def verify_oauth_signature
609
+ begin
610
+ valid = client_application_class.verify_request(request) do |request_proxy|
611
+ self.current_token = client_application_class.find_token(request_proxy.token)
612
+
613
+ if self.current_token.respond_to?(:provided_oauth_verifier=)
614
+ self.current_token.provided_oauth_verifier=request_proxy.oauth_verifier
615
+ end
616
+
617
+ # return the token secret and the consumer secret
618
+ [(current_token.nil? ? nil : current_token.secret), (current_client_application.nil? ? nil : current_client_application.secret)]
619
+ end
620
+
621
+ # reset @current_user to clear state for restful_...._authentication
622
+ @current_user = nil if (!valid)
623
+ valid
624
+ rescue
625
+ false
626
+ end
627
+ end
628
+
629
+ end
630
+
631
+ # Models module for the OAuth Camping Plugin.
632
+ # The module will be plugged in to the main app models module.
633
+ # Example:
634
+ # module CampingOAuthProvider::Models
635
+ # include OAuthCampingPlugin::Models
636
+ #
637
+ # class User < Base;
638
+ # has_many :client_applications
639
+ # has_many :tokens, :class_name=>"OauthToken",:order=>"authorized_at desc",:include=>[:client_application]
640
+ #
641
+ # end
642
+ # # ...
643
+ # end
644
+ #
645
+ # This module requires the oauth-plugin gem to be installed as it will load the following models
646
+ # - ClientApplication
647
+ # - OauthToken
648
+ # - OathNonce
649
+ # - RequestToken
650
+ # - AccessToken
651
+ #
652
+ module OAuthCampingPlugin::Models
653
+
654
+ # Loads the 5 standard OAuth models defined in the oauth-plugin gem
655
+ def self.included(mod)
656
+ oauth_plugin_gem = Gem::loaded_specs['oauth-plugin']
657
+ oauth_plugin_path = oauth_plugin_gem.full_gem_path
658
+ provider_template_path = oauth_plugin_path + '/generators/oauth_provider/templates'
659
+
660
+ %w(
661
+ client_application.rb
662
+ oauth_token.rb
663
+ oauth_nonce.rb
664
+ request_token.rb
665
+ access_token.rb
666
+ ).each { |lib| mod.module_eval(File.read("#{provider_template_path}/#{lib}")) }
667
+
668
+ # @techarch : Reset the table names back to pre-Camping
669
+ mod.module_eval do
670
+ mod::ClientApplication.class_eval { set_table_name "client_applications" }
671
+
672
+ mod::ClientApplication.class_eval do
673
+ def self.verify_request(request, options = {}, &block)
674
+ begin
675
+ signature = OAuth::Signature.build(request, options, &block)
676
+
677
+ app_module_name = self.to_s.split("::").first
678
+ nonce_class_name = "#{app_module_name}::Models::OauthNonce"
679
+ nonce_class = nonce_class_name.constantize
680
+
681
+ return false unless nonce_class.remember(signature.request.nonce, signature.request.timestamp)
682
+
683
+ value = signature.verify
684
+ value
685
+ rescue OAuth::Signature::UnknownSignatureMethod => e
686
+ false
687
+ end
688
+ end
689
+ end
690
+
691
+ mod::OauthToken.class_eval { set_table_name "oauth_tokens" }
692
+ mod::OauthNonce.class_eval { set_table_name "oauth_nonces" }
693
+ end
694
+ end
695
+
696
+ # Up-migrates the schema definition for the 5 OAuth models
697
+ def self.up
698
+ ActiveRecord::Schema.define do
699
+ create_table :client_applications do |t|
700
+ t.string :name
701
+ t.string :url
702
+ t.string :support_url
703
+ t.string :callback_url
704
+ t.string :key, :limit => 20
705
+ t.string :secret, :limit => 40
706
+ t.integer :user_id
707
+
708
+ t.timestamps
709
+ end
710
+
711
+ add_index :client_applications, :key, :unique
712
+
713
+ create_table :oauth_tokens do |t|
714
+ t.integer :user_id
715
+ t.string :type, :limit => 20
716
+ t.integer :client_application_id
717
+ t.string :token, :limit => 20
718
+ t.string :secret, :limit => 40
719
+ t.string :callback_url
720
+ t.string :verifier, :limit => 20
721
+ t.timestamp :authorized_at, :invalidated_at
722
+ t.timestamps
723
+ end
724
+
725
+ add_index :oauth_tokens, :token, :unique
726
+
727
+ create_table :oauth_nonces do |t|
728
+ t.string :nonce
729
+ t.integer :timestamp
730
+
731
+ t.timestamps
732
+ end
733
+
734
+ add_index :oauth_nonces,[:nonce, :timestamp], :unique
735
+
736
+ end
737
+ end
738
+
739
+ # Down-migrates the schema definition for the 5 OAuth models
740
+ def self.down
741
+ ActiveRecord::Schema.define do
742
+ drop_table :client_applications
743
+ drop_table :oauth_tokens
744
+ drop_table :oauth_nonces
745
+ end
746
+ end
747
+
748
+ end
749
+
750
+ # Controllers module for the OAuth Camping Plugin.
751
+ # The module will be plugged in to the main app controllers module using:
752
+ # - extend to add class methods to the app controllers module
753
+ # - include_oauth_controllers to dynamically plugin the OAuth and Helpers modules inside each controller class
754
+ # (this is why the call must be the last statement in the controllers module)
755
+ #
756
+ # Example:
757
+ # module CampingOAuthProvider::Controllers
758
+ # extend OAuthCampingPlugin::Controllers
759
+ #
760
+ # # ...
761
+ #
762
+ # include_oauth_controllers
763
+ # end
764
+ #
765
+ module OAuthCampingPlugin::Controllers
766
+
767
+ # Returns the source code for all common OAuth controllers
768
+ def self.common_oauth_controllers
769
+ <<-CLASS_DEFS
770
+
771
+ class OAuthRegisterApplication < R '/oauth/register'
772
+ def get
773
+ @application= ClientApplication.new
774
+ render :new_application_registration
775
+ end
776
+
777
+ def post
778
+ @user = User.find(@state.user_id)
779
+ if !@user
780
+ return "login first"
781
+ end
782
+
783
+ @application = ClientApplication.find_by_user_id_and_name(@state.user_id, input.name)
784
+ if @application
785
+ @info = 'You already have an application with this name.'
786
+ else
787
+ @application = ClientApplication.new :user_id => @state.user_id,
788
+ :name => input.name,
789
+ :url => input.url,
790
+ :support_url => input.support_url,
791
+ :callback_url => input.callback_url
792
+
793
+ @user.client_applications << @application
794
+
795
+ @application.save
796
+ if @application
797
+ return(render(:application_registration))
798
+ else
799
+ @info = @application.errors.full_messages unless @application.errors.empty?
800
+ end
801
+ end
802
+
803
+ render :new_application_registration
804
+ end
805
+ end
806
+
807
+ class OAuthProvideRequestToken < R '/oauth/request_token'
808
+ include OAuthCampingPlugin::OAuth
809
+
810
+ def post
811
+ oauth_consumer_key = oauth_header_params['oauth_consumer_key']
812
+
813
+ @application = ClientApplication.find_by_key(oauth_consumer_key)
814
+ @token = @application.create_request_token
815
+ log_debug 'OAuthProvideRequestToken> request token for oauth_consumer_key:' + oauth_consumer_key + '=' + @token.inspect
816
+ @token.to_query
817
+ end
818
+ end
819
+
820
+ class OAuthAuthorizeToken < R '/oauth/authorize'
821
+ include OAuthCampingPlugin::OAuth
822
+
823
+ def get
824
+ @oauth_token = input.oauth_token
825
+ render :authorize
826
+ end
827
+
828
+ def post
829
+ @token = RequestToken.find_by_token input.oauth_token
830
+ return(render(:authorize_failure_token_not_found)) if @token.nil?
831
+
832
+ return(render(:authorize_failure_invalidated)) if @token.invalidated?
833
+
834
+ return(render(:authorize_failure)) unless user_authorizes_token?
835
+
836
+ @token.authorize!(current_user)
837
+ log_debug 'OAuthAuthorizeToken> request token=' + @token.inspect
838
+
839
+ if @token.oauth10?
840
+ @redirect_url = input.oauth_callback || @token.client_application.callback_url
841
+ else
842
+ @redirect_url = (@token.oob? || @token.callback_url.nil?) ? @token.client_application.callback_url : @token.callback_url
843
+ end
844
+
845
+ return(render(:authorize_success)) unless @redirect_url
846
+
847
+ @full_redirect_url = @token.oauth10? ? (@redirect_url + '?oauth_token=' + @token.token) : (@redirect_url + '?oauth_token=' + @token.token + '&oauth_verifier=' + @token.verifier)
848
+
849
+ redirect @full_redirect_url
850
+ end
851
+
852
+ # Override this to match your authorization page form
853
+ def user_authorizes_token?
854
+ input.authorize == '1' || input.authorize == 'on'
855
+ end
856
+ end
857
+
858
+ class OAuthRevokeToken < R '/oauth/revoke'
859
+ include OAuthCampingPlugin::OAuth
860
+
861
+ def get
862
+ @token = OauthToken.find_by_token(input.oauth_token)
863
+ return(render(:authorize_failure_token_not_found)) if @token.nil?
864
+
865
+ render :revoke
866
+ end
867
+
868
+ def post
869
+ @token = OauthToken.find_by_token(input.oauth_token)
870
+ return(render(:authorize_failure_token_not_found)) if @token.nil?
871
+
872
+ if input.revoke != 'on'
873
+ @info = "You did not confirm you wanted to revoke this token. Check the checkbox to confirm."
874
+ return(render(:revoke))
875
+ end
876
+
877
+ @token.invalidate!
878
+ log_debug 'OAuthRevokeToken> access token=' + @token.inspect
879
+
880
+ render :revoke_success
881
+ end
882
+ end
883
+
884
+ class OAuthProvideAccessToken < R '/oauth/access_token'
885
+ include OAuthCampingPlugin::OAuth
886
+
887
+ def post
888
+ log_debug 'OAuthProvideAccessToken> @current_token=' + self.current_token.inspect
889
+
890
+ return(r(401,'')) if self.current_token.nil?
891
+
892
+ @token = self.current_token.exchange!
893
+ log_debug 'OAuthProvideAccessToken> access token=' + @token.inspect
894
+
895
+ return(r(401,'')) if self.current_token.nil?
896
+ @token.to_query
897
+
898
+ end #post
899
+ end
900
+
901
+ CLASS_DEFS
902
+ end
903
+
904
+ # Includes the OAuth and Helpers modules inside each controller class using class_eval
905
+ # (this is why the call must be the last statement in the controllers module)
906
+ def include_oauth_controllers
907
+ module_eval OAuthCampingPlugin::Controllers.common_oauth_controllers
908
+
909
+ # Add Oauth to each controller
910
+ r.each do |x|
911
+ x.class_eval do
912
+ include OAuthCampingPlugin::OAuth
913
+ include OAuthCampingPlugin::Helpers
914
+ end
915
+ end
916
+ end
917
+ end
918
+
919
+ # Views module for the OAuth Camping Plugin.
920
+ # The module will be plugged in to the main app views module using:
921
+ # - extend to add class methods to the app views module
922
+ # - include_oauth_views to dynamically plugin the common OAuth views (e.g. authorize_view)
923
+ #
924
+ # Example:
925
+ # module CampingOAuthProvider::Views
926
+ # extend OAuthCampingPlugin::Views
927
+ #
928
+ # # ...
929
+ #
930
+ # include_oauth_views
931
+ # end
932
+ #
933
+ module OAuthCampingPlugin::Views
934
+
935
+ # Returns the source code for all common OAuth views such as error views (e.g. authorize_failure)
936
+ def self.common_oauth_views
937
+ <<-VIEW_DEFS
938
+
939
+ def authorize_failure
940
+ h1 "You have denied access to this token"
941
+ end
942
+
943
+ def authorize_failure_token_not_found
944
+ h1 "Token not found"
945
+ end
946
+
947
+ def authorize_failure_invalidated
948
+ h1 "Token could not be authorized since it has become invalid"
949
+ end
950
+
951
+ def authorize_success
952
+ h1 "You have successfully authorized access to this token"
953
+ p @info
954
+ end
955
+
956
+ def revoke_success
957
+ h1 "You have successfully revoked access to this token"
958
+ p @info
959
+ end
960
+ VIEW_DEFS
961
+ end
962
+
963
+ # Returns the source code for the register_view
964
+ def self.register_view
965
+ <<-VIEW
966
+
967
+ def new_application_registration
968
+ h2 "New OAuth Consumer"
969
+ h3 "Application Registration"
970
+ div.info @info if @info
971
+ form.new_app_reg! :action => R(OAuthRegisterApplication), :method => 'post' do
972
+ label 'Name (*)', :for => 'name'; br
973
+ input.app_name! :name => 'name', :type => 'text'; br
974
+
975
+ label 'Url (*)', :for => 'url'; br
976
+ input.url :name => 'url', :type => 'text'; br
977
+
978
+ label 'Callback Url (*)', :for => 'callback_url'; br
979
+ input.url :name => 'callback_url', :type => 'text'; br;
980
+
981
+ label 'Support Url', :for => 'support_url'; br
982
+ input.url :name => 'support_url', :type => 'text'; br;br;
983
+
984
+ input :type => 'submit', :name => 'signup', :value => 'Register'
985
+ end
986
+ end
987
+
988
+ VIEW
989
+ end
990
+
991
+ # Returns the source code for the registration_view
992
+ def self.registration_view
993
+ <<-VIEW
994
+
995
+ def application_registration
996
+ h2 "Application Registration"
997
+ div @info if @info
998
+
999
+ table.application_registration do
1000
+ tr { td "Name"; td @application.name}
1001
+ tr { td "Url"; td @application.url}
1002
+ tr { td "Support Url"; td @application.support_url}
1003
+ tr { td "Callback Url"; td @application.callback_url}
1004
+ tr { td "Key"; td @application.key}
1005
+ tr { td "Secret"; td @application.secret}
1006
+ end
1007
+ end
1008
+
1009
+ VIEW
1010
+ end
1011
+
1012
+ # Returns the source code for the authorize_view
1013
+ def self.authorize_view
1014
+ <<-VIEW
1015
+
1016
+ def authorize
1017
+ div @info if @info
1018
+ form :action => R(OAuthAuthorizeToken), :method => 'post' do
1019
+ input :name => 'oauth_token', :type=>'hidden', :value=>@oauth_token;
1020
+ input :name => 'authorize', :type=>'checkbox';
1021
+ label 'Authorize token ' + @oauth_token, :for => 'authorize'; br
1022
+
1023
+ input :type => 'submit', :name => 'authorize_btn', :value => 'Authorize'
1024
+ a "Cancel", :href=>"/applications"
1025
+ end
1026
+ end
1027
+
1028
+ VIEW
1029
+ end
1030
+
1031
+ # Returns the source code for the revoke_view
1032
+ def self.revoke_view
1033
+ <<-VIEW
1034
+
1035
+ def revoke
1036
+ div @info if @info
1037
+ form :action => R(OAuthRevokeToken), :method => 'post' do
1038
+ input :name => 'oauth_token', :type=>'hidden', :value=>@token.token;
1039
+ input :name => 'revoke', :type=>'checkbox';
1040
+ label 'Revoke token ' + @token.token, :for => 'revoke'; br
1041
+
1042
+ input :type => 'submit', :name => 'revoke_btn', :value => 'Revoke'
1043
+ a "Cancel", :href=>"/applications"
1044
+ end
1045
+ end
1046
+
1047
+ VIEW
1048
+ end
1049
+
1050
+ # Includes all common OAuth views inside the views module using module_eval
1051
+ # (this is why the call must be the last statement in the views module)
1052
+ def include_oauth_views
1053
+ module_eval OAuthCampingPlugin::Views.common_oauth_views
1054
+
1055
+ module_eval do
1056
+ app_module_name = self.to_s.split("::").first
1057
+ mab_class_name = "#{app_module_name}::Mab"
1058
+ mab_class = mab_class_name.constantize
1059
+
1060
+ unless mab_class.public_instance_methods.include? 'register'
1061
+ module_eval OAuthCampingPlugin::Views.register_view
1062
+ end
1063
+
1064
+ unless mab_class.public_instance_methods.include? 'application_registration'
1065
+ module_eval OAuthCampingPlugin::Views.registration_view
1066
+ end
1067
+
1068
+ unless mab_class.public_instance_methods.include? 'authorize'
1069
+ module_eval OAuthCampingPlugin::Views.authorize_view
1070
+ end
1071
+
1072
+ unless mab_class.public_instance_methods.include? 'revoke'
1073
+ module_eval OAuthCampingPlugin::Views.revoke_view
1074
+ end
1075
+ end
1076
+
1077
+ end
1078
+ end