-
Notifications
You must be signed in to change notification settings - Fork 1k
feat: implement blocking web hooks #1585
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
Codecov Report
@@ Coverage Diff @@
## master #1585 +/- ##
==========================================
+ Coverage 75.29% 75.31% +0.02%
==========================================
Files 295 295
Lines 16453 16592 +139
==========================================
+ Hits 12388 12496 +108
- Misses 3118 3149 +31
Partials 947 947
Help us with your feedback. Take ten seconds to tell us how you rate us. |
Thank you for the PR! I will review it next week! |
No hurry there. I'm off next week so effectively I can resume work on this in two weeks more or less. |
Could you please enable write access for maintainers? 🤔 Thank you! 🙏 |
Alternatively, given that this is an org repo, you can also invite me as a collaborator to the fork |
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.
Thank you for the PR! This is going in the right direction :)
I have merged the conflicts (as we have changed something in the hooks) which I pushed to a separate branch and made a PR against your fork: Wikia#14
High-level this looks good. To see it in action, we will need some tests. I am in particular interested to see how the error parsing will be working in combination with the UI messages / fields.
We also need to make some decisions on how Ory Kratos detects whether a hook wants to return validation errors or not. I also think we need to rename the feature to better match what it does.
- Define a better name for the feature in the config
- Come up with a definition how a web hook could tell Ory Kratos that we have a validation error going on
- Add functional tests for web hook
- Add unit tests for the new helper structs
- Add documentation on how to return validation errors for hooks
- Add e2e test that tests this feature from start to finish
- Remove credentials from hooks
d32a43a
to
6b4c110
Compare
When I was implementing the web hooks, my extension idea was to let the response be verified in a yet another jsonet template to which, as with building of the web hook request, a couple of objects can be passed in, like the response and e.g. the actuall flow objekt. This way the protocol of the web hook is fully open and one can achieve much more compared with the implementation in this pr. |
Yes I was thinking about this but I am not sure how we would properly propagate those responses up to the UI which requires some concrete structures/data to properly handle validation errors etc. (see: https://github.com/ory/kratos/blob/master/ui/container/container.go#L152). It would be great to come up with some flexible solution that would allow to validate response using Jsonnet and transform it into something Kratos can use. For the scenarion where we have fixed data structures in Kratos and create custom payload for the webhooks Jsonnet works nicely providing the glue betwen Kratos and external services for the other way around it is a bit trickier. There must be some binding point. I will think about it more but right now I have no good solution. |
I think this can remain as is implemented by this PR. I mean the implementation right now expects a message with some text in the web hook response. Why not just letting a jennet template call a function on the passed context object, like e.g. |
If you like I can contribute some lines of code 😉 so you can directly see if it fits. |
JsonNet is not really a programming language that executes things. It's for manipulating JSON! Adding functionality like Keep in mind that regular code is much easier to program, test, and document. JsonNet is not that great when trying to test it. The less logic we have in JsonNet, the better! |
While the PR is being worked on I will mark it as a draft. That declutters our review backlog :) Once you're done with your changes and would like someone to review them, mark the PR as ready and request a review from one of the maintainers. Thank you! |
OK. I had some interruptions lately and I wasn't able to devote much time to this but hopefully I can resume work on this soon. |
No rush! Unmerged PRs give me a bit of anxiety so I tend to try to keep the backlog short 😅 |
When this is good for review, mark it as ready! |
a4ad5c4
to
035fbaf
Compare
I've just added support for maintaining form/flow data when hook returns error. Only tests to go now I think. |
58b057a
to
d7400b8
Compare
Let me know when I should take another look :) |
Thanks for the ping, I'll take a look tomorrow! |
@@ -208,6 +208,11 @@ | |||
} | |||
] | |||
}, | |||
"can_interrupt": { |
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.
What happens if we set this value and response.ignore
both to true? Should they be mutually exclusive?
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.
Will take a look.
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.
Not an JSON schema expert but I think I got this working: 98d38c7
All in all this looks very, very, very good :) I will need to try it out end-to-end, but I don't think that there will be big topics outside of: #1585 (comment) :) :) |
0ecde72
to
70be256
Compare
70be256
to
98d38c7
Compare
Sadly migration to v0.10 is being postponed a bit. Will let you know as soon as I know more. Currently we have this in backlog and planned for next sprint (~ two weeks). |
Ok, no problem :) I think the code looks good so I would be fine merging it after I do one final round of review |
…ooks # Conflicts: # test/e2e/modd.conf # test/e2e/run.sh
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.
It's perfect. Thank you!
I've made two minor changes: I removed the message
string and renamed detailed_messages
to messages
. The reason being that message
did not actually have an effect and it was a bit confusing why we need it.
The second thing was that there was a connection leak in the webhook handler as resp.Body.Close()
wasn't being called. This is fixed now :)
I've updated the docs also
Overall, great achievement!
1b95ba8
to
c602790
Compare
…tream_blocking_hooks
Thanks! |
feat: implement blocking webhooks (ory#1585) This feature allows webhooks to return validation errors in the registration and login flow from a webhook. This feature enables you to deny sign-ups from a specific domain, for example. A big thank you goes out to the team at Wikia / Fandom for implementing and contributing to this feature! Closes ory#1724 Closes ory#1483
This change allows webhooks to control the registration flow by either allowing process to continue or fail with an errors propagated to the UI (mostly validation errors at this point). This is not yet complete but the general idea is here to start any discussions and resolve concerns early.
TODO:
Closes #1724
Related issue(s)
#1483
Checklist
contributing code guidelines.
vulnerability. If this pull request addresses a security. vulnerability, I
confirm that I got green light (please contact
[email protected]) from the maintainers to push
the changes.
works.