forked from TryGhost/Ghost
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
no issue - added ghost-admin client_id to admin - added ghost-admin client_secret to admin - added client.read() api endpoint - added random generation of client_secret to migration - removed addClientSecret method - updated tests
- Loading branch information
Showing
12 changed files
with
93 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,11 @@ | ||
import Ember from 'ember'; | ||
import Authenticator from 'simple-auth-oauth2/authenticators/oauth2'; | ||
|
||
export default Authenticator.extend({ | ||
config: Ember.inject.service(), | ||
makeRequest: function (url, data) { | ||
data.client_id = 'ghost-admin'; | ||
data.client_id = this.get('config.clientId'); | ||
data.client_secret = this.get('config.clientSecret'); | ||
return this._super(url, data); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// # Client API | ||
// RESTful API for the Client resource | ||
var Promise = require('bluebird'), | ||
_ = require('lodash'), | ||
dataProvider = require('../models'), | ||
errors = require('../errors'), | ||
utils = require('./utils'), | ||
pipeline = require('../utils/pipeline'), | ||
|
||
docName = 'clients', | ||
clients; | ||
|
||
/** | ||
* ### Clients API Methods | ||
* | ||
* **See:** [API Methods](index.js.html#api%20methods) | ||
*/ | ||
clients = { | ||
|
||
/** | ||
* ## Read | ||
* @param {{id}} options | ||
* @return {Promise<Client>} Client | ||
*/ | ||
read: function read(options) { | ||
var attrs = ['id', 'slug'], | ||
tasks; | ||
|
||
/** | ||
* ### Model Query | ||
* Make the call to the Model layer | ||
* @param {Object} options | ||
* @returns {Object} options | ||
*/ | ||
function doQuery(options) { | ||
// only User Agent (type = `ua`) clients are available at the moment. | ||
options.data = _.extend(options.data, {type: 'ua'}); | ||
return dataProvider.Client.findOne(options.data, _.omit(options, ['data'])); | ||
} | ||
|
||
// Push all of our tasks into a `tasks` array in the correct order | ||
tasks = [ | ||
utils.validate(docName, {attrs: attrs}), | ||
// TODO: add permissions | ||
// utils.handlePublicPermissions(docName, 'read'), | ||
doQuery | ||
]; | ||
|
||
// Pipeline calls each task passing the result of one to be the arguments for the next | ||
return pipeline(tasks, options).then(function formatResponse(result) { | ||
if (result) { | ||
return {clients: [result.toJSON(options)]}; | ||
} | ||
|
||
return Promise.reject(new errors.NotFoundError('Client not found.')); | ||
}); | ||
} | ||
}; | ||
|
||
module.exports = clients; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,7 +31,7 @@ describe('Authentication API', function () { | |
|
||
it('can authenticate', function (done) { | ||
request.post(testUtils.API.getApiQuery('authentication/token')) | ||
.send({grant_type: 'password', username: user.email, password: user.password, client_id: 'ghost-admin'}) | ||
.send({grant_type: 'password', username: user.email, password: user.password, client_id: 'ghost-admin', client_secret: 'not_available'}) | ||
.expect('Content-Type', /json/) | ||
// TODO: make it possible to override oauth2orize's header so that this is consistent | ||
.expect('Cache-Control', 'no-store') | ||
|
@@ -52,7 +52,7 @@ describe('Authentication API', function () { | |
|
||
it('can\'t authenticate unknown user', function (done) { | ||
request.post(testUtils.API.getApiQuery('authentication/token')) | ||
.send({grant_type: 'password', username: '[email protected]', password: user.password, client_id: 'ghost-admin'}) | ||
.send({grant_type: 'password', username: '[email protected]', password: user.password, client_id: 'ghost-admin', client_secret: 'not_available'}) | ||
.expect('Content-Type', /json/) | ||
.expect('Cache-Control', testUtils.cacheRules['private']) | ||
.expect(404) | ||
|
@@ -69,7 +69,7 @@ describe('Authentication API', function () { | |
|
||
it('can\'t authenticate invalid password user', function (done) { | ||
request.post(testUtils.API.getApiQuery('authentication/token')) | ||
.send({grant_type: 'password', username: user.email, password: 'invalid', client_id: 'ghost-admin'}) | ||
.send({grant_type: 'password', username: user.email, password: 'invalid', client_id: 'ghost-admin', client_secret: 'not_available'}) | ||
.expect('Content-Type', /json/) | ||
.expect('Cache-Control', testUtils.cacheRules['private']) | ||
.expect(401) | ||
|
@@ -86,7 +86,7 @@ describe('Authentication API', function () { | |
|
||
it('can request new access token', function (done) { | ||
request.post(testUtils.API.getApiQuery('authentication/token')) | ||
.send({grant_type: 'password', username: user.email, password: user.password, client_id: 'ghost-admin'}) | ||
.send({grant_type: 'password', username: user.email, password: user.password, client_id: 'ghost-admin', client_secret: 'not_available'}) | ||
.expect('Content-Type', /json/) | ||
// TODO: make it possible to override oauth2orize's header so that this is consistent | ||
.expect('Cache-Control', 'no-store') | ||
|
@@ -97,7 +97,7 @@ describe('Authentication API', function () { | |
} | ||
var refreshToken = res.body.refresh_token; | ||
request.post(testUtils.API.getApiQuery('authentication/token')) | ||
.send({grant_type: 'refresh_token', refresh_token: refreshToken, client_id: 'ghost-admin'}) | ||
.send({grant_type: 'refresh_token', refresh_token: refreshToken, client_id: 'ghost-admin', client_secret: 'not_available'}) | ||
.expect('Content-Type', /json/) | ||
// TODO: make it possible to override oauth2orize's header so that this is consistent | ||
.expect('Cache-Control', 'no-store') | ||
|
@@ -116,7 +116,7 @@ describe('Authentication API', function () { | |
|
||
it('can\'t request new access token with invalid refresh token', function (done) { | ||
request.post(testUtils.API.getApiQuery('authentication/token')) | ||
.send({grant_type: 'refresh_token', refresh_token: 'invalid', client_id: 'ghost-admin'}) | ||
.send({grant_type: 'refresh_token', refresh_token: 'invalid', client_id: 'ghost-admin', client_secret: 'not_available'}) | ||
.expect('Content-Type', /json/) | ||
.expect('Cache-Control', testUtils.cacheRules['private']) | ||
.expect(403) | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters