aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api/oauth-clients.ts
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-06-25 17:44:19 +0200
committerChocobozzz <florian.bigard@gmail.com>2017-06-25 17:44:19 +0200
commit0a381679e04bc7adf097da9a6fb4e2c8f41bbda2 (patch)
tree02c6745db0cc36517ceffad3bee129f833fd3341 /server/controllers/api/oauth-clients.ts
parentd58cdea854904369c2dcce905ce42f4f6db836a8 (diff)
downloadPeerTube-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.ts43
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 @@
1import * as express from 'express'
2
3import { CONFIG } from '../../initializers'
4import { logger } from '../../helpers'
5import { database as db } from '../../initializers/database'
6import { OAuthClientLocal } from '../../../shared'
7
8const oauthClientsRouter = express.Router()
9
10oauthClientsRouter.get('/local', getLocalClient)
11
12// Get the client credentials for the PeerTube front end
13function 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
41export {
42 oauthClientsRouter
43}