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.ts54
1 files changed, 0 insertions, 54 deletions
diff --git a/server/controllers/api/oauth-clients.ts b/server/controllers/api/oauth-clients.ts
deleted file mode 100644
index 1899dbb02..000000000
--- a/server/controllers/api/oauth-clients.ts
+++ /dev/null
@@ -1,54 +0,0 @@
1import express from 'express'
2import { isTestOrDevInstance } from '@server/helpers/core-utils'
3import { OAuthClientModel } from '@server/models/oauth/oauth-client'
4import { HttpStatusCode, OAuthClientLocal } from '@shared/models'
5import { logger } from '../../helpers/logger'
6import { CONFIG } from '../../initializers/config'
7import { apiRateLimiter, asyncMiddleware, openapiOperationDoc } from '../../middlewares'
8
9const oauthClientsRouter = express.Router()
10
11oauthClientsRouter.use(apiRateLimiter)
12
13oauthClientsRouter.get('/local',
14 openapiOperationDoc({ operationId: 'getOAuthClient' }),
15 asyncMiddleware(getLocalClient)
16)
17
18// Get the client credentials for the PeerTube front end
19async function getLocalClient (req: express.Request, res: express.Response, next: express.NextFunction) {
20 const serverHostname = CONFIG.WEBSERVER.HOSTNAME
21 const serverPort = CONFIG.WEBSERVER.PORT
22 let headerHostShouldBe = serverHostname
23 if (serverPort !== 80 && serverPort !== 443) {
24 headerHostShouldBe += ':' + serverPort
25 }
26
27 // Don't make this check if this is a test instance
28 if (!isTestOrDevInstance() && req.get('host') !== headerHostShouldBe) {
29 logger.info(
30 'Getting client tokens for host %s is forbidden (expected %s).', req.get('host'), headerHostShouldBe,
31 { webserverConfig: CONFIG.WEBSERVER }
32 )
33
34 return res.fail({
35 status: HttpStatusCode.FORBIDDEN_403,
36 message: `Getting client tokens for host ${req.get('host')} is forbidden`
37 })
38 }
39
40 const client = await OAuthClientModel.loadFirstClient()
41 if (!client) throw new Error('No client available.')
42
43 const json: OAuthClientLocal = {
44 client_id: client.clientId,
45 client_secret: client.clientSecret
46 }
47 return res.json(json)
48}
49
50// ---------------------------------------------------------------------------
51
52export {
53 oauthClientsRouter
54}