Skip to content

[Issue #42] Allow a 'redirect_url' parameter for client registrations#43

Merged
ferjm merged 1 commit intomozilla-sensorweb:masterfrom
ferjm:redirect_url
Jan 11, 2017
Merged

[Issue #42] Allow a 'redirect_url' parameter for client registrations#43
ferjm merged 1 commit intomozilla-sensorweb:masterfrom
ferjm:redirect_url

Conversation

@ferjm
Copy link
Member

@ferjm ferjm commented Jan 9, 2017

No description provided.

@ferjm ferjm requested a review from julienw January 9, 2017 18:11
@coveralls
Copy link

Coverage Status

Coverage increased (+0.5%) to 86.066% when pulling 522822a on ferjm:redirect_url into 7c81079 on mozilla-sensorweb:master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.5%) to 86.066% when pulling dc2a1b4 on ferjm:redirect_url into 7c81079 on mozilla-sensorweb:master.

Copy link
Collaborator

@julienw julienw left a comment

Choose a reason for hiding this comment

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

Some nits, some questions, some remarks for later.

doc/API.md Outdated
Copy link
Collaborator

Choose a reason for hiding this comment

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

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
Copy link
Collaborator

Choose a reason for hiding this comment

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

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...

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok, fair enough

Copy link
Collaborator

Choose a reason for hiding this comment

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

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.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I realize we also need a authFailureRedirectUrl (that could be null)

Copy link
Member Author

Choose a reason for hiding this comment

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

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);
Copy link
Collaborator

Choose a reason for hiding this comment

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

(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:

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll file an issue for this.

Copy link
Member Author

Choose a reason for hiding this comment

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

#44

Copy link
Collaborator

Choose a reason for hiding this comment

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

same remark about the naming: authRedirectUrl ?

Copy link
Collaborator

Choose a reason for hiding this comment

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

So it's optional ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, as mentioned above, I think it should be optional.

break;
case 'name':
errno = ERRNO_INVALID_API_CLIENT_NAME;
break;
Copy link
Collaborator

Choose a reason for hiding this comment

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

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 :) )

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok

Copy link
Collaborator

Choose a reason for hiding this comment

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

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)

Copy link
Member Author

Choose a reason for hiding this comment

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

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.

Copy link
Collaborator

Choose a reason for hiding this comment

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

ok for me !

@coveralls
Copy link

Coverage Status

Coverage increased (+0.5%) to 86.111% when pulling 642ebf8 on ferjm:redirect_url into 7c81079 on mozilla-sensorweb:master.

@ferjm ferjm requested a review from julienw January 11, 2017 16:26
Copy link
Collaborator

@julienw julienw left a comment

Choose a reason for hiding this comment

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

lgtm, thx !

@ferjm ferjm merged commit 71b32ca into mozilla-sensorweb:master Jan 11, 2017
@ferjm ferjm deleted the redirect_url branch January 11, 2017 20:01
const validator = expressValidator.validator;
return Array.isArray(value) &&
value.length > 0 &&
value.every(item => validator.isUrl(item, options));
Copy link
Collaborator

Choose a reason for hiding this comment

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

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'] })
Copy link
Collaborator

Choose a reason for hiding this comment

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

this should have found the issue; I don't know why this doesn't :/ (but locally it actually fails for me...)

Copy link
Collaborator

Choose a reason for hiding this comment

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

ah, this is interesting, this works with a clean node_modules. :)

Copy link
Collaborator

Choose a reason for hiding this comment

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

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...

Copy link
Member Author

Choose a reason for hiding this comment

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

Ugh... thanks for finding the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

Comments