The only fields passed from Drupal to Discourse in discourse_sso_validate() are currently user ID, username and email. Discourse supports custom fields (https://meta.discourse.org/t/custom-user-fields-for-plugins/14956) and in some cases it might be desired to send additional info from Drupal to Discourse. Examples could be anything from passing user name to subscription settings.

I don't see any hook at the moment that would allow to append to return payload unless I am missing something?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

nonsie created an issue. See original summary.

nonsie’s picture

Something like attached patch should suffice. And then in your own custom module you can have something like this:

/**
 * Implements hook_discourse_sso_payload_alter().
 * @param array $payload
 * @param object $account
 */
function mymodule_discourse_sso_payload_alter(&$payload, $account) {
  if (is_object($account)) {
    $wrapper = entity_metadata_wrapper('user', $account->uid);
    $payload['custom.user_field_3'] = $wrapper->field_user_foobar->value();
  }
}
firewaller’s picture

This is great!

Just as a note for anyone else using this, when passing boolean values, use 'true' or 'false' (with quotes) and not: TRUE, FALSE, true, false, 1, 0

ie.
$payload['admin'] = 'true';

Charlotte17’s picture

Status: Active » Needs work
+++ b/includes/discourse.sso.inc
@@ -44,12 +44,18 @@ function discourse_sso_validate($payload, $sig) {
+    foreach (module_implements('discourse_sso_payload_alter') as $module) {

This should be a drupal_alter instead of module_implements.

Charlotte17’s picture

Status: Needs work » Needs review
FileSize
1.15 KB