-
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
Allow resources to auth with multiple methods #453
Allow resources to auth with multiple methods #453
Conversation
This change allows resources (e.g. User) to authenticate through multiple methods for the same real life person. Prior to this, each auth method (e.g. facebook, twitter, etc) would create a new row in User when it was used. See notes in the README that have changed for this commit for more information.
This is very interesting!! I'll review this ASAP!! |
liking option 1 as well |
Hey @lynndylanhurley, just wanted to check if you'd had a chance to look at this yet? Thanks! |
this would solve a problem for me. as it is, I guess I'll implement my own solution until this gets merged |
Any updates on this? |
@lynndylanhurley Any updates here?? |
Just an FYI for anyone coming to this - this is a fairly stale PR, and I'm not sure when/if it will get reviewed. I no longer have any projects that use devise (let alone devise_token_auth) so am not planning on doing anything with this, even if code review comes back. Mainly because as far as I know (@ram535ii can correct me on this!) I don't think this version of the code is running anywhere in production. Consequently, I would think it sensible to have a reasonably chunky change like this running in a production environment (which it was when we raised the PR) before having a merge to I'll leave it open in case it's useful for anyone (or if anyone else is happy to rebase/refactor/make review changes), but use with care as it's pretty far behind @lynndylanhurley - if you don't think this is something you want to incorporate into the gem, I have no problem with you closing this given all this. |
Wanted to reopen this PR as this specific functionality would actually be really useful to my org. @seddy obvs no pressure to keep contributing. I think I'll work on it though! Really appreciate your foundational work here. |
Closing this in favour of #990 - it's coming up in my list of open pull requests 😄 Glad to see you're carrying on the torch @zachfeldman! |
I'm trying to @seddy ! still haven't had time to finish up that PR....it's massive. Hope all is well, Happy Holidays |
TL;DR
This change allows resources (e.g. User) to authenticate through multiple methods for the same real life person. Prior to this, each auth method (e.g. facebook, twitter, etc) would create a new row in User when it was used.
Summary
It's inspired off the back of a number of issues raised around multiple authentication methods (particularly with oauth), primarily a longstanding issue #23. Within that issue there is suggestion of plans A and B, which in short are:
These are both valid ways of accomplishing this end, so we've largely followed:
We've done this by trying to avoid being opinionated about how users should implement their third party domain objects (e.g. FacebookUser or TwitterUser) and what relationship they may have to the authenticating resource.
For more information on the approach we've taken, check out the README changes we've made, specifically this section.
Core changes
There are a couple of conceptual changes worth highlighting in this PR:
1. Dropping usage of provider/uid columns when allowing multiple auth
The main issue we had with the existing implementation was the reliance on the
provider
anduid
columns which had to be added to each resource. It means that whoever uses the gem must model their third party model implementations around these columns in order to have omniauth. It also had the consequence of real life users potentially ending up with multiple rows in theusers
table, which wasn't something we wanted to allow in our system.2. Restructuring the uid field in the http header
The main thing which we'd like opinions on is the change to the
uid
field. In the previous implementation, when we callset_user_by_token
, we would:uid
out of the http headeruid
in the resource table to get the row to authenticate.We wouldn't need to worry about what
provider
they originally signed in with (e.g. facebook, twitter, email, etc). However, in order to give developers freedom to decide how they model their third party domain objects (and therefore how they are associated to the resource) we need theprovider
field.So the big question is how do we pass around the
provider
field between requests? As we see it, there are three options:provider
field to the http token headersprovider
to the existinguid
value in the http token headersuid
value in the http token to being the resource'sid
.A quick table of (what we think) the pros and cons are:
resource_finder_for
lambdas are problematicuid
field remains unchanged, so it's actually auid
uid
fieldresource_finder_for
lambdas are problematicuid
in client systemsresource_finder_for
implementatoinsid
fields, which may not be desirableWe've implemented option 2, but aren't particularly set on it. The primary reason was a concern about being backwards compatible and not adding more fields to the http header, as there are already quite a few of them.
Ultimately though, we're leaning towards option 1 now that we've finished the implementation, so input here would be much appreciated!