aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api/v1/clients.js
diff options
context:
space:
mode:
Diffstat (limited to 'server/controllers/api/v1/clients.js')
-rw-r--r--server/controllers/api/v1/clients.js40
1 files changed, 40 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..0d222634b
--- /dev/null
+++ b/server/controllers/api/v1/clients.js
@@ -0,0 +1,40 @@
1'use strict'
2
3const config = require('config')
4const express = require('express')
5const mongoose = require('mongoose')
6
7const Client = mongoose.model('OAuthClient')
8
9const router = express.Router()
10
11router.get('/local', getLocalClient)
12
13// Get the client credentials for the PeerTube front end
14function getLocalClient (req, res, next) {
15 const serverHost = config.get('webserver.host')
16 const serverPort = config.get('webserver.port')
17 let headerHostShouldBe = serverHost
18 if (serverPort !== 80 && serverPort !== 443) {
19 headerHostShouldBe += ':' + serverPort
20 }
21
22 // Don't make this check if this is a test instance
23 if (process.env.NODE_ENV !== 'test' && req.get('host') !== headerHostShouldBe) {
24 return res.type('json').status(403).end()
25 }
26
27 Client.loadFirstClient(function (err, client) {
28 if (err) return next(err)
29 if (!client) return next(new Error('No client available.'))
30
31 res.json({
32 client_id: client._id,
33 client_secret: client.clientSecret
34 })
35 })
36}
37
38// ---------------------------------------------------------------------------
39
40module.exports = router