diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-06-25 17:44:19 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-06-25 17:44:19 +0200 |
commit | 0a381679e04bc7adf097da9a6fb4e2c8f41bbda2 (patch) | |
tree | 02c6745db0cc36517ceffad3bee129f833fd3341 /server/controllers/api/clients.ts | |
parent | d58cdea854904369c2dcce905ce42f4f6db836a8 (diff) | |
download | PeerTube-0a381679e04bc7adf097da9a6fb4e2c8f41bbda2.tar.gz PeerTube-0a381679e04bc7adf097da9a6fb4e2c8f41bbda2.tar.zst PeerTube-0a381679e04bc7adf097da9a6fb4e2c8f41bbda2.zip |
ClientLocal -> OAuthClientLocal
Diffstat (limited to 'server/controllers/api/clients.ts')
-rw-r--r-- | server/controllers/api/clients.ts | 43 |
1 files changed, 0 insertions, 43 deletions
diff --git a/server/controllers/api/clients.ts b/server/controllers/api/clients.ts deleted file mode 100644 index 96490d04a..000000000 --- a/server/controllers/api/clients.ts +++ /dev/null | |||
@@ -1,43 +0,0 @@ | |||
1 | import * as express from 'express' | ||
2 | |||
3 | import { CONFIG } from '../../initializers' | ||
4 | import { logger } from '../../helpers' | ||
5 | import { database as db } from '../../initializers/database' | ||
6 | import { ClientLocal } from '../../../shared' | ||
7 | |||
8 | const clientsRouter = express.Router() | ||
9 | |||
10 | clientsRouter.get('/local', getLocalClient) | ||
11 | |||
12 | // Get the client credentials for the PeerTube front end | ||
13 | function getLocalClient (req: express.Request, res: express.Response, next: express.NextFunction) { | ||
14 | const serverHostname = CONFIG.WEBSERVER.HOSTNAME | ||
15 | const serverPort = CONFIG.WEBSERVER.PORT | ||
16 | let headerHostShouldBe = serverHostname | ||
17 | if (serverPort !== 80 && serverPort !== 443) { | ||
18 | headerHostShouldBe += ':' + serverPort | ||
19 | } | ||
20 | |||
21 | // Don't make this check if this is a test instance | ||
22 | if (process.env.NODE_ENV !== 'test' && req.get('host') !== headerHostShouldBe) { | ||
23 | logger.info('Getting client tokens for host %s is forbidden (expected %s).', req.get('host'), headerHostShouldBe) | ||
24 | return res.type('json').status(403).end() | ||
25 | } | ||
26 | |||
27 | db.OAuthClient.loadFirstClient(function (err, client) { | ||
28 | if (err) return next(err) | ||
29 | if (!client) return next(new Error('No client available.')) | ||
30 | |||
31 | const json: ClientLocal = { | ||
32 | client_id: client.clientId, | ||
33 | client_secret: client.clientSecret | ||
34 | } | ||
35 | res.json(json) | ||
36 | }) | ||
37 | } | ||
38 | |||
39 | // --------------------------------------------------------------------------- | ||
40 | |||
41 | export { | ||
42 | clientsRouter | ||
43 | } | ||