]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/controllers/api/users/token.ts
Add moderation helpers to plugins
[github/Chocobozzz/PeerTube.git] / server / controllers / api / users / token.ts
CommitLineData
9107d791 1import { handleLogin, handleTokenRevocation } from '@server/lib/auth'
e1c55031
C
2import * as RateLimit from 'express-rate-limit'
3import { CONFIG } from '@server/initializers/config'
4import * as express from 'express'
5import { Hooks } from '@server/lib/plugins/hooks'
6import { asyncMiddleware, authenticate } from '@server/middlewares'
7
8const tokensRouter = express.Router()
9
10const loginRateLimiter = RateLimit({
11 windowMs: CONFIG.RATES_LIMIT.LOGIN.WINDOW_MS,
12 max: CONFIG.RATES_LIMIT.LOGIN.MAX
13})
14
15tokensRouter.post('/token',
16 loginRateLimiter,
9107d791 17 handleLogin,
e1c55031
C
18 tokenSuccess
19)
20
21tokensRouter.post('/revoke-token',
22 authenticate,
e307e4fc 23 asyncMiddleware(handleTokenRevocation)
e1c55031
C
24)
25
26// ---------------------------------------------------------------------------
27
28export {
29 tokensRouter
30}
31// ---------------------------------------------------------------------------
32
33function tokenSuccess (req: express.Request) {
34 const username = req.body.username
35
36 Hooks.runAction('action:api.user.oauth2-got-token', { username, ip: req.ip })
37}