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