Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🌱 Adds support for autoPush url param in poll and verify functions #91

Merged
merged 1 commit into from
Feb 16, 2018

Conversation

gowthamidommety-okta
Copy link
Contributor

Resolves: OKTA-155565

@gowthamidommety-okta gowthamidommety-okta force-pushed the gd-OKTA-155565-autoPushHttpOnly branch from 84b035b to df2162d Compare February 6, 2018 18:33
lib/tx.js Outdated
if (rememberDevice) {
href += '?rememberDevice=true';
opts.rememberDevice = rememberDevice;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should we explicitly set this to true? Same question for autoPush and updatePhone

Choose a reason for hiding this comment

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

I think we should, so we don't change the current way this works for rememberDevice. And if we do the same for the other variables, then we will be consistent everywhere, plus they are supposed to be booleans (I am assuming that is also what the API expects)

@gowthamidommety-okta
Copy link
Contributor Author

Need to change description as this is not only for the poll function

Copy link

Choose a reason for hiding this comment

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

one comment in one the changes
and one important comment for the design: if I understand correctly, once we call pol({autoPush: true}) then we won't be able to change the value in all the polling requests. So for the UI that we want to change based on the checkbox, we will need to stop the current poll and then call verify again with the new value.

lib/tx.js Outdated
if (rememberDevice) {
href += '?rememberDevice=true';
opts.rememberDevice = rememberDevice;

Choose a reason for hiding this comment

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

I think we should, so we don't change the current way this works for rememberDevice. And if we do the same for the other variables, then we will be consistent everywhere, plus they are supposed to be booleans (I am assuming that is also what the API expects)

@gowthamidommety-okta gowthamidommety-okta force-pushed the gd-OKTA-155565-autoPushHttpOnly branch from 1cebed1 to 1a0724f Compare February 12, 2018 02:04
lib/tx.js Outdated
@@ -7,7 +7,8 @@ var AuthPollStopError = require('./errors/AuthPollStopError');
var config = require('./config');

function addStateToken(res, options) {
var builtArgs = util.clone(options) || {};
var builtArgs = {};
util.extend(builtArgs, options || {});
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed this to use extend. clone uses JSON.stringify which makes it difficult to use with functions.

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 work without the || {} check

lib/tx.js Outdated
var href = pollLink.href;
var opts = {};
if (autoPush !== undefined && autoPush !== null) {
opts.autoPush = (typeof autoPush === 'function') ? autoPush() : !!autoPush;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

autoPush now takes a boolean / function. It sets the option on every poll to account for the scenario when the checkbox is clicked during an active poll

Copy link
Contributor

Choose a reason for hiding this comment

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

Interesting. I wonder why this didn't come up for rememberDevice. It'd have the same problem, right?

Copy link
Contributor

Choose a reason for hiding this comment

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

Does this need to be a function for the simple verify case, or is the poll case sufficient?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Correct, I don't think the rememberDevice value will change if the checkbox is clicked during an active poll. However, we are implementing it this way for autoPush to keep it consistent with the way the autoPush cookie is set on the front end now.
It doesn't need to be a function for the verify case, I just thought it would be better to keep it consistent. What do you think?

Choose a reason for hiding this comment

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

Good point Len, it is interesting cause it definitely has the same problem. I was just checking and when you click verify, we send rememberDevice=true, but for polling we do not send that. And if we change the checkbox, then we don't change the value either. I do not know how the backend works for rememberDevice though... maybe we can have a follow up jira for that?
pollingrememberdevice

and yes, for verify it doesn't need to be a function, but my vote goes for the consistency.

Copy link
Contributor

Choose a reason for hiding this comment

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

re: verify - I'm down with consistency
re: rememberDevice - I'm curious if the server maintains the rememberDevice state for us. If it handles the rememberDevice state, it seems natural that it'd also handle the autoPush state. If it doesn't, we can do what this PR does (send it with every request). Is this a question for @srinivasanagandla-okta ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@kentonsmith-okta would you know the answer to the above ^ ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Spoke to @kentonsmith-okta about this. The backend seems to cache the rememberDevice value sent on the first verify and then save it on a successful authentication. If the user were to change the value during a poll, it would have no affect. The only way to clear a saved (true) value is to clear the browser's cookies.

lib/tx.js Outdated
var href = pollLink.href;
var opts = {};
if (autoPush !== undefined && autoPush !== null) {
opts.autoPush = (typeof autoPush === 'function') ? autoPush() : !!autoPush;
Copy link
Contributor

Choose a reason for hiding this comment

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

Interesting. I wonder why this didn't come up for rememberDevice. It'd have the same problem, right?

return test.trans.verify({
passCode: '123456',
autoPush: function () {
return true;
Copy link
Contributor

Choose a reason for hiding this comment

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

What should happen if autoPush() doesn't return true or false (let's say they accidentally return a Promise)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yea, that was something i was thinking about today. It would probably be better to force whatever the function returns to a boolean.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, let's force a boolean

return test.trans.verify({
passCode: '123456',
autoPush: function () {
return true;
Copy link
Contributor

Choose a reason for hiding this comment

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

It'd be nice to add a test that throws an error inside of autoPush (particularly in the polling case)

lib/tx.js Outdated
@@ -7,7 +7,8 @@ var AuthPollStopError = require('./errors/AuthPollStopError');
var config = require('./config');

function addStateToken(res, options) {
var builtArgs = util.clone(options) || {};
var builtArgs = {};
util.extend(builtArgs, options || {});
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 work without the || {} check

lib/tx.js Outdated
var href = pollLink.href;
var opts = {};
if (autoPush !== undefined && autoPush !== null) {
opts.autoPush = (typeof autoPush === 'function') ? autoPush() : !!autoPush;
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this need to be a function for the simple verify case, or is the poll case sufficient?

Copy link

Choose a reason for hiding this comment

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

just one comment in the test, the rest looks good.

lib/tx.js Outdated
var href = pollLink.href;
var opts = {};
if (autoPush !== undefined && autoPush !== null) {
opts.autoPush = (typeof autoPush === 'function') ? autoPush() : !!autoPush;

Choose a reason for hiding this comment

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

Good point Len, it is interesting cause it definitely has the same problem. I was just checking and when you click verify, we send rememberDevice=true, but for polling we do not send that. And if we change the checkbox, then we don't change the value either. I do not know how the backend works for rememberDevice though... maybe we can have a follow up jira for that?
pollingrememberdevice

and yes, for verify it doesn't need to be a function, but my vote goes for the consistency.

return test.trans.poll({
delay: 0,
autoPush: function () {
return true;

Choose a reason for hiding this comment

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

might be a good idea to return false in the third response just to test that it actually sends something different if the value is changed after the first poll request.

Copy link
Contributor

Choose a reason for hiding this comment

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

I second this. We should change one of the polling tests to change between requests

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

Copy link
Contributor

@lboyette-okta lboyette-okta left a comment

Choose a reason for hiding this comment

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

One test that changes the response between requests, then 🚢

@gowthamidommety-okta gowthamidommety-okta force-pushed the gd-OKTA-155565-autoPushHttpOnly branch from 5b920d3 to 23fcc94 Compare February 15, 2018 18:45
@gowthamidommety-okta
Copy link
Contributor Author

gowthamidommety-okta commented Feb 15, 2018

@lboyette-okta @mauriciocastillosilva-okta Please review again. Made changes and also added the test that changes the response between requests.
@lboyette-okta do we need to add documentation for this?

Copy link

Choose a reason for hiding this comment

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

looks good ⛵️

@lboyette-okta
Copy link
Contributor

@gowthamidommety-okta if we could add something here: https://github.com/okta/okta-auth-js#verifyoptions-1, that'd be awesome

README.md Outdated

Poll until factorResult is not WAITING. Throws AuthPollStopError if prev or cancel is called.
- `autoPush` - Send a push notification immediately the next time `verify` is called on a push factor
Copy link
Contributor

Choose a reason for hiding this comment

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

Sweet. Change this to Optional parameter to send a push notification immediately the next time verify is called on a push factor to match the others and 🚢

@gowthamidommety-okta gowthamidommety-okta force-pushed the gd-OKTA-155565-autoPushHttpOnly branch 2 times, most recently from f1d9765 to 5d64acd Compare February 15, 2018 23:51
@gowthamidommety-okta gowthamidommety-okta changed the title 🌱 Adds support for autoPush url param in poll function 🌱 Adds support for autoPush url param in poll and verify functions Feb 15, 2018
@gowthamidommety-okta gowthamidommety-okta merged commit 3d70ed9 into master Feb 16, 2018
@jmelberg-okta jmelberg-okta deleted the gd-OKTA-155565-autoPushHttpOnly branch June 15, 2018 16:08
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