/
auth.js
57 lines (45 loc) · 1.6 KB
/
auth.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// Generated by CoffeeScript 1.4.0
/* Handle authentication of users via Shapeways
*/
(function() {
var Auth, OAuth, cfg;
cfg = require('../cfg/config.js');
OAuth = (require('oauth')).OAuth;
exports.Auth = Auth = (function() {
function Auth() {
var oa;
this.oa = oa = new OAuth(cfg.REQUEST_TOKEN_URL, cfg.ACCESS_TOKEN_URL, cfg.CUSTOMER_KEY, cfg.CUSTOMER_SECRET, '1.0', cfg.CALLBACK_URL, 'HMAC-SHA1');
}
Auth.prototype.login = function(callback) {
console.log('Getting OAuth Request Token');
return this.oa.getOAuthRequestToken(function(error, oauth_token, oauth_token_secret, results) {
var url;
if (error) {
console.log('error :' + JSON.stringify(error));
}
console.log(results);
url = results.authentication_url;
return callback({
oauth_token: oauth_token,
oauth_token_secret: oauth_token_secret,
url: url
});
});
};
Auth.prototype.handleCallback = function(oauth_token, oauth_token_secret, oauth_verifier, callback) {
return this.oa.getOAuthAccessToken(oauth_token, oauth_token_secret, oauth_verifier, function(error, oauth_access_token, oauth_access_token_secret, response) {
if (error) {
console.log('error :' + JSON.stringify(error));
}
if (response === void 0) {
console.log('error: ' + response);
}
return callback({
oauth_access_token: oauth_access_token,
oauth_access_token_secret: oauth_access_token_secret
});
});
};
return Auth;
})();
}).call(this);