1

I'm using Drupal 7.5x and the HybridAuth Social Login module.

I am aware a lot of users have done this using Rules and Rules Event HybridAuth login, combined with Set a data value. However no one explains what comes after, it seems the Hybridauth tokens are either not editable or just invalid.

So I am using the the Rules Event User logged in through HybridAuth, and I want to set a data value. Here is an export of the rule I have so far:

{ "rules_updateinfo" : {
    "LABEL" : "updateinfo",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "TAGS" : [ "login" ],
    "REQUIRES" : [ "hybridauth" ],
    "ON" : { "hybridauth_user_login" : [] },
    "DO" : []
  }
}

I want to update the token user:hybridauth:profileURL with the new data provided by the API (= hybridauth:profileURL). However when trying to input any of these tokens into the data selector, either of the following errors show up:

  • If I use Data selector: hybridauth:profileURL, the error is:

    "The selected data property doesn't support writing."

  • If I use Data selector: user:hybridauth:profileURL, the error is:

    "Data selector user:hybridauth:profileURL for parameter data is invalid."

I'm sure I'm doing something wrong, can someone help me to get such rule to work? Is it even possible?

  • It's not drupal 5, I'm using 7.5 I'm editing the first post to show the export – Kfg Nov 30 '16 at 17:16
  • OK, much better! Please review the extra edit of your question I just did, mostly to improve its formatting and to add some module links (and use correct module names ...). Feel free to further edit if you want, or just rollback if you don't like my edit at all, ok? PS: I bet you mean 7.5x (x=0,1 or 2) ... Hopefully not just 7.5 anymore ... – Pierre.Vriens Nov 30 '16 at 17:41
  • Yeah, I meant 7.5x, the edit looks good to me, thank you. – Kfg Nov 30 '16 at 17:51
0

Some more details about the errors you encountered:

With that, I'm fairly sure that the answer to the "Is it even possible"-part of your question is:

I'm afraid it is NOT ... Though I'd love to see anybody tell me I'm wrong.

  • user:hybridauth:profileURL does exist (you can see it in Devel) but isn't shown on Rules, which is why it says it's invalid, I think. hybridauth:profileURL is another token, and this one does show up in Rules, but it doesn't support writing I know there must be a way to do this, I've read of users doing it and even the module author himself says it can be done, but I can't find how. – Kfg Dec 1 '16 at 17:08
0

I'm going to answer myself here

Want to update the token [user:name] based on [hybridauth:displayName]? Here's the rule:

{ "rules_updateusername" : {
"LABEL" : "UpdateUserNameOnHybridAuthLogin",
"PLUGIN" : "reaction rule",
"ACTIVE" : false,
"OWNER" : "rules",
"TAGS" : [ "userupdate" ],
"REQUIRES" : [ "rules", "hybridauth" ],
"ON" : { "hybridauth_user_login" : [] },
"DO" : [
  { "data_set" : {
      "data" : [ "site:current-user:name" ],
      "value" : [ "hybridauth:displayName" ]
    }
  }
]

} }

Want to update the token [user:picture:url] using [hybridauth:photoURL]? You need to enable the core PHP Filter module, Here's the rule:

{ "rules_updateprofilepic" : {
"LABEL" : "UpdateUserPicture",
"PLUGIN" : "reaction rule",
"OWNER" : "rules",
"TAGS" : [ "userupdate" ],
"REQUIRES" : [ "rules", "hybridauth", "php" ],
"ON" : { "hybridauth_user_login" : [] },
"DO" : [
  { "hybridauth_url_managed_file" : {
      "USING" : { "url" : "[hybridauth:photoURL]", "directory" : "pictures" },
      "PROVIDE" : { "file" : { "pic" : "Managed file entity" } }
    }
  },
  { "php_eval" : { "code" : "global $user;\r\n$file = $pic;\r\n$user-\u003Epicture = file_load($file-\u003Efid);\r\nuser_save($user);" } }
]

} }

Want to update the token [user:hybridauth:profileURL] based on [hybridauth:profileURL]? You need to enable the core PHP Filter module, Here's the rule:

{ "rules_updateprofilelink" : {
"LABEL" : "UpdateProfileLink",
"PLUGIN" : "reaction rule",
"WEIGHT" : "1",
"OWNER" : "rules",
"TAGS" : [ "userupdate" ],
"REQUIRES" : [ "rules", "php", "hybridauth" ],
"ON" : { "hybridauth_user_login" : [] },
"DO" : [
  { "php_eval" : { "code" : "global $user;\r\n$user-\u003Edata[\u0027hybridauth\u0027][\u0027profileURL\u0027] = \u0027[hybridauth:profileURL]\u0027;\r\nuser_save($user);" } }
]

} }

Now I'm not sure if this brings any security issue, I'm not a Drupal expert, so if anyone has a better way to do this without executing a php code on rules I'd be glad to hear it.

Although it would be even better if this was part of the module itself, as users change their pictures and profile URLs all the time, so if anyone has enough knowledge they should contribute to the module.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.