diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2016-10-02 15:39:09 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2016-10-02 15:39:09 +0200 |
commit | a6375e69668ea42e19531c6bc68dcd37f3f7cbd7 (patch) | |
tree | 03204a408d56311692c3528bedcf95d2455e94f2 /server/controllers/api/v1/clients.js | |
parent | 052937db8a8d282eccdbdf38d487ed8d85d3c0a7 (diff) | |
parent | c4403b29ad4db097af528a7f04eea07e0ed320d0 (diff) | |
download | PeerTube-a6375e69668ea42e19531c6bc68dcd37f3f7cbd7.tar.gz PeerTube-a6375e69668ea42e19531c6bc68dcd37f3f7cbd7.tar.zst PeerTube-a6375e69668ea42e19531c6bc68dcd37f3f7cbd7.zip |
Merge branch 'master' into webseed-merged
Diffstat (limited to 'server/controllers/api/v1/clients.js')
-rw-r--r-- | server/controllers/api/v1/clients.js | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/server/controllers/api/v1/clients.js b/server/controllers/api/v1/clients.js new file mode 100644 index 000000000..5b460db2e --- /dev/null +++ b/server/controllers/api/v1/clients.js | |||
@@ -0,0 +1,41 @@ | |||
1 | 'use strict' | ||
2 | |||
3 | const express = require('express') | ||
4 | const mongoose = require('mongoose') | ||
5 | |||
6 | const constants = require('../../../initializers/constants') | ||
7 | |||
8 | const Client = mongoose.model('OAuthClient') | ||
9 | |||
10 | const router = express.Router() | ||
11 | |||
12 | router.get('/local', getLocalClient) | ||
13 | |||
14 | // Get the client credentials for the PeerTube front end | ||
15 | function getLocalClient (req, res, next) { | ||
16 | const serverHost = constants.CONFIG.WEBSERVER.HOST | ||
17 | const serverPort = constants.CONFIG.WEBSERVER.PORT | ||
18 | let headerHostShouldBe = serverHost | ||
19 | if (serverPort !== 80 && serverPort !== 443) { | ||
20 | headerHostShouldBe += ':' + serverPort | ||
21 | } | ||
22 | |||
23 | // Don't make this check if this is a test instance | ||
24 | if (process.env.NODE_ENV !== 'test' && req.get('host') !== headerHostShouldBe) { | ||
25 | return res.type('json').status(403).end() | ||
26 | } | ||
27 | |||
28 | Client.loadFirstClient(function (err, client) { | ||
29 | if (err) return next(err) | ||
30 | if (!client) return next(new Error('No client available.')) | ||
31 | |||
32 | res.json({ | ||
33 | client_id: client._id, | ||
34 | client_secret: client.clientSecret | ||
35 | }) | ||
36 | }) | ||
37 | } | ||
38 | |||
39 | // --------------------------------------------------------------------------- | ||
40 | |||
41 | module.exports = router | ||