Optional subdomain aware redirects and scope based cookie names #157
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hello,
I was using your gem for a long while and I liked it a lot. However, it did not quite work with me well where I was having two user scopes and different subdomains.
In my scenario AdminUser should have been available on "system.example.com" subdomain and User should have been on "portal.example.com", "blog.example.com", "docs.example.com" and "example.com" itself.
I separated session cookie store so that there were two different cookies created for these separations: _core_session and _admin_session
Problem with this gem #1 was that it was creating single "remember_tfa" cookie that arose problems with other scopes.
Problem #2 was that if I logged-in in system.example.com as AdminUser and I was prompted 2FA, if I would not enter anything in the box and manually head to portal.example.com or docs.example com I would be force-redirected back to system.example.com (try 'remember me' from devise) and this was very disturbing.
Feel free to reject this pull-request, or perhaps introduce a better solution but for me this was handy.
USAGE
Your devise models can now have an optional class method two_factor_subdomains, which should return a regex. For example, if you would like User to operate on all subdomains except "system" you would have
This means that when you'll login at User's portal.example.com login page w/ remember me on, will be prompted 2FA code, don't enter it, go to system.example.com you won't be redirected back to portal.example.com 2FA prompt page.
I would really appreciate if you could introduce your version of this PR.
Note: I've added couple of specs for this, but some of them from master were failing before I've added any code.
Thanks,
Dachi