-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathwebtest.js
More file actions
43 lines (36 loc) · 1.48 KB
/
webtest.js
File metadata and controls
43 lines (36 loc) · 1.48 KB
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
var OAuth = require('./oauth').OAuth;
var express = require('express');
var app = express.createServer();
app.use(express.bodyParser());
app.use(express.errorHandler({showStack:true, dumpExceptions:true}));
var config = {
server: 'www.google.com',
requestTokenURI: 'https://www.google.com/accounts/OAuthGetRequestToken',
authorizeTokenURI: 'https://www.google.com/accounts/OAuthAuthorizeToken',
accessTokenURI: 'https://www.google.com/accounts/OAuthGetAccessToken',
signatureMethod: 'HMAC-SHA1',
consumerKey: 'anonymous',
consumerSecret: 'anonymous',
callbackURI: 'http://itea.sytes.net:8080/callback'
};
var oauth = new OAuth(config);
app.get('/', function(request, response) {
response.send('<html><head></head><body><a href="requestToken">requestToekn</a></body></html>');
});
app.get('/requestToken', function(request, response) {
oauth.acquireRequestToken({scope: 'http://www.google.com/calendar/feeds'},
function(oa) {
if(oa instanceof Error) {
response.send(oa.statusCode +' '+ oa.toString());
} else response.redirect(oa.getAuthorizeTokenURI());
});
});
app.get('/callback', function(request, response) {
oauth.setOAuthVerifier(request.param('oauth_verifier'));
oauth.acquireAccessToken(function(oa){
if(oa instanceof Error) {
response.send(oa.statusCode +' '+ oa.toString());
} else response.send('success:' + oa.oauthToken);
});
});
app.listen(8080);