This plugin now supports JWT-based Single Sign-On between Joomla and Flarum using the maicol07/flarum-ext-sso extension.
First, configure the Flarum SSO extension with these settings:
%%https://combo.remository.com%%%%Sha256%%%%c1Y9I+cYf8x5p4pxJDZj7GuAgoi/0ueAn2WC2D+3WYs=%%In the Joomla plugin parameters, add these new settings:
%%https://combo.remository.com%%%%c1Y9I+cYf8x5p4pxJDZj7GuAgoi/0ueAn2WC2D+3WYs=%%This can be used as an alternative or a supplement to creating a menu item to point to the forum.
<?php
// In your Joomla template or module
$user = JFactory::getUser();
if (!$user->guest) {
// User is logged in, create JWT login URL
$app = JFactory::getApplication();
$jinput = $app->input;
// Make AJAX call to generate JWT login URL
$url = JUri::root() . 'index.php?option=com_ajax&plugin=flarum&group=user&method=createJwtLoginUrl&format=json';
echo '<a href="#" onclick="accessForum()" class="btn btn-primary">Access Forum</a>';
echo '<script>
function accessForum() {
fetch("' . $url . '")
.then(response => response.json())
.then(data => {
if (data.success && data.data.login_url) {
window.open(data.data.login_url, "_blank");
} else {
alert("Failed to create forum login URL");
}
})
.catch(error => console.error("Error:", error));
}
</script>';
} else {
echo '<a href="' . JRoute::_('index.php?option=com_users&view=login') . '">Login to Access Forum</a>';
}
?>
%%onUserLogin%% eventThe generated JWT tokens contain:
{
"iss": "https://combo.remository.com",
"sub": "123",
"jti": "123",
"username": "johndoe",
"email": "john@example.com",
"name": "John Doe",
"groups": [
{"id": 1, "name": "Registered"},
{"id": 2, "name": "Public"}
],
"iat": 1234567890,
"exp": 1234571490
}
%%test_jwt.php%% scriptRun the included test script to verify JWT generation:
cd /var/www/flarum/plugins/user/flarum
php test_jwt.php
This will generate a test JWT token and validate its structure.