feat(update): better updating to clients, docs
This commit is contained in:
Родитель
4546599a24
Коммит
a14cbdd277
|
@ -0,0 +1,79 @@
|
|||
# Contributing
|
||||
|
||||
Anyone is welcome to help with Firefox Accounts. Feel free to get in touch with other community members on IRC, the
|
||||
mailing list or through issues here on GitHub.
|
||||
|
||||
- IRC: `#fxa` on `irc.mozilla.org`
|
||||
- Mailing list: <https://mail.mozilla.org/listinfo/dev-fxacct>
|
||||
- and of course, [the issues list](https://github.com/mozilla/fxa-oauth-server/issues)
|
||||
|
||||
## Bug Reports ##
|
||||
|
||||
You can file issues here on GitHub. Please try to include as much information as you can and under what conditions
|
||||
you saw the issue.
|
||||
|
||||
## Sending Pull Requests ##
|
||||
|
||||
Patches should be submitted as pull requests (PR).
|
||||
|
||||
Before submitting a PR:
|
||||
- Your code must run and pass all the automated tests before you submit your PR for review. "Work in progress" pull requests are allowed to be submitted, but should be clearly labeled as such and should not be merged until all tests pass and the code has been reviewed.
|
||||
- Run `npm test` to make sure all tests still pass and there are no lint errors.
|
||||
- Your patch should include new tests that cover your changes. It is your and your reviewer's responsibility to ensure your patch includes adequate tests.
|
||||
|
||||
When submitting a PR:
|
||||
- You agree to license your code under the project's open source license ([MPL 2.0](/LICENSE)).
|
||||
- Base your branch off the current `master` (see below for an example workflow).
|
||||
- Add both your code and new tests if relevant.
|
||||
- Run `grunt jshint` and `npm test` to make sure your code passes linting and tests.
|
||||
- Please do not include merge commits in pull requests; include only commits with the new relevant code.
|
||||
|
||||
See the main [README.md](/README.md) for information on prerequisites, installing, running and testing.
|
||||
|
||||
## Code Review ##
|
||||
|
||||
This project is production Mozilla code and subject to our [engineering practices and quality standards](https://developer.mozilla.org/en-US/docs/Mozilla/Developer_guide/Committing_Rules_and_Responsibilities). Every patch must be peer reviewed. This project is part of the [Firefox Accounts module](https://wiki.mozilla.org/Modules/Other#Firefox_Accounts), and your patch must be reviewed by one of the listed module owners or peers.
|
||||
|
||||
## Example Workflow ##
|
||||
|
||||
This is an example workflow to make it easier to submit Pull Requests. Imagine your username is `user1`:
|
||||
|
||||
1. Fork this repository via the GitHub interface
|
||||
|
||||
2. The clone the upstream (as origin) and add your own repo as a remote:
|
||||
|
||||
```sh
|
||||
$ git clone https://github.com/mozilla/fxa-oauth-console.git
|
||||
$ cd fxa-oauth-console
|
||||
$ git remote add user1 git@github.com:user1/fxa-oauth-console.git
|
||||
```
|
||||
|
||||
3. Create a branch for your fix/feature and make sure it's your currently checked-out branch:
|
||||
|
||||
```sh
|
||||
$ git checkout -b add-new-feature
|
||||
```
|
||||
|
||||
4. Add/fix code, add tests then commit and push this branch to your repo:
|
||||
|
||||
```sh
|
||||
$ git add <files...>
|
||||
$ git commit
|
||||
$ git push user1 add-new-feature
|
||||
```
|
||||
|
||||
5. From the GitHub interface for your repo, click the `Review Changes and Pull Request` which appears next to your new branch.
|
||||
|
||||
6. Click `Send pull request`.
|
||||
|
||||
### Keeping up to Date ###
|
||||
|
||||
The main reason for creating a new branch for each feature or fix is so that you can track master correctly. If you need
|
||||
to fetch the latest code for a new fix, try the following:
|
||||
|
||||
```sh
|
||||
$ git checkout master
|
||||
$ git pull
|
||||
```
|
||||
|
||||
Now you're ready to branch again for your new feature (from step 3 above).
|
18
README.md
18
README.md
|
@ -5,7 +5,7 @@
|
|||
|
||||
## Development
|
||||
|
||||
Installation:
|
||||
Install:
|
||||
|
||||
```
|
||||
git clone https://github.com/mozilla/fxa-oauth-console
|
||||
|
@ -13,18 +13,20 @@ cd fxa-oauth-console
|
|||
npm install
|
||||
```
|
||||
|
||||
Running tests:
|
||||
|
||||
```
|
||||
npm test
|
||||
```
|
||||
|
||||
Running the server locally:
|
||||
Run development server locally:
|
||||
|
||||
```
|
||||
npm start
|
||||
```
|
||||
|
||||
**You will need a local Firefox Accounts stack.**
|
||||
|
||||
Run tests:
|
||||
|
||||
```
|
||||
npm test
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
[MPL v2.0](LICENSE)
|
||||
|
|
|
@ -15,49 +15,102 @@ export default DS.RESTAdapter.extend({
|
|||
* API Host
|
||||
*/
|
||||
host: config.servers.oauth,
|
||||
/**
|
||||
* Request headers
|
||||
*
|
||||
* Sets Authorization headers
|
||||
*/
|
||||
headers: Ember.computed(function () {
|
||||
return {
|
||||
'Authorization': 'Bearer ' + this.get('session.content.token')
|
||||
};
|
||||
}),
|
||||
/**
|
||||
* Overrides default RESTAdapter 'find'.
|
||||
*
|
||||
* @param store
|
||||
* @param type
|
||||
* @param id
|
||||
* @param record
|
||||
* @returns {*}
|
||||
*/
|
||||
find: function(store, type, id, record) {
|
||||
// post process the resuld of 'find'. Need to add the Model type 'client' into the response
|
||||
return this.ajax(this.buildURL(type.typeKey, id, record), 'GET').then(function (resp) {
|
||||
resp.id = id;
|
||||
|
||||
return { client: resp };
|
||||
});
|
||||
},
|
||||
/**
|
||||
* Overrides default RESTAdapter 'createRecord'
|
||||
*
|
||||
* @param store
|
||||
* @param type
|
||||
* @param record
|
||||
* @returns {*}
|
||||
*/
|
||||
createRecord: function(store, type, record) {
|
||||
var data = {};
|
||||
var serializer = store.serializerFor(type.typeKey);
|
||||
|
||||
serializer.serializeIntoHash(data, type, record, { includeId: true });
|
||||
|
||||
// post process the resuld of 'find'. Need to add the Model type 'client' into the response
|
||||
return this.ajax(this.buildURL(type.typeKey, null, record), "POST", { data: data }).then(function (resp) {
|
||||
|
||||
resp.id = resp.client_id;
|
||||
delete resp.client_id;
|
||||
|
||||
return { client: resp };
|
||||
});
|
||||
},
|
||||
buildURL: function(type, id, record) {
|
||||
var url = [],
|
||||
host = this.host,
|
||||
prefix = this.urlPrefix();
|
||||
/**
|
||||
* Overrides default RESTAdapter 'updateRecord'
|
||||
* @param store
|
||||
* @param type
|
||||
* @param record
|
||||
* @returns {*}
|
||||
*/
|
||||
updateRecord: function(store, type, record) {
|
||||
var data = {};
|
||||
var serializer = store.serializerFor(type.typeKey);
|
||||
serializer.serializeIntoHash(data, type, record);
|
||||
|
||||
var id = record.id;
|
||||
// set POST instead of PUT
|
||||
return this.ajax(this.buildURL(type.typeKey, id, record), "POST", { data: data }).then(function () {
|
||||
data.id = id;
|
||||
|
||||
return { client: data };
|
||||
});
|
||||
},
|
||||
/**
|
||||
/**
|
||||
* Overrides default RESTAdapter 'buildURL'.
|
||||
* @param type
|
||||
* @param id
|
||||
* @param record
|
||||
* @returns {Array}
|
||||
*/
|
||||
buildURL: function(type, id, record) {
|
||||
var url = [];
|
||||
var host = this.host;
|
||||
var prefix = this.urlPrefix();
|
||||
|
||||
// FxA OAuth API requires singular 'client' when the record id is set
|
||||
if (record) {
|
||||
url.push('client');
|
||||
} else {
|
||||
url.push('clients');
|
||||
}
|
||||
|
||||
if (id && !Ember.isArray(id)) { url.push(encodeURIComponent(id)); }
|
||||
if (id && !Ember.isArray(id)) {
|
||||
url.push(encodeURIComponent(id));
|
||||
}
|
||||
|
||||
if (prefix) { url.unshift(prefix); }
|
||||
if (prefix) {
|
||||
url.unshift(prefix);
|
||||
}
|
||||
|
||||
url = url.join('/');
|
||||
if (!host && url) { url = '/' + url; }
|
||||
if (!host && url) {
|
||||
url = '/' + url;
|
||||
}
|
||||
|
||||
return url;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
import Ember from 'ember';
|
||||
|
||||
export default Ember.Controller.extend({
|
||||
needs: ['client']
|
||||
});
|
|
@ -0,0 +1,10 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
import Ember from 'ember';
|
||||
|
||||
export default Ember.Controller.extend({
|
||||
sortProperties: ['name'],
|
||||
sortAscending: true
|
||||
});
|
|
@ -6,6 +6,7 @@ import Ember from 'ember';
|
|||
|
||||
export var initialize = function(container, application) {
|
||||
Ember.A(['adapter', 'controller', 'route']).forEach(function(component) {
|
||||
// inject session into adapters, controllers and routes
|
||||
application.inject(component, 'session', 'simple-auth-session:main');
|
||||
});
|
||||
};
|
||||
|
|
|
@ -5,9 +5,21 @@
|
|||
import Ember from 'ember';
|
||||
import Base from 'simple-auth/authenticators/base';
|
||||
|
||||
/**
|
||||
* Custom Ember Simple Auth Authenticator
|
||||
* See docs: http://ember-simple-auth.simplabs.com/ember-simple-auth-api-docs.html
|
||||
*/
|
||||
var CustomAuthenticator = Base.extend({
|
||||
/**
|
||||
* Token endpoint
|
||||
*/
|
||||
tokenEndpoint: '/oauth',
|
||||
|
||||
/**
|
||||
* Restores application session data
|
||||
*
|
||||
* @param data
|
||||
* @returns {Rx.Promise}
|
||||
*/
|
||||
restore: function(data) {
|
||||
return new Ember.RSVP.Promise(function(resolve, reject) {
|
||||
if (!Ember.isEmpty(data.token)) {
|
||||
|
@ -18,6 +30,11 @@ var CustomAuthenticator = Base.extend({
|
|||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Authenticate the user using the server side endpoint
|
||||
*
|
||||
* @returns {Rx.Promise}
|
||||
*/
|
||||
authenticate: function () {
|
||||
var _this = this;
|
||||
|
||||
|
@ -27,35 +44,46 @@ var CustomAuthenticator = Base.extend({
|
|||
type: 'GET',
|
||||
contentType: 'application/json'
|
||||
}).then(function (response) {
|
||||
response = JSON.parse(response);
|
||||
try {
|
||||
response = JSON.parse(response);
|
||||
} catch (e) {
|
||||
return reject(e);
|
||||
}
|
||||
|
||||
Ember.run(function () {
|
||||
if (response && response.email && response.token) {
|
||||
if (response && response.email && response.token && response.code) {
|
||||
|
||||
return resolve({
|
||||
code: response.code,
|
||||
email: response.email,
|
||||
token: response.token
|
||||
});
|
||||
} else {
|
||||
|
||||
return reject();
|
||||
return reject('Respose missing credential data.');
|
||||
}
|
||||
});
|
||||
}, function (xhr/*, status, error*/) {
|
||||
var response = xhr.responseText;
|
||||
|
||||
try {
|
||||
response = JSON.parse(xhr.responseText);
|
||||
} catch (e) {
|
||||
|
||||
return reject();
|
||||
}
|
||||
|
||||
Ember.run(function () {
|
||||
reject(response.error);
|
||||
return reject(response.error);
|
||||
});
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Invalidates the user session on the server
|
||||
*
|
||||
* @returns {Rx.Promise}
|
||||
*/
|
||||
invalidate: function () {
|
||||
var _this = this;
|
||||
|
||||
|
@ -73,7 +101,8 @@ var CustomAuthenticator = Base.extend({
|
|||
export default {
|
||||
name: 'authentication',
|
||||
before: 'simple-auth',
|
||||
initialize: function (container/*, application*/) {
|
||||
initialize: function (container) {
|
||||
// registers the custom authenticator
|
||||
container.register('authenticator:custom', CustomAuthenticator);
|
||||
}
|
||||
};
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
import Ember from 'ember';
|
||||
import AuthenticatedRouteMixin from 'simple-auth/mixins/authenticated-route-mixin';
|
||||
|
||||
export default Ember.Route.extend(AuthenticatedRouteMixin, {
|
||||
actions: {
|
||||
update: function (model) {
|
||||
this.transitionTo('client.update', model);
|
||||
},
|
||||
remove: function (id) {
|
||||
return this.store.find('client', id).then(function (client) {
|
||||
client.destroyRecord();
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
|
@ -5,4 +5,17 @@
|
|||
import Ember from 'ember';
|
||||
import AuthenticatedRouteMixin from 'simple-auth/mixins/authenticated-route-mixin';
|
||||
|
||||
export default Ember.Route.extend(AuthenticatedRouteMixin, {});
|
||||
export default Ember.Route.extend(AuthenticatedRouteMixin, {
|
||||
actions: {
|
||||
update: function(model) {
|
||||
var _this = this;
|
||||
|
||||
return model.save().then(function () {
|
||||
_this.transitionTo('client.index', model.id);
|
||||
});
|
||||
},
|
||||
cancel: function() {
|
||||
return this.transitionTo('clients');
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -28,9 +28,7 @@ export default Ember.Route.extend(AuthenticatedRouteMixin, {
|
|||
this.transitionTo('clients');
|
||||
},
|
||||
remove: function (id) {
|
||||
console.log(id);
|
||||
return this.store.find('client', id).then(function (client) {
|
||||
console.log(client);
|
||||
client.destroyRecord();
|
||||
});
|
||||
},
|
||||
|
|
|
@ -51,6 +51,18 @@
|
|||
|
||||
.table {
|
||||
width: 100%;
|
||||
&.table-clients {
|
||||
a {
|
||||
font-weight: bold;
|
||||
font-size: 20px;
|
||||
padding: 10px 0;
|
||||
display: block;
|
||||
}
|
||||
}
|
||||
td.table-actions {
|
||||
width: 25%;
|
||||
text-align: center;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,19 +1,46 @@
|
|||
<div class="form-group">
|
||||
<label for="inputImage">ID</label>
|
||||
<input type="text" disabled="disabled" {{bind-attr value=id}} id="id"/>
|
||||
<h3>OAuth Client: <strong>{{name}}</strong></h3>
|
||||
|
||||
<table class="table">
|
||||
<tbody>
|
||||
<tr>
|
||||
<th>Client ID:</th>
|
||||
<td>{{id}}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Redirect URI</th>
|
||||
<td>{{redirect_uri}}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Image URI</th>
|
||||
<td>{{image_uri}}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Client Secret</th>
|
||||
<td>
|
||||
<button class="tiny button">Reset Client Secret</button>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<div class="row">
|
||||
<div class="large-6 columns">
|
||||
<ul class="inline-list ">
|
||||
<li>
|
||||
{{#link-to 'clients' classNames="small button success"}}< Back to Clients{{/link-to}}
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="large-6 columns">
|
||||
<ul class="inline-list right">
|
||||
<li>
|
||||
<button class="small button " {{action 'update' id}}>Update Client</button>
|
||||
</li>
|
||||
<li>
|
||||
<button class="small button alert" {{action 'remove' id}}>Delete Client</button>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="inputTitle">Client Name</label>
|
||||
{{name}}
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="inputRedirect">Redirect URI</label>
|
||||
{{redirect_uri}}
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="inputImage">Image URI</label>
|
||||
{{image_uri}}
|
||||
</div>
|
||||
{{outlet}}
|
||||
|
|
|
@ -1,19 +1,18 @@
|
|||
<button {{action 'goToNewClient' }} class="small button success">Create a new OAuth Client</button>
|
||||
<button {{action 'goToNewClient' }} class="small button success">+ Create a new OAuth Client</button>
|
||||
<hr/>
|
||||
|
||||
<table class="table">
|
||||
<table class="table table-clients">
|
||||
<tbody>
|
||||
<tr>
|
||||
<th>ID</th>
|
||||
<th>Name</th>
|
||||
<th>Redirect URI</th>
|
||||
</tr>
|
||||
{{#each client in content}}
|
||||
<tr>
|
||||
<td {{action 'goToClient' client.id}}>{{client.id}}</td>
|
||||
<td>{{client.name}}</td>
|
||||
<td><a {{action 'goToClient' client.id}}>{{client.name}}</a>{{client.id}}</td>
|
||||
<td>{{client.redirect_uri}}</td>
|
||||
<td>
|
||||
<td class="table-actions">
|
||||
<button class="small button " {{action 'update' client.id}}>Update</button>
|
||||
<button class="small button alert" {{action 'remove' client.id}}>Delete</button>
|
||||
</td>
|
||||
</tr>
|
||||
|
|
|
@ -33,7 +33,8 @@ router.get('/status', function (req, res) {
|
|||
if (req.session && req.session.email) {
|
||||
return res.send(JSON.stringify({
|
||||
email: req.session.email,
|
||||
token: req.session.token
|
||||
token: req.session.token,
|
||||
code: req.session.code
|
||||
}));
|
||||
} else {
|
||||
return res.status(401).end();
|
||||
|
@ -81,6 +82,7 @@ router.get('/redirect', function (req, res) {
|
|||
}
|
||||
|
||||
log.verbose(err, body);
|
||||
req.session.code = code;
|
||||
req.session.scopes = body.scopes;
|
||||
req.session.token_type = body.token_type;
|
||||
var token = req.session.token = body.access_token;
|
||||
|
|
|
@ -40,7 +40,6 @@
|
|||
},
|
||||
"devDependencies": {
|
||||
"ember-cli": "0.1.2",
|
||||
"ember-cli-inject-live-reload": "^1.3.0",
|
||||
"ember-cli-qunit": "0.1.0",
|
||||
"grunt": "^0.4.5",
|
||||
"grunt-cli": "^0.1.13",
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
import {
|
||||
moduleFor,
|
||||
test
|
||||
} from 'ember-qunit';
|
||||
|
||||
moduleFor('controller:clients', 'ClientsController', {
|
||||
// Specify the other units that are required for this test.
|
||||
// needs: ['controller:foo']
|
||||
});
|
||||
|
||||
// Replace this with your real tests.
|
||||
test('it exists', function() {
|
||||
var controller = this.subject();
|
||||
ok(controller);
|
||||
});
|
Загрузка…
Ссылка в новой задаче