@Injectable()
export class AuthService {
- private static BASE_CLIENT_URL = '/api/v1/users/client';
+ private static BASE_CLIENT_URL = '/api/v1/clients/local';
private static BASE_TOKEN_URL = '/api/v1/users/token';
loginChangedSource: Observable<AuthStatus>;
--- /dev/null
+'use strict'
+
+const config = require('config')
+const express = require('express')
+const mongoose = require('mongoose')
+
+const Client = mongoose.model('OAuthClient')
+
+const router = express.Router()
+
+router.get('/local', getLocalClient)
+
+// Get the client credentials for the PeerTube front end
+function getLocalClient (req, res, next) {
+ const serverHost = config.get('webserver.host')
+ const serverPort = config.get('webserver.port')
+ let headerHostShouldBe = serverHost
+ 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) {
+ return res.type('json').status(403).end()
+ }
+
+ Client.loadFirstClient(function (err, client) {
+ if (err) return next(err)
+ if (!client) return next(new Error('No client available.'))
+
+ res.json({
+ client_id: client._id,
+ client_secret: client.clientSecret
+ })
+ })
+}
+
+// ---------------------------------------------------------------------------
+
+module.exports = router
const router = express.Router()
+const clientsController = require('./clients')
const podsController = require('./pods')
const remoteController = require('./remote')
const usersController = require('./users')
const videosController = require('./videos')
+router.use('/clients', clientsController)
router.use('/pods', podsController)
router.use('/remote', remoteController)
router.use('/users', usersController)
'use strict'
const each = require('async/each')
-const config = require('config')
const express = require('express')
const mongoose = require('mongoose')
const waterfall = require('async/waterfall')
const oAuth = middlewares.oauth
const validatorsUsers = middlewares.validators.users
-const Client = mongoose.model('OAuthClient')
const User = mongoose.model('User')
const Video = mongoose.model('Video')
validatorsUsers.usersRemove,
removeUser
)
-router.get('/client', getAngularClient)
+
router.post('/token', oAuth.token, success)
// TODO: Once https://github.com/oauthjs/node-oauth2-server/pull/289 is merged, implement revoke token route
})
}
-function getAngularClient (req, res, next) {
- const serverHost = config.get('webserver.host')
- const serverPort = config.get('webserver.port')
- let headerHostShouldBe = serverHost
- 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) {
- return res.type('json').status(403).end()
- }
-
- Client.loadFirstClient(function (err, client) {
- if (err) return next(err)
- if (!client) return next(new Error('No client available.'))
-
- res.json({
- client_id: client._id,
- client_secret: client.clientSecret
- })
- })
-}
-
function listUsers (req, res, next) {
User.list(function (err, usersList) {
if (err) return next(err)