Issue
There seems to be a need to associate existing Drupal accounts with new connector logins. For instance, if you have allowed your website to run for awhile with one oauthconnector option (i.e. Google), and you want to add another option (i.e. Facebook), then people who switch over from using Google to now using Facebook will get a new Drupal account. The desire is to have the new connector associate with same account as we originally created with the first connector. This custom module solution offers a way around that.
Current Logic
If _connector_log_in() does not successfully do a user_external_load() (through an entry in authmap), then _connector_create_account() will create a new account. During the account creation, if there is already a Drupal user with the same name and/or email field values received from the sync, then that piece of information is left out of the new account being created. Subsequently, you have two accounts for the same user, but only the first one has all the information needed (e.g. the second account might have a blank email address).
Proposed Logic
The hook_oauth_common_authorized() offers you a chance to create this association before _connector_log_in() and _connector_create_account() get called. So in your custom module:
- If the authname is not found in authmap, then:
- check for existing users with same name and/or email
- if found, then:
- _connector_add_connection to authmap
- oauthconnector_oauth_common_authorized() will be responsible for logging the user in with the new connection
- see attached file for example
Comment | File | Size | Author |
---|
Comments
Comment #1
dxx CreditAttribution: dxx commentedVery good, why do not include this feature (need UI switch for activate/deactivate) into the module project... or as separate module?
Comment #2
pianomansam CreditAttribution: pianomansam commentedThe code from switchstar was used at the inspiration for a new module that creates an email field and links existing accounts through their email address (https://www.drupal.org/project/oauth_connector_email).
Comment #3
pianomansam CreditAttribution: pianomansam commentedClosing in favor of the original issue #1010264: Need a way to associate to an existing account