We're attempting to set roles in Vanilla Forum based on a user's groups in Craft CMS. We've created a module based on the documentation at https://nystudio107.com/docs/vanillaforums/#using-vanilla-forums and are successfully setting $event->ssoData['roles'] to our user groups, but the roles are not set in Vanilla.
This is the relevant bit of the module:
Event::on(
Sso::class,
Sso::EVENT_SSO_DATA,
function (SsoDataEvent $event) {
// get the current user
$user = Craft::$app->getUser()->getIdentity();
$groups = [];
foreach ($user->getGroups() as $group) {
$groups[] = $group->name;
}
$event->ssoData['roles'] = implode(',', $groups);
}
);
In craft-vanillaforums Sso.php, we found this code that seems to be what passes the relevant data to JsConnect:
public function output(string $jwt): void
{
$settings = $this->getPluginSettings();
$ssoData = $this->getSsoData($jwt);
$jsConnect = new JsConnect();
$jsConnect->setSigningCredentials($settings->vanillaForumsClientID, $settings->vanillaForumsSecret);
// If they are signed in to Craft
if ($ssoData !== null) {
$jsConnect
->setUniqueID($ssoData->uniqueid)
->setName($ssoData->name)
->setEmail($ssoData->email)
->setPhotoUrl($ssoData->photourl);
} else {
// They are not signed in to Craft
$jsConnect->setGuest(true);
}
$request = Craft::$app->getRequest();
// And away we go
$jsConnect->handleRequest($request->get());
Craft::$app->end();
}
It seems like the only data passed to JsConnect is the id, name, email, and photoUrl. If I add ->setRoles(explode(',', $ssoData->roles)); the roles are set in Vanilla. Is there a setting or configuration option somewhere that I'm missing that will enable setting the roles without having to modify the plugin's code?
To reproduce
Steps to reproduce the behaviour:
Create module as described in documentation and modify $ssoData to include a ['roles'] property
Sign in to Vanilla via SSO
Check user roles in Vanilla
Expected behaviour
The user's roles in Vanilla will match the groups they are members of in Craft.
Describe the bug
Hi,
We're attempting to set roles in Vanilla Forum based on a user's groups in Craft CMS. We've created a module based on the documentation at https://nystudio107.com/docs/vanillaforums/#using-vanilla-forums and are successfully setting
$event->ssoData['roles']
to our user groups, but the roles are not set in Vanilla.This is the relevant bit of the module:
In craft-vanillaforums Sso.php, we found this code that seems to be what passes the relevant data to JsConnect:
It seems like the only data passed to JsConnect is the id, name, email, and photoUrl. If I add
->setRoles(explode(',', $ssoData->roles));
the roles are set in Vanilla. Is there a setting or configuration option somewhere that I'm missing that will enable setting the roles without having to modify the plugin's code?To reproduce
Steps to reproduce the behaviour:
$ssoData
to include a['roles']
propertyExpected behaviour
The user's roles in Vanilla will match the groups they are members of in Craft.
Versions