Skip to content

Commit fb51ff6

Browse files
committed
Added error handling for expired JWT in UserMeetingSettingsService.
Specifically, the method 'handleConnectCalendarCallback' was updated and the JWT verification secret value has been moved to an environment variable.
1 parent 860ac08 commit fb51ff6

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@
4343
# Get nylas client id and secret from nylas developer page
4444
NYLAS_CLIENT_ID=
4545
NYLAS_CLIENT_SECRET=
46+
# Configure a secret value to be used in UserMeetingSettingsService in the method 'handleConnectCalendarCallback'
47+
NYLAS_CONNECT_CALENDAR_JWT_SECRET=
4648
# Locally deployed services (via docker-compose)
4749
ES_HOST=http://dockerhost:9200
4850
DATABASE_URL=postgres://postgres:postgres@dockerhost:5432/postgres

config/default.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,7 @@ module.exports = {
330330
// Nylas Client id
331331
NYLAS_CLIENT_ID: process.env.NYLAS_CLIENT_ID,
332332
NYLAS_CLIENT_SECRET: process.env.NYLAS_CLIENT_SECRET,
333+
NYLAS_CONNECT_CALENDAR_JWT_SECRET: process.env.NYLAS_CONNECT_CALENDAR_JWT_SECRET,
333334

334335
// Zoom JWT credentials
335336
ZOOM_ACCOUNTS: process.env.ZOOM_ACCOUNTS

src/services/UserMeetingSettingsService.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,13 @@ createUserMeetingSettingsIfNotExisting.schema = Joi.object().keys({
188188
*/
189189
async function handleConnectCalendarCallback (reqQuery) {
190190
// verifying jwt token for request query param - 'state'
191-
const verifyQueryStateJwt = await jwt.verify(reqQuery.state, 'secret')
191+
const verifyQueryStateJwt = await jwt.verify(reqQuery.state, config.NYLAS_CONNECT_CALENDAR_JWT_SECRET, (err, decoded) => {
192+
if (err) {
193+
throw new errors.UnauthorizedError('Could not verify JWT token.')
194+
}
195+
196+
return decoded
197+
})
192198

193199
// note userId is actually the UUID in the following line. not to confuse with other 'userId'
194200
const { userId, redirectTo } = verifyQueryStateJwt
@@ -207,7 +213,7 @@ async function handleConnectCalendarCallback (reqQuery) {
207213
const { accessToken, accountId, provider } = await NylasService.getAccessToken(reqQuery.code)
208214
// view https://developer.nylas.com/docs/api/#post/oauth/token for error response schema
209215
if (!accessToken || !accountId) {
210-
throw new errors.BadRequestError('Error during getting access token for the calendar.')
216+
throw new errors.BadRequestError('Error getting access token for the calendar.')
211217
}
212218

213219
// getting user's all existing calendars

0 commit comments

Comments
 (0)