oauth 2.0 - OAuth2 & Node.js - No redirect after Google confirmation [Solved] -
i'm using node.js authenticate web application google+. i've followed official instructions here. code looks this:
var google = require('googleapis'); // oauth var oauth2 = google.auth.oauth2; var plus = google.plus('v1'); var oauth2client = new oauth2( 'my_client_id', // client id 'my_client_secret', // client secret 'http://localhost:8080/oauth' // redirect url ); function getoauthurl(){ var url = oauth2client.generateauthurl({ access_type: 'offline', scope: 'https://www.googleapis.com/auth/plus.me' }); return url; } // oauth authorization app.use('/oauth', function(req, res){ var session = req.session; var code = req.query.code; oauth2client.gettoken(code, function(err, tokens) { // tokens contains access_token , optional refresh_token. save them. if (!err) { oauth2client.setcredentials(tokens); session['tokens'] = tokens; res.redirect(__dirname + '/public/html/redirect.html?r=1'); // success! }else{ res.redirect(__dirname + '/public/html/redirect.html?r=0'); // fail! } }); }); the login page called index.html @ root of folder. login page makes ajax request /oauth/url responds oauth2 url user must click.
js on index.html:
/* oauth */ $.ajax({ url: '/oauth/url', datatype: 'text', cache: false, success: function (e) { $('#login').attr('href', e); } }); node.js response:
// oauth url app.use('/oauth/url', function(req, res){ var url = getoauthurl(); res.end(url); }); i can click link take me authentication page normal. when select account authenticate, page freezes , doesn't redirected localhost:8080/oauth it's supposed to.
update: looking @ networking tab on console noticed get request callback being cancelled. code recieved node.js , request.
solved:
the issue static directory not allowing node.js redirect page. fixed changing redirect address /html/redirect.html. thank @james.

Comments
Post a Comment