Commit f3f14fef55b03accf2e45b6f73ea71497bb4979e
1 parent
fbe7f7a7
Exists in
master
add value config & fix refresh token
Showing
3 changed files
with
9 additions
and
6 deletions
Show diff stats
app/controllers/home.controller.js
| @@ -13,6 +13,7 @@ var lib = require('../lib') | @@ -13,6 +13,7 @@ var lib = require('../lib') | ||
| 13 | 13 | ||
| 14 | var url = config.server.url | 14 | var url = config.server.url |
| 15 | var port = config.server.port | 15 | var port = config.server.port |
| 16 | +var URLCALENDAR = config.urlcalendar | ||
| 16 | 17 | ||
| 17 | function rmsRes(res) { | 18 | function rmsRes(res) { |
| 18 | this._40401 = function (data) { | 19 | this._40401 = function (data) { |
| @@ -175,7 +176,7 @@ function oauth2callback(req, res) { | @@ -175,7 +176,7 @@ function oauth2callback(req, res) { | ||
| 175 | rms._50000(err) | 176 | rms._50000(err) |
| 176 | } else { | 177 | } else { |
| 177 | 178 | ||
| 178 | - res.redirect('http://localhost:8000/#!/calendar') | 179 | + res.redirect(URLCALENDAR) |
| 179 | } | 180 | } |
| 180 | }) | 181 | }) |
| 181 | } | 182 | } |
| @@ -311,7 +312,7 @@ function deleteCalendar(req, res) { | @@ -311,7 +312,7 @@ function deleteCalendar(req, res) { | ||
| 311 | 312 | ||
| 312 | function refreshToken(req, res) { | 313 | function refreshToken(req, res) { |
| 313 | var rms = new rmsRes(res); | 314 | var rms = new rmsRes(res); |
| 314 | - | 315 | + var options = {}; |
| 315 | lib.authorize((err, auth) => { | 316 | lib.authorize((err, auth) => { |
| 316 | if (err) { | 317 | if (err) { |
| 317 | rms._50000(err) | 318 | rms._50000(err) |
| @@ -340,4 +341,3 @@ module.exports.createCalendar = createCalendar; | @@ -340,4 +341,3 @@ module.exports.createCalendar = createCalendar; | ||
| 340 | module.exports.getCalendar = getCalendar; | 341 | module.exports.getCalendar = getCalendar; |
| 341 | module.exports.deleteCalendar = deleteCalendar; | 342 | module.exports.deleteCalendar = deleteCalendar; |
| 342 | module.exports.refreshToken = refreshToken; | 343 | module.exports.refreshToken = refreshToken; |
| 343 | - |
app/lib/index.js
| @@ -21,6 +21,7 @@ const CALENDAR_ID = config.google.calendar_id; | @@ -21,6 +21,7 @@ const CALENDAR_ID = config.google.calendar_id; | ||
| 21 | const REDIRECT_URL = config.google.redirect_url; | 21 | const REDIRECT_URL = config.google.redirect_url; |
| 22 | const CLIENT_ID = config.google.client_id; | 22 | const CLIENT_ID = config.google.client_id; |
| 23 | const CLIENT_SECRET = config.google.client_secret; | 23 | const CLIENT_SECRET = config.google.client_secret; |
| 24 | +const EMAIL = config.email; | ||
| 24 | 25 | ||
| 25 | /** | 26 | /** |
| 26 | * เรียกใช้ oauth2Client | 27 | * เรียกใช้ oauth2Client |
| @@ -94,7 +95,7 @@ module.exports = { | @@ -94,7 +95,7 @@ module.exports = { | ||
| 94 | authorize: (callback) => { | 95 | authorize: (callback) => { |
| 95 | var setToken = {} // set token from callback | 96 | var setToken = {} // set token from callback |
| 96 | Token.findOne({ | 97 | Token.findOne({ |
| 97 | - email: 'zentoriono@gmail.com' | 98 | + email: EMAIL |
| 98 | }, function (err, token) { | 99 | }, function (err, token) { |
| 99 | if (err) { | 100 | if (err) { |
| 100 | return callback(null, null, getNewToken(oauth2Client, callback)); | 101 | return callback(null, null, getNewToken(oauth2Client, callback)); |
| @@ -117,7 +118,7 @@ module.exports = { | @@ -117,7 +118,7 @@ module.exports = { | ||
| 117 | 118 | ||
| 118 | setNewToken: (code, callback) => { | 119 | setNewToken: (code, callback) => { |
| 119 | Token.findOne({ | 120 | Token.findOne({ |
| 120 | - email: 'zentoriono@gmail.com' | 121 | + email: EMAIL |
| 121 | }, function (err, token) { | 122 | }, function (err, token) { |
| 122 | if (token) { | 123 | if (token) { |
| 123 | oauth2Client.credentials = JSON.parse(token); | 124 | oauth2Client.credentials = JSON.parse(token); |
| @@ -376,7 +377,7 @@ module.exports = { | @@ -376,7 +377,7 @@ module.exports = { | ||
| 376 | }, | 377 | }, |
| 377 | 378 | ||
| 378 | refreshToken: (options, callback) => { | 379 | refreshToken: (options, callback) => { |
| 379 | - oauth2Client.setCredentials(options.auth); | 380 | + // oauth2Client.setCredentials(options.auth); |
| 380 | oauth2Client.refreshAccessToken(function(err, tokens) { | 381 | oauth2Client.refreshAccessToken(function(err, tokens) { |
| 381 | // your access_token is now refreshed and stored in oauth2Client | 382 | // your access_token is now refreshed and stored in oauth2Client |
| 382 | // store these new tokens in a safe place (e.g. database) | 383 | // store these new tokens in a safe place (e.g. database) |
config/config.yml
| @@ -15,6 +15,8 @@ localhost: | @@ -15,6 +15,8 @@ localhost: | ||
| 15 | pass: | 15 | pass: |
| 16 | timerecheck: '10000' #millisecond | 16 | timerecheck: '10000' #millisecond |
| 17 | apitimeout: 3000 #millisecond | 17 | apitimeout: 3000 #millisecond |
| 18 | + email: 'tzbattleboy@gmail.com' | ||
| 19 | + urlcalendar: 'http://localhost:8000/#/new/calendar' | ||
| 18 | google: | 20 | google: |
| 19 | calendar_id: 'rvmbg3kg7uqninf7n3au1ku4mc@group.calendar.google.com' | 21 | calendar_id: 'rvmbg3kg7uqninf7n3au1ku4mc@group.calendar.google.com' |
| 20 | redirect_url: 'http://localhost:3030/oauth2callback' | 22 | redirect_url: 'http://localhost:3030/oauth2callback' |