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

Fix converter getting called twice if using an authenticator with a JsonConverter on the request #324

Merged
merged 4 commits into from Jan 30, 2022

Conversation

maxroehrl
Copy link
Contributor

@maxroehrl maxroehrl commented Jan 17, 2022

Fix _handleRequestConverter getting called twice if using an authenticator with a JsonConverter on the request.

Otherwise an already encoded body string in req.body will be encoded again after the authentication challenge was solved.

So in the end in this MR we call send() with the same arguments as the initial request which fails with 403 as the token is outdated.

This behaviour was last changed in #310 to fix #308.

@JEuler
Copy link
Collaborator

JEuler commented Jan 18, 2022

But it will return the #308 error, as I understand

@maxroehrl
Copy link
Contributor Author

maxroehrl commented Jan 18, 2022

Another solution would be that we add the original/not converted request as a new parameter to authenticate().

So in my own code I can return the right request and the bug in #308 is not reintroduced.

@JEuler
Copy link
Collaborator

JEuler commented Jan 20, 2022

Whoops, @maxroehrl could you please dart format the code in Changed lib/src/authenticator.dart? :)

@maxroehrl
Copy link
Contributor Author

@JEuler I have formatted the file.

@JEuler
Copy link
Collaborator

JEuler commented Jan 21, 2022

@stewemetal Hi! I think it is okay, just one more param to allow customization. What do you think?

@stewemetal
Copy link
Collaborator

stewemetal commented Jan 21, 2022

It's OK in terms of solving the issue, but it's kind of not OK as this would be a breaking change on the public interface of the lib.

Whoever uses authenticate already will get a missing param error after upgrading to the latest version.

I'll try to come up with something for this today evening, that would break compatibility gracefully, or not at all.

However, this would definitely mean a minor version update either way as this is a breaking change, and it needs to be documented at least in the update note.

@JEuler
Copy link
Collaborator

JEuler commented Jan 21, 2022

Maybe we can go with optional then? :)

@JEuler
Copy link
Collaborator

JEuler commented Jan 21, 2022

Whoops, I misunderstood the problem. :) But anyway, it is a light change for client code, so, maybe it is not very BIG. Thank you!

@JEuler
Copy link
Collaborator

JEuler commented Jan 27, 2022

@stewemetal Hi! Any news? :)

@stewemetal
Copy link
Collaborator

Yeah, we can go on with having it as optional I guess. :)

@JEuler
Copy link
Collaborator

JEuler commented Jan 30, 2022

The option will also break the interface (meaning, the client will need to update the signature in his Auth class). But maybe it is okay. :)

@JEuler
Copy link
Collaborator

JEuler commented Jan 30, 2022

@maxroehrl Could you please make this param optional? Like [Request? originalRequest]

@maxroehrl
Copy link
Contributor Author

Yes, the users will still need to update their method signature, but I see no way to prevent this.

@JEuler
Copy link
Collaborator

JEuler commented Jan 30, 2022

Yeah, I think it is okay. Sorry for the delay, a hard-working week. I will merge it and create new PR with version update : )

@JEuler
Copy link
Collaborator

JEuler commented Jan 30, 2022

And we are passing the original request inside so the optional is nothing here... but anyway, let's go :)

@JEuler JEuler merged commit 4185d14 into lejard-h:develop Jan 30, 2022
@flodaniel
Copy link

I just updated the package and worked around the bug, this PR is solving.
@JEuler is it correct that the new property originalRequest can never be optional? Why make it optional then?

@JEuler
Copy link
Collaborator

JEuler commented Feb 8, 2022

Correct, as I told it in "And we are passing the original request inside so the optional is nothing here... but anyway, let's go :)"
Will fix this glitch later, not important.

@flodaniel
Copy link

Sorry about that, I was not quite sure about the phrase - english is not my primary language :)

Awesome! Thanks to everyone here - this allows me to remove my dirty fix 👍

@JEuler
Copy link
Collaborator

JEuler commented Feb 8, 2022

Thank you! Hooray! 🎉

JEuler pushed a commit that referenced this pull request Oct 8, 2022
JEuler added a commit that referenced this pull request Oct 15, 2022
* Fix Header Option Casting (#260)

Co-authored-by: Ivan Terekhin <i.terhin@gmail.com>

* Fix for #259 (#263)

* 4.0.1 fixes (#264)

* analyzer dependency upgraded (#296)

* fix(generator): fix PartValueFile value not nullable if arg is (#288) (#293)

* Chopper generator release 4.0.2 (#297)

* fix: fix this.body cast of null value when response body is null (#291) (#292)

* Interpolation fixes (#275)

* encodeQueryComponent now encodeComponent (#278)

* Prevent double call on token refreshment (#276)

* Fixes for #309 #308 (#310)

* Remove new keyword from interceptors.md (#312)

* Analyzer upgrade (#320)

Co-authored-by: István Juhos <stewemetal@gmail.com>

* Add unnecessary_brace_in_string_interps to lint ignores (#317)

* Extend pragma to quiet the linter (#318)

Co-authored-by: Ivan Terekhin <i.terhin@gmail.com>

* Fix converter getting called twice if using an authenticator with a JsonConverter on the request (#324)

* migrate example to nullsafety (#331)

* Resolve problem in main_json_serializable example (#328)

* Add @FiledMap @PartMap @PartFileMap (#335)

Co-authored-by: Meysam Karimi <mysmartapply.it4@gmail.com>

* Upgrade of analyzer (#340)

* Fix nullable QueryMap fails to compile (#344)

* Change return type of decodeJson to FutureOr in order to be able to support compute() (#345)

* Migrate from pedantic to lints ^2.0.0 with lints/recommended.yaml (#349)

* Version bumped for release (#352)

* Revert analyzer to ^4.1.0 and silence linters for Element.enclosingElement (#354)

* [chopper_generator] Update analyzer to ^4.4.0 and code_builde to ^4.3.0 and migrate deprecated code (#358)

* Add Makefiles to streamline development (#357)

* Add Bug Report Github issue template (#359)

* [chopper_generator] Add types to the generated variables (#360)

* Provide an example using an Isolate Worker Pool with Squadron (#361)

* mapToQuery changes (#364)

* Version bumped / changelog update (#367)

* Request extends http.BaseRequest (#370)

* Exclude null query vars by default and add new @method annotation includeNullQueryVars (#372)

* 5.1.0 (dev) (#373)

Co-authored-by: Ivan Terekhin <231950+JEuler@users.noreply.github.com>

Co-authored-by: Youssef Raafat <youssefraafatnasry@gmail.com>
Co-authored-by: luis901101 <luis901101@gmail.com>
Co-authored-by: melvspace <ratealt@gmail.com>
Co-authored-by: Michal Šrůtek <35694712+michalsrutek@users.noreply.github.com>
Co-authored-by: István Juhos <stewemetal@gmail.com>
Co-authored-by: Andre <andre.lipke@gmail.com>
Co-authored-by: John Wimer <john@wimer.org>
Co-authored-by: Max Röhrl <max.roehrl11@gmail.com>
Co-authored-by: ipcjs <gipcjs@gmail.com>
Co-authored-by: ibadin <exbatek@gmail.com>
Co-authored-by: Meysam Karimi <31154534+meysam1717@users.noreply.github.com>
Co-authored-by: Meysam Karimi <mysmartapply.it4@gmail.com>
Co-authored-by: Klemen Tusar <techouse@gmail.com>
Co-authored-by: Klemen Tusar <k.tusar@cmcmarkets.com>
Co-authored-by: Ivan Terekhin <231950+JEuler@users.noreply.github.com>
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.

Wrong Request instance is passed to Authenticator.authenticate method
4 participants