Add get subscription endpoint
[oweals/peertube.git] / server / middlewares / validators / activitypub / signature.ts
1 import * as express from 'express'
2 import { body } from 'express-validator/check'
3 import {
4   isSignatureCreatorValid, isSignatureTypeValid,
5   isSignatureValueValid
6 } from '../../../helpers/custom-validators/activitypub/signature'
7 import { isDateValid } from '../../../helpers/custom-validators/misc'
8 import { logger } from '../../../helpers/logger'
9 import { areValidationErrors } from '../utils'
10
11 const signatureValidator = [
12   body('signature.type').custom(isSignatureTypeValid).withMessage('Should have a valid signature type'),
13   body('signature.created').custom(isDateValid).withMessage('Should have a valid signature created date'),
14   body('signature.creator').custom(isSignatureCreatorValid).withMessage('Should have a valid signature creator'),
15   body('signature.signatureValue').custom(isSignatureValueValid).withMessage('Should have a valid signature value'),
16
17   (req: express.Request, res: express.Response, next: express.NextFunction) => {
18     logger.debug('Checking activitypub signature parameter', { parameters: { signature: req.body.signature } })
19
20     if (areValidationErrors(req, res)) return
21
22     return next()
23   }
24 ]
25
26 // ---------------------------------------------------------------------------
27
28 export {
29   signatureValidator
30 }