-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Call before/after_successful_authorization callbacks on create as well as new #1075
Call before/after_successful_authorization callbacks on create as well as new #1075
Conversation
So the callback will be invoked twice? Looks strange from my point of view... Moreover, maybe it will be better to move the hooks under the Authorization class instead of controller? It will DRY the code at least |
+1. I would rather rename callback in
As I mentioned in previous PR, we need controller's scope in that callback (i.e. for interacting with cookies/sessions). |
We can use existing callbacks, but add an extra argument - action ('new' or 'create'). Controller ais already passed with the context argument, so you already has an access to cookies or request. |
I think the
The duplicated code (before + authorize + after) could easily be extracted into a new method, perhaps into I looked at moving the hooks into the request objects like the before/after_successful_response hooks in |
9e76d9e
to
68165b5
Compare
I've rebased onto master and extracted some of the duplicated code. Now the callbacks are closer to the Authorization class and I think the intent is clearer: that the callbacks are invoked when the request is successfully authorized. |
@@ -84,7 +80,13 @@ def strategy | |||
end | |||
|
|||
def authorize_response | |||
@authorize_response ||= strategy.authorize | |||
@authorize_response ||= begin | |||
valid = pre_auth.authorizable? |
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.
Let's rename it to authorizable
to be closer to implementation and the essentials of this method. What do you think?
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.
Good call -- I'll change it.
Look better now. Don't forget to add a changelog entry to NEWS.md and squash the commits :) Thanks! |
68165b5
to
dd42847
Compare
OK, I renamed the variable, added a changelog entry, and squashed/rebased. |
Got it, thank you for your work! 👍 |
Summary
The before/after_successful_authorization callbacks added in #1064 are only called on the
new
action. I think they should also be called oncreate
to cover situations where the user must explicitly authorize the client.Other Information
I also found that the callbacks can be run when authorization is not successful. I added some more tests and modified the existing code a bit.
This PR has some conflicts with my other PR, #1072. I'll resolve them but wanted to put this up for review.
cc @nattfodd