diff options
author | Rigel Kent <sendmemail@rigelk.eu> | 2020-08-13 15:07:23 +0200 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2020-11-25 11:07:56 +0100 |
commit | afff310e50f2fa8419bb4242470cbde46ab54463 (patch) | |
tree | 34efda2daf8f7cdfd89ef6616a79e2222082f93a /server/controllers/api/users/token.ts | |
parent | f619de0e435f7ac3abad2ec772397486358b56e7 (diff) | |
download | PeerTube-afff310e50f2fa8419bb4242470cbde46ab54463.tar.gz PeerTube-afff310e50f2fa8419bb4242470cbde46ab54463.tar.zst PeerTube-afff310e50f2fa8419bb4242470cbde46ab54463.zip |
allow private syndication feeds via a user feedToken
Diffstat (limited to 'server/controllers/api/users/token.ts')
-rw-r--r-- | server/controllers/api/users/token.ts | 31 |
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' | |||
4 | import * as express from 'express' | 4 | import * as express from 'express' |
5 | import { Hooks } from '@server/lib/plugins/hooks' | 5 | import { Hooks } from '@server/lib/plugins/hooks' |
6 | import { asyncMiddleware, authenticate } from '@server/middlewares' | 6 | import { asyncMiddleware, authenticate } from '@server/middlewares' |
7 | import { ScopedToken } from '@shared/models/users/user-scoped-token' | ||
8 | import { v4 as uuidv4 } from 'uuid' | ||
7 | 9 | ||
8 | const tokensRouter = express.Router() | 10 | const tokensRouter = express.Router() |
9 | 11 | ||
@@ -23,6 +25,16 @@ tokensRouter.post('/revoke-token', | |||
23 | asyncMiddleware(handleTokenRevocation) | 25 | asyncMiddleware(handleTokenRevocation) |
24 | ) | 26 | ) |
25 | 27 | ||
28 | tokensRouter.get('/scoped-tokens', | ||
29 | authenticate, | ||
30 | getScopedTokens | ||
31 | ) | ||
32 | |||
33 | tokensRouter.post('/scoped-tokens', | ||
34 | authenticate, | ||
35 | asyncMiddleware(renewScopedTokens) | ||
36 | ) | ||
37 | |||
26 | // --------------------------------------------------------------------------- | 38 | // --------------------------------------------------------------------------- |
27 | 39 | ||
28 | export { | 40 | export { |
@@ -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 | |||
51 | function 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 | |||
59 | async 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 | } | ||