storage-upload/api/media/security.mjs

19 lines
486 B
JavaScript
Raw Normal View History

import { HttpError } from '../error.mjs'
import decode from '../jwt/decode.mjs'
import config from '../config.mjs'
2017-12-10 09:45:38 +00:00
export function verifyToken(ctx) {
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
}
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
}