Skip to content

Added error handling for expired JWT in UserMeetingSettingsService. #604

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from Oct 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
# Get nylas client id and secret from nylas developer page
NYLAS_CLIENT_ID=
NYLAS_CLIENT_SECRET=
# Configure a secret value to be used in UserMeetingSettingsService in the method 'handleConnectCalendarCallback'
NYLAS_CONNECT_CALENDAR_JWT_SECRET=
# Locally deployed services (via docker-compose)
ES_HOST=http://dockerhost:9200
DATABASE_URL=postgres://postgres:postgres@dockerhost:5432/postgres
Expand Down
1 change: 1 addition & 0 deletions config/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ module.exports = {
// Nylas Client id
NYLAS_CLIENT_ID: process.env.NYLAS_CLIENT_ID,
NYLAS_CLIENT_SECRET: process.env.NYLAS_CLIENT_SECRET,
NYLAS_CONNECT_CALENDAR_JWT_SECRET: process.env.NYLAS_CONNECT_CALENDAR_JWT_SECRET,

// Zoom JWT credentials
ZOOM_ACCOUNTS: process.env.ZOOM_ACCOUNTS
Expand Down
10 changes: 8 additions & 2 deletions src/services/UserMeetingSettingsService.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,13 @@ createUserMeetingSettingsIfNotExisting.schema = Joi.object().keys({
*/
async function handleConnectCalendarCallback (reqQuery) {
// verifying jwt token for request query param - 'state'
const verifyQueryStateJwt = await jwt.verify(reqQuery.state, 'secret')
const verifyQueryStateJwt = await jwt.verify(reqQuery.state, config.NYLAS_CONNECT_CALENDAR_JWT_SECRET, (err, decoded) => {
if (err) {
throw new errors.UnauthorizedError('Could not verify JWT token.')
}

return decoded
})

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

// getting user's all existing calendars
Expand Down