javascript - passportjs authentication using google apps email id -
I'm trying Passport Js with a google app email id to authenticate me using gmail.com email id But if I'm an email id, google.com/a/companyname.com, then how can I prove it?
This is my code
var express = require ('express'); Var app = express (); Var passport = requirement ('passport'); Var GoogleStrategy = Required ('Passport-Google') Strategy; Passport.use (New GoogleStrategy ({returnURL: 'http://10.3.0.52:3000/auth/google/return', realm: 'http://10.3.0.52:3000/'}, function (identifier, profile, Done} {User.findOrCreate ({openId: identifier}, function (mistake, user) {done (err, user);});})); App.get ('/ auth / google', passport.authenticate ('google')); App.get ('/ auth / google / return', passport.authenticate ('google', {successRedirect: '/', failure redirection: '/ login'})); App.get ('/', function (rik, ridge) {res.writeHead (200); res.end ("connect");}); App.listen (process.env.port || 3000);
Some important parts are missing in your code:
< Code> ... passport. (...); // It has // // It is necessary as well App.use (passport.initialize ()); App.use (passport.session ()); // Please read the docs for the following two calls passport.serializeUser (function (user, done) (done (user, user);}); passportdatarielize user (function (obje, done) {done (blank, obg);} ); ... With those places, I can simply log in using my Google app address.
Edit: < / Strong> This only works with node 0.8, node returns 0.10 an error. I think the use of passport-google-oauth There is a better solution, for that you have to register your application with Google; After registration, you will be provided both GOOGLE_CLIENT_ID and GOOGLE_CLIENT_SECRET codes which you can use.
Comments
Post a Comment