Skip to content
This repository has been archived by the owner on Mar 19, 2021. It is now read-only.

feat(clients): implement all the commands #4

Merged
merged 2 commits into from
Feb 4, 2015
Merged

feat(clients): implement all the commands #4

merged 2 commits into from
Feb 4, 2015

Conversation

seanmonstar
Copy link
Contributor

This command will return a list of clients registered with the server.
The command can be passed a --token option to skip fetching a new token.

password: password,
error.assert(program.fxa, '--fxa or --env');
error.assert(program.url, '--url or --env');
if (program.token) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you need to add some sort of program.option('--token <token') declaration in the option-parsing logic to accommodate this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fear that this command-line-parsing lib doesn't like having both a --token option and a token sub-command.

When I try to run it like this to generate an oauth token:

./bin/fxa-oauth.js --env=latest --user=rfkelly@mozilla.com token 24bdbfa45cd300c5 oauth

It fails out complaining about a "missing email". Tracing it through, I can see that it's taking this if (program.token) branch even though I haven't specified a --token command-line option. And logging the contents of program.token show that it's some sort of object with the command-line args etc in it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually this is better as it's a valid canGrant clientId:

./bin/fxa-oauth.js --env=latest --user=rfkelly@mozilla.com token 5882386c6d801776 oauth

This works on master but fails out with "missing email" on this branch.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It also works if I rename the --token option to --tok.

@seanmonstar
Copy link
Contributor Author

@rfk forgot to mention last week that i'd pushed an update.

@@ -40,6 +43,15 @@ const URLS = {
]
};

function yesno(val) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name suggests this should handle strings like "no" and "false" as well, but it doesn't. Should it?

I'd also prefer a clearer name e.g. toBoolean, but don't feel strongly about it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should handle strings like "no" and "false" as well

Uh, my bad, of course it handles this as part of the "anything that's not explicitly true" default case.

@rfk
Copy link
Contributor

rfk commented Dec 10, 2014

Code looks good, I'm going to try taking it for a spin.

const Client = require('../');
const log = require('npmlog');
const read = P.promisify(require('read'));

const CLI_CLIENT_ID = '66041b7ec3991ec0';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a newly-provisioned ID that we need to add to all our envs?

@seanmonstar seanmonstar changed the title feat(clients): implement the "clients" command feat(clients): implement all the commands Jan 6, 2015
@@ -3,3 +3,26 @@
A command line tool to ease interacting with the OAuth implementation of
Firefox Accounts.

```
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ckolos How's this usage look?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gimme a sample usage and lgtm...

@seanmonstar
Copy link
Contributor Author

@rfk ok, so I removed the token option, since it seemed problematic. Instead, the Client will just fetch a token for every request, and then cleanup afterwards.

method: 'post',
url: this._baseUrl + '/v1/destroy',
json: {
token: token
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rfk
Copy link
Contributor

rfk commented Jan 27, 2015

Code looks good, will take it for a spin this afternoon

-u, --user <email> Env: FXA_USER
--url <url> The base url of the OAuth server
--fxa <url> The base url of the Auth server
-v, --verbose Receive verbose output.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might consider a matching -q, --quiet option as well; the default logging verbosity seems to log all requests and responses, which is nice for trying it out but may be too verbose for e.g. scripted use.

@rfk
Copy link
Contributor

rfk commented Jan 27, 2015

Running the clients command I get an error like so:

fxa http 403 https://oauth-latest.dev.lcip.org/v1/clients
fxa ERR! oauth Forbidden
fxa ERR! token temporary token was not cleaned up!

I guess this is because of mozilla/fxa-oauth-server#198 which hasn't propagated out to the dev servers yet?

name: {},
redirectUri: {},
imageUri: {},
canGrant: {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These all need to be snake_case rather than camelCase, to match the form expected by the API per https://github.com/mozilla/fxa-oauth-server/blob/master/docs/api.md#post-v1client

@rfk
Copy link
Contributor

rfk commented Jan 27, 2015

After the above-mentioned tweaks to get the register command running, it fails with a 500 Server Error and the following traceback on the fxa-oauth-server logs:

{"Timestamp":1422332816497000000,"Logger":"fxa-oauth-server","Type":"summary.summary","Severity":2,"Pid":13970,"EnvVersion":"2.0","Fields":{"code":500,"errno":999,"method":"post","path":"/v1/client","t":21,"auth":"{\"user\":\"1c44d32a121546d8a5b3431dab450cfb\",\"scope\":[\"oauth\"]}","payload":"[\"name\",\"can_grant\",\"image_uri\",\"redirect_uri\"]","stack":"Error: whitelisted is required\n    at Object.exports.create (/data/fxa-oauth-server/node_modules/hapi/node_modules/boom/lib/index.js:21:17)\n    at Object.exports.internal (/data/fxa-oauth-server/node_modules/hapi/node_modules/boom/lib/index.js:246:92)\n    at Object.exports.badImplementation (/data/fxa-oauth-server/node_modules/hapi/node_modules/boom/lib/index.js:282:23)\n    at postValidate (/data/fxa-oauth-server/node_modules/hapi/lib/validation.js:150:26)\n    at internals.Any._validateWithOptions (/data/fxa-oauth-server/node_modules/joi/lib/any.js:430:16)\n    at root.validate (/data/fxa-oauth-server/node_modules/joi/lib/index.js:102:23)\n    at exports.response (/data/fxa-oauth-server/node_modules/hapi/lib/validation.js:159:16)\n    at /data/fxa-oauth-server/node_modules/hapi/lib/request.js:304:13\n    at iterate (/data/fxa-oauth-server/node_modules/hapi/node_modules/items/lib/index.js:35:13)\n    at done (/data/fxa-oauth-server/node_modules/hapi/node_modules/items/lib/index.js:27:25)"}}

I guess this is due to not providing a value for whitelisted as part of the request. Forcing it to send whitelisted=false allows the registration to succeed for me.

.command('update <clientId> <property> <value>')
.description('Update a property of a client.')
.action(function(id, prop, value) {
//TODO: validate id,prop,value
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried update CLIENTID canGrant true and it reported success, despite the property name being invalid. I guess this is partly missing client-side validation, and partly the server not rejecting unknown fields.

Doing update CLIENTID can_grant true seems to work correctly, with the modified value reflecting in a subsequent client listing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm thinking that the leniency allowed in the server to ease using the OAuth endpoints should only be enabled for those specific endpoints (POST /v1/authorization). Otherwise, tossing 400s seems better.

- `list`: provides a list of all registered clients
- `register`: prompts for details to register a new client
- `update`: updates a single property on a registered client
- `delete`: deletes a client! boom!

The commands will delete the token after usage, or blow up with an error
if the token couldn't be deleted.
@seanmonstar
Copy link
Contributor Author

Addressed comments.

@ckarlof
Copy link

ckarlof commented Feb 3, 2015

@rfk, after @seanmonstar's most recent updates, are we ready to merge?

@rfk
Copy link
Contributor

rfk commented Feb 3, 2015

I am literally trying this out again right now :-)

.action(function(id, prop, value) {
//TODO: validate id,prop,value
withTempToken(function(oauth) {
var client = { id: id };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The oauth server doesn't take "id" in the request body when updating a client record. This used to be silently ignored but it's now failing. We need to either accept a matching "id" in the request body on the server, or stop sending it in the client.

@rfk
Copy link
Contributor

rfk commented Feb 4, 2015

There's something weird going on with the temp-token cleanup and the delete command. Take a look at the following:

$> ./bin/fxa-oauth.js -e latest delete 061b0de00efa3424 
fxa info env latest
fxa info user rfkelly@mozilla.com
fxa http POST https://latest.dev.lcip.org/auth/v1/account/login
fxa http 200 https://latest.dev.lcip.org/auth/v1/account/login
fxa http POST https://latest.dev.lcip.org/auth/v1/certificate/sign
fxa http 200 https://latest.dev.lcip.org/auth/v1/certificate/sign
fxa http POST https://oauth-latest.dev.lcip.org/v1/authorization
fxa http 200 https://oauth-latest.dev.lcip.org/v1/authorization
fxa http GET https://oauth-latest.dev.lcip.org/v1/client/061b0de00efa3424
fxa http POST https://oauth-latest.dev.lcip.org/v1/destroy
fxa http 200 https://oauth-latest.dev.lcip.org/v1/client/061b0de00efa3424
Delete  "{\"id\":\"061b0de00efa3424\",\"name\":\"rfkelly test client four\",\"image_uri\":\"\",\"redirect_uri\":\"http://www.rfk.id.au/tst/me\"}"
Are you sure? y/n? (n) fxa http 200 https://oauth-latest.dev.lcip.org/v1/destroy
y
fxa info delete-client yes
fxa http DELETE https://oauth-latest.dev.lcip.org/v1/client/061b0de00efa3424
fxa http 401 https://oauth-latest.dev.lcip.org/v1/client/061b0de00efa3424

AFAICT what's happening is, it stops to prompt me and confirm the client deletion, but the cleanup code executes without waiting for my reply. The token gets deleted, then a enter "yes", and it gets a 401 trying to use the now-deleted token.

@rfk
Copy link
Contributor

rfk commented Feb 4, 2015

(I've also been getting sporadic 401s with other commands, which might be the same issue, but not surfacing regularly because they don't stop and prompt for any input)

@rfk
Copy link
Contributor

rfk commented Feb 4, 2015

With the client-id-field and switch-done-to-then fixes mentioned above, all commands run successfully for me; r+ with those fixes

@seanmonstar
Copy link
Contributor Author

@rfk your thorough reviewing has been invaluable. I've addressed the latest comments, in a new commit to make it easier to see what changed.

@rfk
Copy link
Contributor

rfk commented Feb 4, 2015

nice work @seanmonstar, 👍

rfk added a commit that referenced this pull request Feb 4, 2015
feat(clients): implement all the commands
@rfk rfk merged commit 14c4db2 into master Feb 4, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants