-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Allow built-in token middleware to run repeatedly #2108
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
Conversation
|
Can one of the admins verify this patch? To accept patch and trigger a build add comment ".ok\W+to\W+test." |
|
@slnode ok to test |
|
@benkroeger thank you for the pull request. The code changes look reasonable, I appreciate you included a unit-test too! I have one concern though.
I think our original assumption was that all instances of the token middleware use the same auth method and if the first instance of the token middleware does find any valid credentials, then the second and all subsequent instances will not find any valid credentials either, and thus we can skip them to improve performance. Now your use case is different and our assumption no longer holds. Can we find a way how to support both cases? For example, what if we added a configuration option for the /cc @raymondfeng @ritch thoughts? |
|
@bajtos sure, making this a middleware prop shouldn't be a problem. suggestions on the naming? how 'bout |
|
now that I think about it - I actually don't want a subsequent instance to overwrite any existing |
As suggested by @bajtos, token middleware now as new options for loading multiple instances: * @Property {Boolean} [enableDoublecheck] Execute middleware although an instance mounted earlier in the chain didn't find a token * @Property {Boolean} [overwriteExistingToken] only has effect in combination with `enableDoublecheck`. If truthy, will allow to overwrite an existing accessToken.
Sure, that makes sense to me as well. I am thinking about the following rule: As for the option name, now about |
|
I've implemented a two-step decision now: It checks for |
|
@slnode test please! |
|
Can one of the admins verify this patch? To accept patch and trigger a build add comment ".ok\W+to\W+test." |
|
ok to test |
|
Since there hasn't been any updates on this issue from the maintainers, I thought it might be because the tests on travis fail. Judging from the indications, it looks like "grunt" does not get installed correctly during the tests for Node.js 5.0. All of them state "grunt: command not found". Thoughts? Any chance we can get this PR moving again? |
|
@rmg should your latest CI fix have resolved this?
Node 5 is failing on all platforms. |
|
The Node 5 failure looks like it happened before I removed shelljs from the cache (which was the source of the source of the problem when installing deps with npm3). The current failure on node-0.12 on Windows looks like a run of the mill flaky test. |
|
looks like now tests are failing that previously were successful - without further commits / code change. npm-debug.log says something about failing to install phantom.js |
|
r u guys adding more and more tests? What's about all the dependant tests? Didn't see those in other PRs. And the ones I looked at are failing due to timeout reasons (e.g. dependant strong-arc after > 5 mins). |
|
@benkroeger, we have always checked the dependants to make sure that nothing is broken down stream. I believe that the only two dependants that failed that we need to worry about are the angular sdk and the angular live-set. @bajtos PTAL. Are we still having issues with CI? |
test/access-token.test.js
Outdated
| // the middleware should load the token from | ||
| .expect(401) | ||
| .end(done); | ||
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like pure spacing/formatting change to me, unrelated to the changes made in this patch. Could you please revert?
include all valid (non-private) properties in the test
|
@benkroeger please let me know when this patch is ready for another round of review. Note that github does not send any notifications when you add a commit, one has to leave a comment for that (ideally including the GH handle of the reviewer). |
|
alright @bajtos this PR is ready for another review. I reverted the |
|
@slnode test please |
prevents "can not read property id of null"
Allow built-in token middleware to run repeatedly
|
Landed via a9c7801, thank you @benkroeger for your contribution and the patience with us :) |
|
Finally! 🎉 Agreed, thanks a lot @benkroeger, awesome job! |
|
Woohoo! |
|
forget my previous comment. it's in a9c7801 |
|
@benkroeger ouch! Could you please add a unit-test to a9c7801 that demonstrates/reproduces the bug in the current implementation and send a new PR? Please mention my GH handle in the PR description, I'll get it landed ASAP. |
subsequent token middleware tries to read `token.id` when `enableDoublecheck: true`. That caused a "Cannot read property `id` of `null`" error when the first middleware didn't actually find a valid accessToken.
Subsequent token middleware tries to read `token.id` when `enableDoublecheck: true`. That caused a "Cannot read property `id` of `null`" error when the first middleware didn't actually find a valid accessToken. [back-port of #2227]
* add missing unit tests for #2108 (Benjamin Kroeger) * Expose `Replace*` methods (Amir Jafarian) * Update tests for strong-error-handler (David Cheung) * Remove legacy express 3.x middleware getters (Miroslav Bajtoš) * Docuemtation for `replace*` methods (Amir Jafarian) * Make the doc clear for `findORCreate` cb (Amir Jafarian) * Fix JSCS unsupported rule error (Jason) * Remove env.json and strong-pm dir (Ritchie Martori) * Throw error upon extending unknown model (David Cheung) * Remove unused UserModel properties (David Cheung) * Remove Change.handleError (Candy) * Update user.js (Rik) * Separate error-checking and next/done logic from other logic in the test suite (Supasate Choochaisri) * Clean up by removing unnecessary comments (Supasate Choochaisri) * Add feature to not allow duplicate role name (Supasate Choochaisri) * update copyright statements (Ryan Graham) * relicense as MIT only (Ryan Graham) * Upgrade phantomjs to 2.x (Miroslav Bajtoš) * app: send port:0 instead of port:undefined (Miroslav Bajtoš) * travis: drop node@5, add node@6 (Miroslav Bajtoš) * Disable DEBUG output for eslint on Jenkins CI (Miroslav Bajtoš) * Remove "loopback.autoAttach()" (Miroslav Bajtoš) * test/rest.middleware: use local registry (Miroslav Bajtoš) * Fix role.isOwner to support app-local registry (Miroslav Bajtoš) * test/user: use local registry (Miroslav Bajtoš) * Resolver support return promise (juehou) * remove @Private from jsdoc (Manu Phatak) * Fixes for emit `remoteMethodDisabled` PR (Simon Ho) * Add new feature to emit a `remoteMethodDisabled` event when disabling a remote method. (Supasate Choochaisri) * Fix typo in Model.nestRemoting (Tim Needham) * Update loopback.js (Rand McKinney) * Allow built-in token middleware to run repeatedly (Benjamin Kröger) * Use eslint with loopback config (Miroslav Bajtoš) * promise docs (Jue Hou) * Update JSDoc ([email protected]) * Remove constraint making isStatic required (Candy) * Fix inconsistencies in JSDoc ([email protected]) * Improve error message on connector init error (Miroslav Bajtoš) * application: correct spelling of "cannont" (Sam Roberts) * Remove sl-blip from dependency (Candy) * Use new strong-remoting API (Candy) * test: remove forgotten console.trace logs (Miroslav Bajtoš) * Fix race condition in replication tests (Miroslav Bajtoš) * Fix race condition in error handler test (Miroslav Bajtoš) * test: remove errant console.log from test (Ryan Graham) * Promisify Model Change (Jue Hou) * Travis: drop iojs, add v4.x and v5.x (Miroslav Bajtoš) * test: use ephemeral port for e2e server (Ryan Graham) * test: fail on error instead of crash (Ryan Graham) * ensure app is booted before integration tests (Ryan Graham) * Remove "loopback.DataModel" (Miroslav Bajtoš) * Correct JSDoc findOrCreate() callback in PersistedModel (Chris Coggburn) * Fix typo in package.json (publishConfig) (Miroslav Bajtoš) * Start development of 3.0 (Candy) * Hide verificationToken (Samuel Gaus) * Fix description for User.prototype.hasPassword (Jue Hou) * Checkpoint speedup (Amir Jafarian) * Always use bluebird as promise library Replace `global.Promise` with `bluebird` (Jue Hou) * Remove unused code from loopback-testing-helper (Simon Ho) * Make juggler a regular dependency (Miroslav Bajtoš) * Remove dependency on loopback-testing (Simon Ho) * Fix failing tests (Simon Ho) * Update persisted-model.js (Rand McKinney) * Update persisted-model.js (linguofeng)
Add two new options:
enableDoublecheckis true, the middleware will runeven if a previous middleware has already set
req.accessToken(possibly to
nullfor anonymous requests)overwriteExistingTokenis true (andenableDoublechecktoo),the middleware will overwrite
req.accessTokenset by a previousmiddleware instances.
fixes #2106
For details, please see issue description #2106
@richardpringle