diff --git a/api/controllers/AuthController.js b/api/controllers/AuthController.js new file mode 100644 index 0000000..603dc35 --- /dev/null +++ b/api/controllers/AuthController.js @@ -0,0 +1,47 @@ +var passport = require('passport'); +var GoogleStrategy = require('passport-google-oauth').OAuth2Strategy; +var gcal = require('google-calendar'); +var util = require('util'); + +passport.use(new GoogleStrategy({ + clientID: '553555458366-bl2e989fn88t27recf2cgp74b3ogcdc1.apps.googleusercontent.com', + clientSecret: '8TNPb5ehq-t7g1uiwztaHmC7', + callbackURL: "http://127.0.0.1:1337/auth/google" + + },function(accessToken, refreshToken, profile, done) { + // asynchronous verification, for effect... + console.log(accessToken+"========="); + process.nextTick(function () { + + // To keep the example simple, the user's Google profile is returned to + // represent the logged-in user. In a typical application, you would want + // to associate the Google account with a user record in your database, + // and return that user instead. + return done(null, profile); + }); + } +)); + +passport.serializeUser(function (user, done) { + done(null, user); +}); + +passport.deserializeUser(function (obj, done) { + done(null, obj); +}); + + +var AuthController = { + index: passport.authenticate('google', { scope: ['https://www.googleapis.com/auth/userinfo.profile', + 'https://www.googleapis.com/auth/userinfo.email'] }), + + + auth: passport.authenticate('google',function(req,res){ + console.log(res) ; + console.log(req); + }) + + + +}; +module.exports = AuthController; \ No newline at end of file diff --git a/config/application.js b/config/application.js index 31f5f32..23138bb 100644 --- a/config/application.js +++ b/config/application.js @@ -1,12 +1,12 @@ module.exports = { - + // Name of the application (used as default ) - appName: "Sails Application", + appName: "Sohub", // Port this Sails application will live on port: process.env.PORT || 1337, - // The environment the app is deployed in + // The environment the app is deployed in // (`development` or `production`) // // In `production` mode, all css and js are bundled up and minified @@ -16,7 +16,7 @@ module.exports = { // Logger // Valid `level` configs: - // + // // - error // - warn // - debug diff --git a/config/routes.js b/config/routes.js index ddceed6..0b5fe64 100644 --- a/config/routes.js +++ b/config/routes.js @@ -38,7 +38,7 @@ module.exports.routes = { controller: 'message', action: 'viewImage' }, - 'get /message/notice':{ + 'get /message/notice': { controller: 'message', action: 'viewNotice' }, @@ -58,9 +58,17 @@ module.exports.routes = { controller: 'weibo', action: 'index' }, - 'get /spike':{ + 'get /spike': { controller: 'message', action: 'spike' + }, + 'get /auth': { + controller: 'auth', + action: 'index' + }, + 'get /auth/google': { + controller: 'auth', + action: 'auth' } diff --git a/package.json b/package.json index b7023a9..67faa9d 100644 --- a/package.json +++ b/package.json @@ -4,13 +4,16 @@ "version": "0.0.1", "description": "social media information hub and aggregator application", "dependencies": { - "sails": "0.8.91", + "sails": "0.8.93", "sails-mongo": "0.0.3", "optimist": "0.4.0", "wechat": "0.4.4", "nn-oss": "0.0.9", "request": "2.21.0", - "weibo": "0.6.9" + "weibo": "0.6.9", + "google-calendar":"1.0.0", + "passport": "> 0.0.0", + "passport-google-oauth": ">= 0.1.0" }, "devDependencies": { "mocha": "*"