[Issue #42] Allow a 'redirect_url' parameter for client registrations#43
[Issue #42] Allow a 'redirect_url' parameter for client registrations#43ferjm merged 1 commit intomozilla-sensorweb:masterfrom
Conversation
julienw
left a comment
There was a problem hiding this comment.
Some nits, some questions, some remarks for later.
doc/API.md
Outdated
There was a problem hiding this comment.
nit: looks like an indentation mismatch; I don't have any preference with/without, up to you :)
| ERRNO_UNAUTHORIZED : 401, | ||
| ERRNO_FORBIDDEN : 403, | ||
| ERRNO_RESOURCE_NOT_FOUND : 404, | ||
| ERRNO_INTERNAL_ERROR : 500 |
There was a problem hiding this comment.
not for this patch, but I'm not a big fan of this indentation mechanism. As a result we need to change all lines when we really need to add 1 line...
src/models/clients.js
Outdated
There was a problem hiding this comment.
nit: tell me what you think, I would use "authRedirectUrl" to make it clear, when looking at the database, that this is for the authentication process.
There was a problem hiding this comment.
I realize we also need a authFailureRedirectUrl (that could be null)
There was a problem hiding this comment.
Sounds good. I'll change the naming and add the failure redirect url
| errno = ERRNO_INVALID_API_CLIENT_NAME; | ||
| break; | ||
| } | ||
| return ApiError(res, 400, errno, BAD_REQUEST); |
There was a problem hiding this comment.
(not for this patch either)
I don't really like how the errors are generated currently. For example I don't get why we need to put the numeric error number when errors.js already have it... It's also difficult to remember the order of the parameters.
Here is how I did it in a previous app:
- in the main app configuration file: https://github.com/project-abigail/calendar-server/blob/master/app.js#L46-L68
- here are my errors: https://github.com/project-abigail/calendar-server/blob/master/utils/errors.js
- here is an example about how to use them: https://github.com/project-abigail/calendar-server/blob/master/routes/users.js#L38-L41
There was a problem hiding this comment.
I'll file an issue for this.
src/routes/clients.js
Outdated
There was a problem hiding this comment.
same remark about the naming: authRedirectUrl ?
There was a problem hiding this comment.
Yes, as mentioned above, I think it should be optional.
| break; | ||
| case 'name': | ||
| errno = ERRNO_INVALID_API_CLIENT_NAME; | ||
| break; |
There was a problem hiding this comment.
nit: I'd find it more readable to use a default: close to set ERRNO_BAD_REQUEST. (+ eslint will be happier when I'll set it up :) )
src/models/clients.js
Outdated
There was a problem hiding this comment.
allowNull: false ? Or a null means we can't login ? :)
Another question: do you think a client would want to configure several redirect urls ? (Facebook permits it)
There was a problem hiding this comment.
allowNull: false makes the field mandatory. I was thinking that we should probably allow creating new clients without auth redirection urls. Some of these clients might not want to use the APIs that will require user authentication (I think for now we will have only an API to bookmark sensors requiring user authentication). Some clients might only be interested on pushing sensors data to the server. And for sensors authentication we can't use a redirection url (we can't redirect to a sensor) so the authentication process will be different.
Allowing to configure several redirection urls sounds good.
…ng clients registration
| const validator = expressValidator.validator; | ||
| return Array.isArray(value) && | ||
| value.length > 0 && | ||
| value.every(item => validator.isUrl(item, options)); |
There was a problem hiding this comment.
I realize that it is isURL we want here. I don't know why we didn't see it earlier, but now this fails badly for me.
| .send({ name: 'clientName' }) | ||
| .send({ name: 'clientName', | ||
| authRedirectUrls: ['http://something.com'], | ||
| authFailureRedirectUrls: ['http://something.com'] }) |
There was a problem hiding this comment.
this should have found the issue; I don't know why this doesn't :/ (but locally it actually fails for me...)
There was a problem hiding this comment.
ah, this is interesting, this works with a clean node_modules. :)
There was a problem hiding this comment.
https://github.com/sequelize/sequelize/blob/2f8930f84837722f5a6e2f288a3a20dcaf247d4e/lib/utils/validator-extras.js#L18-L20
oooh bad bad bad sequelize monkey-patching validatorjs, and so the behavior seems to depend on the order of something...
There was a problem hiding this comment.
Ugh... thanks for finding the issue.
No description provided.