|
18 | 18 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
19 | 19 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
20 | 20 | */ |
| 21 | +"use strict"; |
21 | 22 |
|
22 | | -var g = require('../global') |
| 23 | +var g = require('../global'); |
23 | 24 |
|
24 | 25 | module.exports = { |
25 | | - connect: function(url) { |
26 | | - return { |
27 | | - casLogin: function(ticket, callback) { |
28 | | - var path = g.format(url + '/users/login?ticket=%s', ticket); |
29 | | - g.getURL(path, callback); |
30 | | - }, |
31 | | - authenticate: function(username, apiKey, callback) { |
32 | | - var path = g.format(url + '/users/%s/authenticate', g.escape(username)); |
33 | | - g.info(g.format("POST %s", path)); |
34 | | - g.rest.post(path, { data: apiKey }).on('complete', function(token, response) { |
35 | | - if ( token instanceof Error) |
36 | | - return callback(token); |
37 | | - else if ( response.statusCode !== 200 ) |
38 | | - return callback(g.format("POST %s failed : %s", path, response.statusCode)); |
39 | | - |
40 | | - callback(null, token); |
41 | | - }) |
42 | | - } |
| 26 | + connect: function (url) { |
| 27 | + return { |
| 28 | + casLogin: function (ticket, callback) { |
| 29 | + var path = g.format(url + '/users/login?ticket=%s', ticket); |
| 30 | + g.getURL(path, callback); |
| 31 | + }, |
| 32 | + authenticate: function (username, apiKey, callback) { |
| 33 | + var path = g.format(url + '/users/%s/authenticate', g.escape(username)); |
| 34 | + g.info(g.format("POST %s", path)); |
| 35 | + g.rest.post(path, {data: apiKey}).on('complete', function (token, response) { |
| 36 | + if (token instanceof Error){ |
| 37 | + return callback(token); |
| 38 | + } |
| 39 | + if (response.statusCode !== 200) { |
| 40 | + return callback(g.format("POST %s failed : %s", path, response.statusCode)); |
| 41 | + } |
| 42 | + callback(null, token); |
| 43 | + }); |
| 44 | + } |
| 45 | + }; |
| 46 | + }, |
| 47 | + username: function (token) { |
| 48 | + return g.username(token); |
| 49 | + }, |
| 50 | + tokenHeader: function (token) { |
| 51 | + return g.format('Token token="%s"', new Buffer(JSON.stringify(token)).toString('base64')); |
43 | 52 | } |
44 | | - }, |
45 | | - username: function(token) { |
46 | | - return g.username(token); |
47 | | - }, |
48 | | - tokenHeader: function(token) { |
49 | | - return g.format('Token token="%s"', new Buffer(JSON.stringify(token)).toString('base64')) |
50 | | - } |
51 | | -} |
| 53 | +}; |
0 commit comments