2021-10-11 00:21:57 +00:00
|
|
|
import { HttpError } from '../error.mjs'
|
2021-10-09 00:11:52 +00:00
|
|
|
import decode from '../jwt/decode.mjs'
|
2021-07-03 13:56:53 +00:00
|
|
|
import config from '../config.mjs'
|
2017-12-10 09:45:38 +00:00
|
|
|
|
2021-10-09 00:11:52 +00:00
|
|
|
export function verifyToken(ctx) {
|
2021-10-11 00:21:57 +00:00
|
|
|
let token = ctx.query.get('token')
|
|
|
|
if (!token) {
|
|
|
|
throw new HttpError('Token is missing in query', 422)
|
2017-12-10 09:45:38 +00:00
|
|
|
}
|
|
|
|
|
2021-10-11 00:21:57 +00:00
|
|
|
try {
|
|
|
|
let decoded = decode(token, config.get('sites'), [])
|
|
|
|
return decoded.iss
|
|
|
|
} catch (err) {
|
|
|
|
ctx.log.error(err, 'Error decoding token: ' + token)
|
|
|
|
throw new HttpError('Token was invalid', 422)
|
|
|
|
}
|
2017-12-10 09:45:38 +00:00
|
|
|
}
|