Implementing a custom SSO Protocol
This guide explains how to extend the B2bSso addon in the B2B Platform by implementing a custom external Single Sign-On (SSO) protocol (e.g., OAuth).
Extension Point & Architecture
To add a custom protocol, extend the abstract base class AbstractSsoProtocol, which serves as the Service Provider Interface (SPI). For reference, review the default Auth0 implementation in Components/Protocol/Auth0.php.
Base Class Methods
function login(
Request $request,
SalesChannelContext $context,
B2bSsoProvider $provider
): stringStarts the authentication flow. Read credentials from $provider->getConfig() and return the IdP authorization URL where the user should be redirected.
function callback(
Request $request,
SalesChannelContext $context,
B2bSsoProvider $provider
): stringHandles the redirect back from the IdP. Exchange the authorization code, resolve the user, log them in, persist the subject ID, and return the target URL. The $provider is re-loaded from the providerId route parameter, providing the same configuration as in login().
Required Flow in callback()
Your callback() implementation must execute the following step-by-step logic:
Call
getByToken($sub)using the IdP subject ID.Fall back to
getByEmail($email)if no token is linked yet.Call
updateEmail()if the email address has drifted.Authenticate the user via
loginEmployee()orloginCustomer()(refer toAuth0.phpfor branching logic).Call
saveToken($sub)to store the relation.Return
$this->generateResponseUrl($request);.
Step-by-Step Implementation
To register a custom protocol (e.g., oauth), create the following 5 files in your custom plugin (no database migrations required):
1. PHP Protocol Class
Create a class extending AbstractSsoProtocol within your plugin's namespace.
2. Service Definition
Register your service in services.xml using the b2bsellers_sso.protocol tag and pass the required positional arguments:
3. Administration Vue Component
Create the Administration component b2b-sso-protocol-oauth. It accepts the props providerId and config, and emits changes via $emit('change', config). You can copy the reference component from Resources/app/administration/src/components/b2b-sso-protocol-auth0/.
4. Administration Override
Override b2b-sso-provider-detail-modal to include your new key in the protocols computed property:
JavaScript
5. Snippets
Add admin translation snippets under b2bSso.ssoProtocol.oauth.*, mirroring the structure of the auth0 block.
Key Considerations
No Automatic User Creation:
B2bSsodoes not create customer accounts. The user or employee must already exist in Shopware. If no match is found, the system redirects to the login page withb2bSso.noConnectedUser.State / PKCE Handling: No built-in state or PKCE helpers are provided. You must handle CSRF protection and token verification manually within your protocol class.
Schema Flexibility: Providers are not scoped to individual sales channels, and provider configuration is stored as a free-form JSON column, requiring no database schema changes.
Last updated
Was this helpful?