6419c7dd4bf04c92f99497db0a02a27562fc43a1
[acontent.git] / docs / documentation / oauth_server_api.php
1 <?php\r
2 /************************************************************************/\r
3 /* AContent                                                             */\r
4 /************************************************************************/\r
5 /* Copyright (c) 2010                                                   */\r
6 /* Inclusive Design Institute                                           */\r
7 /*                                                                      */\r
8 /* This program is free software. You can redistribute it and/or        */\r
9 /* modify it under the terms of the GNU General Public License          */\r
10 /* as published by the Free Software Foundation.                        */\r
11 /************************************************************************/\r
12 \r
13 define('TR_INCLUDE_PATH', '../include/');\r
14 \r
15 include(TR_INCLUDE_PATH.'vitals.inc.php');\r
16 include(TR_INCLUDE_PATH.'header.inc.php');\r
17 ?>\r
18 <div class="output-form" style="line-height:150%">\r
19 \r
20 <h1>OAuth Server API</h1>\r
21 <p>AContent implements the OAuth Core 1.0 specification.</p>\r
22 <p>The <a href="http://oauth.net/documentation/getting-started" target="new">OAuth</a> protocol enables web service consumers to access protected resources via an API without requiring users to supply the service credentials to the consumers. It's a generic methodology for unobtrusive, wire protocol level authenticated data access over HTTP.</p>\r
23 \r
24 <p>AContent exposes the following API endpoints:</p>\r
25 \r
26     <div id="toc">\r
27       <ul>\r
28         <li><a href="<?php echo TR_BASE_HREF.'documentation/oauth_server_api.php'; ?>#register_consumer">Register consumer</a></li>\r
29         <li><a href="<?php echo TR_BASE_HREF.'documentation/oauth_server_api.php'; ?>#request_token">Request token</a></li>\r
30         <li><a href="<?php echo TR_BASE_HREF.'documentation/oauth_server_api.php'; ?>#authorization">Authorization</a></li>\r
31         <li><a href="<?php echo TR_BASE_HREF.'documentation/oauth_server_api.php'; ?>#access_token">Access token</a></li>\r
32         <li><a href="<?php echo TR_BASE_HREF.'documentation/oauth_server_api.php'; ?>#import">Import Common Cartridge or Content Package into AContent</a></li>\r
33       </ul>\r
34     </div>\r
35     \r
36     <p id="skip"></p>\r
37 \r
38 <h2 id="register_consumer">Register consumer</h2>\r
39 \r
40 <h3>Endpoint: </h3><p>http://server-cname/oauth/register_consumer.php</p>\r
41 <h3>Parameters</h3><br />\r
42 \r
43 <table class="data" rules="all">\r
44 <tbody><tr>\r
45 <th>Parameter</th><th>Description</th><th>Default value</th>\r
46 </tr>\r
47 \r
48 <tr>\r
49   <th>consumer</th>\r
50   <td>Required. The encoded string of consumer name.</td>\r
51   <td>None</td>\r
52 </tr>\r
53 \r
54 <tr>\r
55   <th>expire</th>\r
56   <td>Optional. The length of time in seconds that the access token is valid. The access token expires after this number of seconds since being assigned. When "expire" is set to 0, the access token never expires.</td>\r
57   <td>0</td>\r
58 </tr>\r
59 \r
60 </tbody></table>\r
61 <br />\r
62 \r
63 <h3>Example</h3><br />\r
64 <span style="font-weight: bold">Request</span>\r
65 <pre style="background-color:#F7F3ED;"> \r
66 <?php echo TR_BASE_HREF; ?>oauth/register_consumer.php?consumer=http%3A%2F%2Flocalhost%2Facontent%2F&expire=300<br />\r
67 </pre>\r
68 <p>Goal: Registers consumer http://localhost/acontent/ and requests that the assigned access token expires in 5 minutes.</p>\r
69 \r
70 <span style="font-weight:bold">Success response</span>\r
71 <pre style="background-color:#F7F3ED;"> \r
72 consumer_key=8862a51faa12c1b1&consumer_secret=79d591810c803167&expire=300<br />\r
73 </pre>\r
74 <p>consumer_key and consumer_secret are both 16 characters long. expire_threshold confirms the access token expire duration.</p> \r
75 \r
76 <span style="font-weight:bold">Fail response</span>\r
77 <pre style="background-color:#F7F3ED;"> \r
78 error=Empty+parameter+%22consumer%22<br />\r
79 </pre>\r
80 <p>A fail response returns an error message.</p> \r
81 \r
82 <h2 id="request_token">Request token</h2>\r
83 \r
84 <h3>Endpoint: </h3><p>http://server-cname/oauth/request_token.php</p>\r
85 <h3>Parameters</h3><br />\r
86 <p>Both GET or POST methods are supported.</p>\r
87 \r
88 <table class="data" rules="all">\r
89 <tbody><tr>\r
90 <th>Parameter</th><th>Description</th><th>Default value</th>\r
91 </tr>\r
92 \r
93 <tr>\r
94   <th>oauth_consumer_key</th>\r
95   <td>Required. The consumer key.</td>\r
96   <td>None</td>\r
97 </tr>\r
98 \r
99 <tr>\r
100   <th>oauth_signature_method</th>\r
101   <td>Required. The signature method the Consumer used to sign the request.</td>\r
102   <td>None. <br /> Or, One of these values: HMAC-SHA1, RSA-SHA1, and PLAINTEXT.</td>\r
103 </tr>\r
104 \r
105 <tr>\r
106   <th>oauth_signature</th>\r
107   <td>Required. The signature as defined in <a href="http://oauth.net/core/1.0#signing_process">Signing Requests</a>.</td>\r
108   <td>None</td>\r
109 </tr>\r
110 \r
111 <tr>\r
112   <th>oauth_timestamp</th>\r
113   <td>Required. As defined in <a href="http://oauth.net/core/1.0#nonce">Nonce and Timestamp</a>.</td>\r
114   <td>None</td>\r
115 </tr>\r
116 \r
117 <tr>\r
118   <th>oauth_nonce</th>\r
119   <td>Required. As defined in <a href="http://oauth.net/core/1.0#nonce">Nonce and Timestamp</a>.</td>\r
120   <td>None</td>\r
121 </tr>\r
122 \r
123 <tr>\r
124   <th>oauth_version</th>\r
125   <td>OPTIONAL. If present, value MUST be 1.0.</td>\r
126   <td>1.0</td>\r
127 </tr>\r
128 \r
129 </tbody></table>\r
130 <br />\r
131 \r
132 <h3>Example</h3><br />\r
133 <span style="font-weight: bold">Request</span>\r
134 <pre style="background-color:#F7F3ED;"> \r
135 <?php echo TR_BASE_HREF; ?>oauth/request_token.php?oauth_consumer_key=8862a51faa12c1b1&<br />oauth_signature_method=HMAC-SHA1&oauth_signature=tVWpcskRSY34wxhv%2BP9NcgXuuGk%3D&<br />oauth_timestamp=1255524495&oauth_nonce=3e43dd6ce0e09614e79e2a4b53e124c8&oauth_version=1.0<br />\r
136 </pre>\r
137 \r
138 <span style="font-weight:bold">Success response</span>\r
139 <pre style="background-color:#F7F3ED;"> \r
140 oauth_token=086cbfe90b41a7fdf9&oauth_token_secret=55e2bd8454b2f75a21<br />\r
141 </pre>\r
142 <p>oauth_token and oauth_token_secret are both 18 characters long.</p> \r
143 \r
144 <span style="font-weight:bold">Fail response</span>\r
145 <pre style="background-color:#F7F3ED;"> \r
146 error=Consumer+is+not+registered<br />\r
147 </pre>\r
148 <p>A fail response returns an error message.</p> \r
149 \r
150 <h2 id="authorization">Authorization</h2>\r
151 \r
152 <h3>Endpoint: </h3><p>http://server-cname/oauth/authorization.php</p>\r
153 <h3>Parameters</h3><br />\r
154 \r
155 <table class="data" rules="all">\r
156 <tbody><tr>\r
157 <th>Parameter</th><th>Description</th><th>Default value</th>\r
158 </tr>\r
159 \r
160 <tr>\r
161   <th>oauth_token</th>\r
162   <td>Required. The Request Token obtained in the previous step.</td>\r
163   <td>None</td>\r
164 </tr>\r
165 \r
166 <tr>\r
167   <th>oauth_callback</th>\r
168   <td>Optional. The Consumer MAY specify a URL the Service Provider will use to redirect the User \r
169   back to the Consumer along with the request token when \r
170   <a href="http://oauth.net/core/1.0#auth_step2">Obtaining User Authorization</a> \r
171   is complete. If this parameter was not given or empty, the message "User was authenticated successfully" \r
172   will be returned as a success response.</td>\r
173   <td>0</td>\r
174 </tr>\r
175 \r
176 </tbody></table>\r
177 <br />\r
178 \r
179 <h3>Example</h3><br />\r
180 <span style="font-weight: bold">Request</span>\r
181 <pre style="background-color:#F7F3ED;"> \r
182 <?php echo TR_BASE_HREF; ?>oauth/authorization.php?oauth_token=086cbfe90b41a7fdf9&oauth_callback=<?php echo urlencode(TR_BASE_HREF);?><br />\r
183 </pre>\r
184 \r
185 <span style="font-weight:bold">Success response</span>\r
186 <p>Redirect the User back to the URL specified in oauth_callback along with the send-in request token "oauth_token". \r
187 If oauth_callback is not given or empty, the message "User was authenticated successfully" will be returned.</p> \r
188 \r
189 <span style="font-weight:bold">Fail response</span>\r
190 <pre style="background-color:#F7F3ED;"> \r
191 error=Empty+oauth+token<br />\r
192 </pre>\r
193 <p>A fail response returns an error message.</p> \r
194 \r
195 <h2 id="access_token">Access token</h2>\r
196 \r
197 <h3>Endpoint: </h3><p>http://server-cname/oauth/access_token.php</p>\r
198 <h3>Parameters</h3><br />\r
199 \r
200 <table class="data" rules="all">\r
201 <tbody><tr>\r
202 <th>Parameter</th><th>Description</th><th>Default value</th>\r
203 </tr>\r
204 \r
205 <tr>\r
206   <th>oauth_consumer_key</th>\r
207   <td>Required. The consumer key.</td>\r
208   <td>None</td>\r
209 </tr>\r
210 \r
211 <tr>\r
212   <th>oauth_token</th>\r
213   <td>Required. The Request Token obtained previously.</td>\r
214   <td>None.</td>\r
215 </tr>\r
216 \r
217 <tr>\r
218   <th>oauth_signature_method</th>\r
219   <td>Required. The signature method the Consumer used to sign the request.</td>\r
220   <td>None. <br /> Or, one of these values: HMAC-SHA1, RSA-SHA1, and PLAINTEXT.</td>\r
221 </tr>\r
222 \r
223 <tr>\r
224   <th>oauth_signature</th>\r
225   <td>Required. The signature as defined in <a href="http://oauth.net/core/1.0#signing_process">Signing Requests</a>.</td>\r
226   <td>None</td>\r
227 </tr>\r
228 \r
229 <tr>\r
230   <th>oauth_timestamp</th>\r
231   <td>Required. As defined in <a href="http://oauth.net/core/1.0#nonce">Nonce and Timestamp</a>.</td>\r
232   <td>None</td>\r
233 </tr>\r
234 \r
235 <tr>\r
236   <th>oauth_nonce</th>\r
237   <td>Required. As defined in <a href="http://oauth.net/core/1.0#nonce">Nonce and Timestamp</a>.</td>\r
238   <td>None</td>\r
239 </tr>\r
240 \r
241 <tr>\r
242   <th>oauth_version</th>\r
243   <td>OPTIONAL. If present, value MUST be 1.0.</td>\r
244   <td>1.0</td>\r
245 </tr>\r
246 \r
247 </tbody></table>\r
248 <br />\r
249 \r
250 <h3>Example</h3><br />\r
251 <span style="font-weight: bold">Request</span>\r
252 <pre style="background-color:#F7F3ED;"> \r
253 <?php echo TR_BASE_HREF; ?>oauth/access_token.php?oauth_consumer_key=8862a51faa12c1b1&oauth_token=086cbfe90b41a7fdf9&\r
254 oauth_signature_method=HMAC-SHA1&oauth_signature=tVWpcskRSY34wxhv%2BP9NcgXuuGk%3D&oauth_timestamp=1255524495&\r
255 oauth_nonce=3e43dd6ce0e09614e79e2a4b53e124c8&oauth_version=1.0<br />\r
256 </pre>\r
257 \r
258 <span style="font-weight:bold">Success response</span>\r
259 <pre style="background-color:#F7F3ED;"> \r
260 oauth_token=086cbfe90b41a7fdf9&oauth_token_secret=55e2bd8454b2f75a21<br />\r
261 </pre>\r
262 <p>oauth_token and oauth_token_secret are both 18 characters long.</p> \r
263 \r
264 <span style="font-weight:bold">Fail response</span>\r
265 <pre style="background-color:#F7F3ED;"> \r
266 error=Invalid+oauth+request+token<br />\r
267 </pre>\r
268 <p>A fail response returns an error message.</p> \r
269 <p>Note that the access token can be reused during the expire threshold is reached. Expire threshold is defined in the \r
270 <a href="<?php echo TR_BASE_HREF;?>documentation/oauth_server_api.php#register_consumer">register consumer request</a>.</p>\r
271 \r
272 <h2 id="import">Import Common Cartridge or Content Package into AContent</h2>\r
273 <p>Until here, with a set of token credentials, the client is now able to import common cartridges or content packages into\r
274 AContent as a new lesson. The generated course ID is returned at success. Or, an error message is returned at fail.</p>\r
275 <h3>Endpoint: </h3><p>http://server-cname/home/ims/ims_import.php</p>\r
276 <h3>Parameters</h3><br />\r
277 \r
278 <table class="data" rules="all">\r
279 <tbody><tr>\r
280 <th>Parameter</th><th>Description</th><th>Default value</th>\r
281 </tr>\r
282 \r
283 <tr>\r
284   <th>oauth_token</th>\r
285   <td>Required. The Access Token obtained previously.</td>\r
286   <td>None.</td>\r
287 </tr>\r
288 \r
289 <tr>\r
290   <th>url</th>\r
291   <td>Required. The URL pointing to a zip file of the common cartridge or content package.</td>\r
292   <td>None.</td>\r
293 </tr>\r
294 </tbody></table>\r
295 <br />\r
296 \r
297 <h3>Example</h3><br />\r
298 <span style="font-weight: bold">Request</span>\r
299 <pre style="background-color:#F7F3ED;"> \r
300 <?php echo TR_BASE_HREF; ?>home/ims/ims_import.php?oauth_token=9941b13ebc574a62d0&\r
301 url=http%3A%2F%2Fatutor.ca%2Fdemo%2Fmods%2F_core%2Fimscp%2Fims_export.php%3Fcid%3D0%26c%3D15%26m%3D7478785009a6629d0a5d5b5ff5850eb8<br />\r
302 </pre>\r
303 \r
304 <span style="font-weight:bold">Success response</span>\r
305 <pre style="background-color:#F7F3ED;"> \r
306 course_id=20<br />\r
307 </pre>\r
308 <p>course_id is the number ID of the newly-imported lesson. This ID can be used to view and download the imported lesson. \r
309 Refer to <a href="<?php echo TR_BASE_HREF;?>documentation/web_service_api.php">Web Service API</a> for details.</p> \r
310 \r
311 <span style="font-weight:bold">Fail response</span>\r
312 <pre style="background-color:#F7F3ED;"> \r
313 error=User+has+no+author+privilege<br />\r
314 error=Empty+OAuth+token<br />\r
315 error=Invalid+OAuth+token<br />\r
316 error=OAuth+token+expired<br />\r
317 error=Invalid+imported+file<br />\r
318 error=Cannot+create+import+directory<br />\r
319 error=IMS+manifest+file+does+not+appear+to+be+valid<br />\r
320 error=Error+at+parsing+IMS+manifest+file<br />\r
321 </pre>\r
322 <p>A fail response returns an error message. Could be any of the above.</p> \r
323 \r
324 <?php include(TR_INCLUDE_PATH.'footer.inc.php'); ?>\r