Developer Implementation Guide for SSO Integration (Keycloak + CRM +
Ticketing)
This guide provides a complete, step-by-step process for integrating the CRM and Ticketing
systems with BSW Keycloak Single Sign-On (SSO). This document includes explanations, code
blocks, and dedicated placeholders for screenshots.
1. Overview of SSO Integration
Keycloak acts as the Identity Provider (IdP). Your CRM and Ticketing applications authenticate
users by redirecting them to Keycloak, receiving tokens, validating them, and creating local
sessions.
Screenshot Placeholder: [Insert SSO architecture diagram here]
2. Required Application URLs
CRM Application:
• Login Page: [Link]
• New Callback URL (to create): [Link]
Ticketing Application:
• Login Page: [Link]
• New Callback URL (to create): [Link]
3. Keycloak Configuration (Performed by BSW Team)
✔ Create a new Client entry in Keycloak for CRM and Ticketing.
✔ Set Access Type to CONFIDENTIAL.
✔ Add Redirect URI matching callback URLs.
✔ Enable Standard Flow (Authorization Code Flow).
✔ Provide Client ID and Client Secret to vendor.
✔ Provide Realm Name and OIDC Discovery URL to vendor.
Screenshot Placeholder: [Insert Keycloak admin console screenshots here]
4. Install PHP OIDC Authentication Library
Run this command in your project folder:
composer require jumbojett/openid-connect-php
Screenshot Placeholder: [Insert Composer installation screenshot here]
5. Implement SSO Login Redirect (CRM Example)
Modify [Link]:
<?php
if (isset($_GET["relogin"]) && $_GET["relogin"] === "YES") {
require "vendor/[Link]";
$oidc = new OpenIDConnectClient(
"[Link]
"crm-webfontaine",
"CRM_CLIENT_SECRET"
);
$oidc->setRedirectURL("[Link]
$oidc->addScope("openid");
$oidc->addScope("profile");
$oidc->addScope("email");
$oidc->authenticate();
exit;
}
?>
Screenshot Placeholder: [Insert screenshot showing added code block]
6. Implement Callback Handler (CRM Example)
<?php
session_start();
require "vendor/[Link]";
$oidc = new OpenIDConnectClient(
"[Link]
"crm-webfontaine",
"CRM_CLIENT_SECRET"
);
$oidc->setRedirectURL("[Link]
$oidc->authenticate();
$userInfo = $oidc->requestUserInfo();
$_SESSION["user_username"] = $userInfo->preferred_username;
$_SESSION["user_email"] = $userInfo->email;
$_SESSION["user_name"] = $userInfo->name;
$_SESSION["user_roles"] = $userInfo->roles ?? [];
header("Location: [Link]
exit;
?>
Screenshot Placeholder: [Insert screenshot of callback file location]
7. Ticketing System – Login & Callback Implementation
Follow the same code structure as CRM but use the Ticketing Client ID, Client Secret, and
callback URL.
Screenshot Placeholder: [Insert Ticketing code screenshot here]
8. Implement Logout Functionality
<?php
session_start();
$_SESSION = [];
session_destroy();
$redirectAfterLogout = "[Link]
$keycloakLogout = "[Link]
. "?post_logout_redirect_uri=" . urlencode($redirectAfterLogout);
header("Location: " . $keycloakLogout);
exit;
?>
Screenshot Placeholder: [Insert screenshot of logout button and flow]
9. Testing Checklist
☐ User is redirected to Keycloak when not logged in.
☐ User can log in using BSW credentials.
☐ Callback correctly receives authorization code.
☐ Session variables are created successfully.
☐ Dashboard loads only after successful SSO login.
☐ Logout clears both local and SSO sessions.
Screenshot Placeholder: [Insert test validation screenshots here]