From: Chocobozzz Date: Sun, 25 Jun 2017 15:44:19 +0000 (+0200) Subject: ClientLocal -> OAuthClientLocal X-Git-Tag: v0.0.1-alpha~385 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=0a381679e04bc7adf097da9a6fb4e2c8f41bbda2;p=oweals%2Fpeertube.git ClientLocal -> OAuthClientLocal --- diff --git a/client/src/app/core/auth/auth.service.ts b/client/src/app/core/auth/auth.service.ts index fcc6b9bb6..d5aa80512 100644 --- a/client/src/app/core/auth/auth.service.ts +++ b/client/src/app/core/auth/auth.service.ts @@ -11,13 +11,13 @@ import { NotificationsService } from 'angular2-notifications' import { AuthStatus } from './auth-status.model' import { AuthUser } from './auth-user.model' -import { ClientLocal } from '../../../../../shared' +import { OAuthClientLocal } from '../../../../../shared' // Do not use the barrel (dependency loop) import { RestExtractor } from '../../shared/rest' @Injectable() export class AuthService { - private static BASE_CLIENT_URL = API_URL + '/api/v1/clients/local' + private static BASE_CLIENT_URL = API_URL + '/api/v1/oauth-clients/local' private static BASE_TOKEN_URL = API_URL + '/api/v1/users/token' private static BASE_USER_INFORMATIONS_URL = API_URL + '/api/v1/users/me' @@ -43,7 +43,7 @@ export class AuthService { .map(this.restExtractor.extractDataGet) .catch(res => this.restExtractor.handleError(res)) .subscribe( - (result: ClientLocal) => { + (result: OAuthClientLocal) => { this.clientId = result.client_id this.clientSecret = result.client_secret console.log('Client credentials loaded.') diff --git a/server/controllers/api/clients.ts b/server/controllers/api/clients.ts deleted file mode 100644 index 96490d04a..000000000 --- a/server/controllers/api/clients.ts +++ /dev/null @@ -1,43 +0,0 @@ -import * as express from 'express' - -import { CONFIG } from '../../initializers' -import { logger } from '../../helpers' -import { database as db } from '../../initializers/database' -import { ClientLocal } from '../../../shared' - -const clientsRouter = express.Router() - -clientsRouter.get('/local', getLocalClient) - -// Get the client credentials for the PeerTube front end -function getLocalClient (req: express.Request, res: express.Response, next: express.NextFunction) { - const serverHostname = CONFIG.WEBSERVER.HOSTNAME - const serverPort = CONFIG.WEBSERVER.PORT - let headerHostShouldBe = serverHostname - if (serverPort !== 80 && serverPort !== 443) { - headerHostShouldBe += ':' + serverPort - } - - // Don't make this check if this is a test instance - if (process.env.NODE_ENV !== 'test' && req.get('host') !== headerHostShouldBe) { - logger.info('Getting client tokens for host %s is forbidden (expected %s).', req.get('host'), headerHostShouldBe) - return res.type('json').status(403).end() - } - - db.OAuthClient.loadFirstClient(function (err, client) { - if (err) return next(err) - if (!client) return next(new Error('No client available.')) - - const json: ClientLocal = { - client_id: client.clientId, - client_secret: client.clientSecret - } - res.json(json) - }) -} - -// --------------------------------------------------------------------------- - -export { - clientsRouter -} diff --git a/server/controllers/api/index.ts b/server/controllers/api/index.ts index 3abe9bcf8..a9205b33c 100644 --- a/server/controllers/api/index.ts +++ b/server/controllers/api/index.ts @@ -2,7 +2,7 @@ import * as express from 'express' import { badRequest } from '../../helpers' -import { clientsRouter } from './clients' +import { oauthClientsRouter } from './oauth-clients' import { configRouter } from './config' import { podsRouter } from './pods' import { remoteRouter } from './remote' @@ -12,7 +12,7 @@ import { videosRouter } from './videos' const apiRouter = express.Router() -apiRouter.use('/clients', clientsRouter) +apiRouter.use('/oauth-clients', oauthClientsRouter) apiRouter.use('/config', configRouter) apiRouter.use('/pods', podsRouter) apiRouter.use('/remote', remoteRouter) 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 @@ +import * as express from 'express' + +import { CONFIG } from '../../initializers' +import { logger } from '../../helpers' +import { database as db } from '../../initializers/database' +import { OAuthClientLocal } from '../../../shared' + +const oauthClientsRouter = express.Router() + +oauthClientsRouter.get('/local', getLocalClient) + +// Get the client credentials for the PeerTube front end +function getLocalClient (req: express.Request, res: express.Response, next: express.NextFunction) { + const serverHostname = CONFIG.WEBSERVER.HOSTNAME + const serverPort = CONFIG.WEBSERVER.PORT + let headerHostShouldBe = serverHostname + if (serverPort !== 80 && serverPort !== 443) { + headerHostShouldBe += ':' + serverPort + } + + // Don't make this check if this is a test instance + if (process.env.NODE_ENV !== 'test' && req.get('host') !== headerHostShouldBe) { + logger.info('Getting client tokens for host %s is forbidden (expected %s).', req.get('host'), headerHostShouldBe) + return res.type('json').status(403).end() + } + + db.OAuthClient.loadFirstClient(function (err, client) { + if (err) return next(err) + if (!client) return next(new Error('No client available.')) + + const json: OAuthClientLocal = { + client_id: client.clientId, + client_secret: client.clientSecret + } + res.json(json) + }) +} + +// --------------------------------------------------------------------------- + +export { + oauthClientsRouter +} diff --git a/shared/models/client-local.model.ts b/shared/models/client-local.model.ts deleted file mode 100644 index c27963e88..000000000 --- a/shared/models/client-local.model.ts +++ /dev/null @@ -1,4 +0,0 @@ -export interface ClientLocal { - client_id: string - client_secret: string -} diff --git a/shared/models/index.ts b/shared/models/index.ts index fffac795e..95d95ab47 100644 --- a/shared/models/index.ts +++ b/shared/models/index.ts @@ -1,5 +1,5 @@ -export * from './client-local.model' export * from './job.model' +export * from './oauth-client-local.model' export * from './pod.model' export * from './request-scheduler.model' export * from './user-video-rate.model' diff --git a/shared/models/oauth-client-local.model.ts b/shared/models/oauth-client-local.model.ts new file mode 100644 index 000000000..0c6ce6c5d --- /dev/null +++ b/shared/models/oauth-client-local.model.ts @@ -0,0 +1,4 @@ +export interface OAuthClientLocal { + client_id: string + client_secret: string +}