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/oauth-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/oauth-clients.ts')
-rw-r--r-- | server/controllers/api/oauth-clients.ts | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/server/controllers/api/oauth-clients.ts b/server/controllers/api/oauth-clients.ts new file mode 100644 index 000000000..b9bc0534f --- /dev/null +++ b/server/controllers/api/oauth-clients.ts | |||
@@ -0,0 +1,43 @@ | |||
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 { OAuthClientLocal } from '../../../shared' | ||
7 | |||
8 | const oauthClientsRouter = express.Router() | ||
9 | |||
10 | oauthClientsRouter.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: OAuthClientLocal = { | ||
32 | client_id: client.clientId, | ||
33 | client_secret: client.clientSecret | ||
34 | } | ||
35 | res.json(json) | ||
36 | }) | ||
37 | } | ||
38 | |||
39 | // --------------------------------------------------------------------------- | ||
40 | |||
41 | export { | ||
42 | oauthClientsRouter | ||
43 | } | ||