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

throw :forbidden #588

Merged
merged 5 commits into from Jun 15, 2022
Merged

throw :forbidden #588

merged 5 commits into from Jun 15, 2022

Conversation

leastbad
Copy link
Contributor

Type of PR (feature, enhancement, bug fix, etc.)

Feature

Description

Introduces a new authentication primative that provides a flexible, unopinionated mechanism to disallow Reflexes from being run when the user does not have permission to do so.

Functionally, it works very similarly to using throw :abort in a before callback to halt a Reflex. Developers can use throw :forbidden and it will halt the Reflex in the same way :abort does, but instead of triggering a halted life-cycle on the client, there is now a forbidden life-cycle stage, with all corresponding callbacks and events.

As with all Reflex types, any payload values defined before the throw statement are delivered to the client. The developer can optionally use the payload to deliver information about why the Reflex was prevented from running.

This feature does not make any attempt to decide what constitutes an authentication violation; it is expected that this logic is best handled in plugins or the application itself.

Templates have been updated, and I took the opportunity to further simplify the client-side logging module.

Why should this be added

Action Cable Connections can persist longer than the current user session, which poses significant security complexity to over-the-wire applications. This is especially true given that modern use cases often see users logged in from multiple tabs and multiple devices simultaineously.

It is no longer enough to just refresh the page, as the user could logout on another tab and today, the current tab would continue running Reflexes as the logged out user. This is unacceptable.

I am preparing to release a new gem which will provide easy, Devise-like authentication checking. I would very much like an API surface to plug into to provide this functionality.

Checklist

  • My code follows the style guidelines of this project
  • Checks (StandardRB & Prettier-Standard) are passing
  • This is not a documentation update

@leastbad leastbad added enhancement New feature or request proposal ruby Pull requests that update Ruby code javascript Pull requests that update Javascript code labels Jun 11, 2022
@leastbad leastbad added this to the 3.5 milestone Jun 11, 2022
@leastbad leastbad self-assigned this Jun 11, 2022
lib/stimulus_reflex/broadcasters/broadcaster.rb Outdated Show resolved Hide resolved
lib/stimulus_reflex/callbacks.rb Show resolved Hide resolved
javascript/log.js Show resolved Hide resolved
@leastbad leastbad merged commit 019a9d2 into stimulusreflex:master Jun 15, 2022
@leastbad leastbad deleted the forbidden branch June 15, 2022 10:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request javascript Pull requests that update Javascript code proposal ruby Pull requests that update Ruby code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants