aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api/oauth-clients.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/controllers/api/oauth-clients.ts')
-rw-r--r--server/controllers/api/oauth-clients.ts26
1 files changed, 13 insertions, 13 deletions
diff --git a/server/controllers/api/oauth-clients.ts b/server/controllers/api/oauth-clients.ts
index f7dac598c..ac1ee9e36 100644
--- a/server/controllers/api/oauth-clients.ts
+++ b/server/controllers/api/oauth-clients.ts
@@ -2,15 +2,18 @@ import * as express from 'express'
2 2
3import { CONFIG } from '../../initializers' 3import { CONFIG } from '../../initializers'
4import { logger } from '../../helpers' 4import { logger } from '../../helpers'
5import { asyncMiddleware } from '../../middlewares'
5import { database as db } from '../../initializers/database' 6import { database as db } from '../../initializers/database'
6import { OAuthClientLocal } from '../../../shared' 7import { OAuthClientLocal } from '../../../shared'
7 8
8const oauthClientsRouter = express.Router() 9const oauthClientsRouter = express.Router()
9 10
10oauthClientsRouter.get('/local', getLocalClient) 11oauthClientsRouter.get('/local',
12 asyncMiddleware(getLocalClient)
13)
11 14
12// Get the client credentials for the PeerTube front end 15// Get the client credentials for the PeerTube front end
13function getLocalClient (req: express.Request, res: express.Response, next: express.NextFunction) { 16async function getLocalClient (req: express.Request, res: express.Response, next: express.NextFunction) {
14 const serverHostname = CONFIG.WEBSERVER.HOSTNAME 17 const serverHostname = CONFIG.WEBSERVER.HOSTNAME
15 const serverPort = CONFIG.WEBSERVER.PORT 18 const serverPort = CONFIG.WEBSERVER.PORT
16 let headerHostShouldBe = serverHostname 19 let headerHostShouldBe = serverHostname
@@ -24,17 +27,14 @@ function getLocalClient (req: express.Request, res: express.Response, next: expr
24 return res.type('json').status(403).end() 27 return res.type('json').status(403).end()
25 } 28 }
26 29
27 db.OAuthClient.loadFirstClient() 30 const client = await db.OAuthClient.loadFirstClient()
28 .then(client => { 31 if (!client) throw new Error('No client available.')
29 if (!client) throw new Error('No client available.') 32
30 33 const json: OAuthClientLocal = {
31 const json: OAuthClientLocal = { 34 client_id: client.clientId,
32 client_id: client.clientId, 35 client_secret: client.clientSecret
33 client_secret: client.clientSecret 36 }
34 } 37 return res.json(json)
35 res.json(json)
36 })
37 .catch(err => next(err))
38} 38}
39 39
40// --------------------------------------------------------------------------- 40// ---------------------------------------------------------------------------