Issue
The Drupal 7 branch of Connector does not sync most user fields, neither on account creation or login. The administrative user interface leads one to believe this possible, but it simply isn't.
Cause
The _connector_create_account() or _connector_log_in() functions didn't assign values other than name and mail.
Solution
Provided patch does the following:
- Creates a new _connector_store_account_values() internal function and implements it in _connector_create_account() and _connector_log_in()
- Creates hook_connector_user_info_alter() which let's you alter the incoming info. I then used this to handle the avatar situation.
- Creates hook_connector_field_value_handler_FIELDNAME() can save each field.
- Saves a temporary picture file for the avatar field, which will be permanently saved by user.module
Original Issue
After successfully creating and/or connecting an account with Google or Facebook there's no data imported to the user profile. Here is the exported code of my Google connector:
$provider = new stdClass();
$provider->disabled = FALSE; /* Edit this to true to make a default provider disabled initially */
$provider->name = 'google';
$provider->title = 'Google';
$provider->url = 'https://accounts.google.com';
$provider->consumer_advanced = array(
'oauth2' => 1,
'signature method' => 'HMAC-SHA1',
'authentication realm' => 'authorization_code',
'request token endpoint' => 'none',
'authorization scope' => 'https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email',
'authorization endpoint' => '/o/oauth2/auth',
'access token endpoint' => '/o/oauth2/token',
);
$provider->mapping = array(
'fields' => array(
'uid' => array(
'resource' => 'https://www.googleapis.com/oauth2/v1/userinfo',
'method post' => 0,
'field' => 'id',
'querypath' => FALSE,
'sync_with_field' => '',
),
'email' => array(
'resource' => 'https://www.googleapis.com/oauth2/v1/userinfo',
'method post' => 0,
'field' => 'email',
'querypath' => FALSE,
'sync_with_field' => 'mail',
),
'name' => array(
'resource' => 'https://www.googleapis.com/oauth2/v1/userinfo',
'method post' => 0,
'field' => 'name',
'querypath' => FALSE,
'sync_with_field' => 'name',
),
'avatar' => array(
'resource' => 'https://www.googleapis.com/oauth2/v1/userinfo',
'method post' => 0,
'field' => 'picture',
'querypath' => FALSE,
'sync_with_field' => 'picture',
),
),
'format' => 'json',
);
Additionally I get these errors when saving a new connector:
Notice: Undefined property: stdClass::$csid in oauthconnector_provider_save() (line 461 of /home/s080feb3/public_html/d7/sites/default/modules/oauthconnector/oauthconnector.module).
Notice: Undefined property: stdClass::$csid in oauthconnector_provider_save() (line 462 of /home/s080feb3/public_html/d7/sites/default/modules/oauthconnector/oauthconnector.module).
Great module by the way, just need it to work!
Comment | File | Size | Author |
---|---|---|---|
#36 | 1503258-36-connector-no-user-data-imported.patch | 6.72 KB | alexverb |
#32 | 1503258-24-connector-no-user-data-imported.patch | 6.76 KB | pianomansam |
#10 | connector-import-profile-fields-1503258-10.patch | 1.32 KB | remydenton |
Comments
Comment #1
nonozz CreditAttribution: nonozz commentedComment #2
nonozz CreditAttribution: nonozz commentedComment #3
Frans CreditAttribution: Frans commentedWhat data do you mean?
The mapping of the fields is a pain in the ...
Basic fields as email and username should work.
Comment #4
nonozz CreditAttribution: nonozz commentedI'm afraid I'm talking about that pain in that place.. none of the mapped fields gets filled after connecting/creating an account, guess it's related to that 'Notice: Undefined property'
Comment #5
Frans CreditAttribution: Frans commentedDoes 'sync local profile with PROVIDERNAME' do something on:
user/1/connections ?
If not, did you map fields on the aouthconnector provider config?
'Field to match on user profile'
Comment #6
nonozz CreditAttribution: nonozz commentedYes and yes, connected accounts does appear on the user profile tab and I have mapped the fields in the config.. even tried different combinations of default and custom fields but didn't get any data.
I'm running Drupal 7.12 minimal profile install with the necessary modules only.
Comment #7
Frans CreditAttribution: Frans commentedcan you export the provider and dump it here?
admin/structure/oauthconnector
Also like to know what kind of fields (text, username...) you are trying to fill.
Comment #8
nonozz CreditAttribution: nonozz commentedI've tried mapping with the preset's default fields and also with just a custom text field mapped to the username, no succeed. When creating a new account the resulting profile is empty, no email, no picture, nothing in the custom field, nothing at all but the username which is something like 'oauthconnector_google__10533...'
Here is the exported provider:
Comment #9
Frans CreditAttribution: Frans commentedI did some work on the mapping of the fields.
This is a connector thingie and not a oauth connector thingie.
The default action now maps email and name to the right fields on first login. Please read carefully... it only maps mail and name and only on first login .
So... it does not do anything with avatar or other fields (yet).
The functionality 'sync local profile with PROVIDERNAME' does also a better job now. Normal text fields are all mapped now, images and other fields not.
What now... or how to solve...
When writing patches, please also see and try to team up:
#1450664: Prefill user form patch
#1481574: Integration with feeds
Comment #10
remydenton CreditAttribution: remydenton commentedThis patch adds additional fields on account creation (it uses entity metadata wrappers, which means it should work for most user profile entity fields but also requires the entity api module).
It definitely needs some more work and this may not even be the right approach, but I needed a solution for this and thought I'd share what I had in case it helps with progress.
Comment #11
mauriziopinotti CreditAttribution: mauriziopinotti commentedThanks remydenton for your patch, following yout work I've added support for importing link fields and address fields.
Please note that this requires patch #10 to work:
Comment #12
Deciphered CreditAttribution: Deciphered commentedAnother patch along the same lines, except this one actually makes Entity a dependency.
I've turned the
$allowed_fields
into$unique_fields
so it will still check if the username or email address is already in use, but otherwise all other fields will be inserted as per the EntityMetaDataWrapper.Might need some additional checks to make sure every type of field is being attached correctly, but definitely not with such specific checking as per #11.
Comment #13
Deciphered CreditAttribution: Deciphered commentedMinor fix, last minute optimisation accidentally broke the unique_fields stuff.
Comment #14
Yorgg CreditAttribution: Yorgg commentedWhy are you guys looking at 7.x-1.0-beta1?
I can't even find that version to test the patch.
Just thought that new patches would apply on the latest versions.
Comment #15
Deciphered CreditAttribution: Deciphered commentedWe're no (well, I'm not), I just didn't update the issue version.
Comment #16
johnnyfofo CreditAttribution: johnnyfofo commented#13 works fine, would love to see this committed!
Comment #17
d0tcom CreditAttribution: d0tcom commented#13 works great when using the Google+ scopes! (It took me a while to finally get the correct combination that will fetch information from Google)
Unfortunately I am still unable to map the avatar field..
I'm using https://www.googleapis.com/auth/plus.login https://www.googleapis.com/auth/plus.me for the scope.
I'm using https://www.googleapis.com/plus/v1/people/me as the resource URL and image.url for the Avatar field.
I am able to fetch the URL if I map the image.url field to a regular text field in Drupal but it doesn't work for the Drupal Picture field.
Comment #18
ram4nd CreditAttribution: ram4nd commented#13 seems to work
What about auto-sync?
Comment #19
ram4nd CreditAttribution: ram4nd commentedThis patch syncs data when logging in.
Comment #20
heshanlk(Only for beta2)
This patch fixed the issue with no image import when login and sync. There are two ways to map the avatar.
The both scenarios worked fine in this path.
Thanks
Comment #21
heshanlkSame patch for as in #20. Re-rolled against dev branch.
Comment #22
pianomansam CreditAttribution: pianomansam commentedI'm providing a new patch and updating the issue summary to explain exactly what the issue is. This new patch takes many of the solutions strung across all the previous patches, improves upon them, sometimes fixing them, and putting them in a single patch. Since the work here introduced the entity module as a requirement, I continued to use it even expanded upon its use. Using entity_metadata_wrapper() should work for many fields on users, but there are several properties that it cannot be used for yet #2224645: EntityMetadataWrapper missing "picture", "timezone" & "signature" properties for user entity. So this patch allows values to be stored in an $edit variable as well as the entity wrapper.
This patch also introduces the hook_connector_field_value() hook as a DRY method of validating and setting values. This is used for both user creation and login. There is a default implementation included that provides handling of the avatar field since so many comments and patches were regarding that. This default hook can be expanded to handle other field types like the code suggested by twist3r in #11, or other implementation of it in another module.
Regarding handling the avatar field, I greatly simplified and improved the code given heshan.lk in #20 and #21. Those patches were trying to do too much that was already handled in user.module, assumed the incoming image was JPG, and in the case of #21, gave show-stopping errors because they were trying to create a managed file using the uid when the user hadn't been saved yet.
Comment #23
tr33m4n CreditAttribution: tr33m4n commentedHello there,
Applied your patch to the latest dev however hunk #1 failed (adding "dependencies[] = entity" to the info file). Easy fix though
Cheers
Comment #24
pianomansam CreditAttribution: pianomansam commentedtr33m4n, I'm not sure why the patch gave you an error. I tried both
patch -p1 < 1503258-22-connector-no-user-data-imported.patch
andgit apply 1503258-22-connector-no-user-data-imported.patch
and they both worked fine. Anyways, I'm updating the patch because I wasn't satisfied with how values were being stored to the user account. Since this is using a hook, there is no way for each hook implementation to know if the value had been saved already or not. And I also didn't like how the hook combined both modifying the value and saving the value. So I've split the hook up into two hooks now:A few words on hook_connector_field_value_handler_FIELDNAME(). When called, this hook doesn't have to save something to the user. It can do additional validation or anything else. However, if it is implemented and doesn't save something to the user, it must set
$field['stored'] = FALSE
otherwise the default mapping handler will assume it really did save something.Also, I did consider removing the new entity module requirement and trying to do everything without it. This would have been possible except the entity module really makes working with fields on user objects a lot easier. So I left it in.
Comment #25
tr33m4n CreditAttribution: tr33m4n commented@pianomansam Just tried with your latest patch and still get the same hunk issue. I did the following:
Which resulted in:
Comment #26
pianomansam CreditAttribution: pianomansam commented@tr33m4n I think I see the issue. I created my patch against the git checkout, which differs slightly since the packaged version adds a few lines of to info file.
Comment #27
tr33m4n CreditAttribution: tr33m4n commentedFair enough, I was thinking that was the case
Comment #28
tr33m4n CreditAttribution: tr33m4n commentedI'd imagine for such a major patch maybe build against dev to just avoid future people having similar problems
Comment #29
loool CreditAttribution: loool commentedHi Guys,
any news about this patch? I applied it, all fields now are populated except for the avatar picture .. is the same for you?
Comment #30
pianomansam CreditAttribution: pianomansam commented@lool, what kind of field is your avatar picture mapped to? The builtin profile field or a true image field?
Comment #31
arthur_drupal CreditAttribution: arthur_drupal commentedHi pianomansam,
I am trying your patch,
The $picture_file variable is not initialised (function connector_connector_field_value_handler_avatar)
Comment #32
pianomansam CreditAttribution: pianomansam commented@arthur_drupal, thank you for that find. It was an artifact of my prior code refactoring. Here's an updated patch that should fix that.
Comment #33
judahtanthony CreditAttribution: judahtanthony commentedWhat is the progress on this?
After struggling a bit to get LinkedIn authentication set up (the existing system doesn't use the "state" CSRF token and the "Authorization: Bearer ..." header). I finally got it to login/create a user, but the user profile fields weren't pulled down.
Is this fixed in beta? ... in dev? ... in dev with "1503258-24-connector-no-user-data-imported.patch" applies?
Comment #34
ram4nd CreditAttribution: ram4nd as a volunteer commentedThe status is needs review, so asking what is the status is kind of obsolete. You are welcome to contribute, by trying this patch, etc...
Comment #35
pianomansam CreditAttribution: pianomansam commented@judahtanthony, the status is that the latest patch (#24) needs to be tested by more people to see if it indeed fixes the problem. So go ahead and apply it to dev and see if it works for you, then report back and let us know.
Comment #36
alexverb CreditAttribution: alexverb commentedI wasn't able to patch because there were new lines in the patch. For people who also couldn't patch it, I've re-written it. Try this one.