aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api
diff options
context:
space:
mode:
authorRigel Kent <sendmemail@rigelk.eu>2020-08-13 15:07:23 +0200
committerChocobozzz <chocobozzz@cpy.re>2020-11-25 11:07:56 +0100
commitafff310e50f2fa8419bb4242470cbde46ab54463 (patch)
tree34efda2daf8f7cdfd89ef6616a79e2222082f93a /server/controllers/api
parentf619de0e435f7ac3abad2ec772397486358b56e7 (diff)
downloadPeerTube-afff310e50f2fa8419bb4242470cbde46ab54463.tar.gz
PeerTube-afff310e50f2fa8419bb4242470cbde46ab54463.tar.zst
PeerTube-afff310e50f2fa8419bb4242470cbde46ab54463.zip
allow private syndication feeds via a user feedToken
Diffstat (limited to 'server/controllers/api')
-rw-r--r--server/controllers/api/users/token.ts31
1 files changed, 31 insertions, 0 deletions
diff --git a/server/controllers/api/users/token.ts b/server/controllers/api/users/token.ts
index 41aa26769..821429358 100644
--- a/server/controllers/api/users/token.ts
+++ b/server/controllers/api/users/token.ts
@@ -4,6 +4,8 @@ import { CONFIG } from '@server/initializers/config'
4import * as express from 'express' 4import * as express from 'express'
5import { Hooks } from '@server/lib/plugins/hooks' 5import { Hooks } from '@server/lib/plugins/hooks'
6import { asyncMiddleware, authenticate } from '@server/middlewares' 6import { asyncMiddleware, authenticate } from '@server/middlewares'
7import { ScopedToken } from '@shared/models/users/user-scoped-token'
8import { v4 as uuidv4 } from 'uuid'
7 9
8const tokensRouter = express.Router() 10const tokensRouter = express.Router()
9 11
@@ -23,6 +25,16 @@ tokensRouter.post('/revoke-token',
23 asyncMiddleware(handleTokenRevocation) 25 asyncMiddleware(handleTokenRevocation)
24) 26)
25 27
28tokensRouter.get('/scoped-tokens',
29 authenticate,
30 getScopedTokens
31)
32
33tokensRouter.post('/scoped-tokens',
34 authenticate,
35 asyncMiddleware(renewScopedTokens)
36)
37
26// --------------------------------------------------------------------------- 38// ---------------------------------------------------------------------------
27 39
28export { 40export {
@@ -35,3 +47,22 @@ function tokenSuccess (req: express.Request) {
35 47
36 Hooks.runAction('action:api.user.oauth2-got-token', { username, ip: req.ip }) 48 Hooks.runAction('action:api.user.oauth2-got-token', { username, ip: req.ip })
37} 49}
50
51function getScopedTokens (req: express.Request, res: express.Response) {
52 const user = res.locals.oauth.token.user
53
54 return res.json({
55 feedToken: user.feedToken
56 } as ScopedToken)
57}
58
59async function renewScopedTokens (req: express.Request, res: express.Response) {
60 const user = res.locals.oauth.token.user
61
62 user.feedToken = uuidv4()
63 await user.save()
64
65 return res.json({
66 feedToken: user.feedToken
67 } as ScopedToken)
68}