Documentation versions (currently viewingVaadin 23)

You are viewing documentation for Vaadin 23. View latest documentation

Getting Started with SSO Kit

Step-by-step guide on how to use SSO Kit in an application.

SSO Kit builds upon Spring Boot and Spring Security. It comes with a starter module that configures the security settings needed to authenticate with an identity provider.

1. Add the SSO Kit Dependency

To get started, you need to add SSO Kit as a dependency to an application. For example, to add to a Maven project, do something like this:


Next, you need to set some configuration properties to connect SSO Kit to an OpenID Connect provider. These properties can be added to the file where you define the provider URL and the client registration details, such as credentials and scope.

Provider definition is configured within the namespace where you define a key to identify the provider, such as keycloak. Then you can use the same key to register the client for that provider within the namespace, where you specify client credentials and the requested scope.

The scope is a list of keywords to request the provider for a specific set of information, such as user profile, email or roles. The following is an example of the properties to set to enable a Keycloak instance to perform authentication: my-client,openid,email,roles

Once you have at least one client configured, you’re ready to secure any views.

2. Securing Views

The default configuration redirects requests to any view, to the provider’s login page. You can set which views require authentication, annotating them as described in Securing Spring Boot Applications: Annotating the View Classes.

The following is an example how you might do this:

@Route(value = "private")
public class ProfileView extends VerticalLayout {
    // ...

3. Single Sign-On

SSO Kit provides the SingleSignOnConfiguration auto-configuration class to setup Vaadin and Spring to allow single sign-on with external identity providers.

Customized security configuration
If you need a customized security configuration, you can disable this auto-configuration class by setting the property to false and define your own configuration class.

The following configuration enables login for the identity providers defined in the application configuration. It instructs the application to accept requests for the login route. It can be configured by setting the vaadin.sso.login-route property, which defaults to /login. If there is no view defined for this route, Spring auto-generates a page with links to each of the configured providers login forms.

To redirect users automatically to the provider login form, you can set this property to /oauth2/authorization/{provider-key}, where {provider-key} is the key used to configure the provider in file.

Custom Login Page
Some providers support a custom theme for their login pages. Find out more in Theming.

4. Authentication Context

Upon successful authentication, the provider redirects the user back to the protected view. To access the authenticated user’s information (such as name, email and roles), Flow provides the AuthenticationContext bean that can be used as a view constructor argument. Then you can get the authenticated user with getAuthenticatedUser(Class<U> userType). It returns an Optional object containing the user instance if the session has an authenticated user or is empty otherwise.

public class ProfileView extends VerticalLayout {
    public ProfileView(AuthenticationContext authContext) {
        authContext.getAuthenticatedUser(OidcUser.class).ifPresent(user -> {
            Avatar userAvatar = new Avatar(user.getFullName());
    // ...

By default, the SSO Kit authenticated user is an instance of OidcUser. If your application defines a custom user service to provide your own user type, you can use that type as the userType parameter.

5. Single Sign-Off

SSO Kit provides two methods for logging out the user, defined by the OpenID Connect specification:

5.1. RP-Initiated Logout

RP-Initiated Logout (i.e., Relaying Party, the application) enables the user to logout from the application itself, ensuring the connected provider session is terminated. The AuthenticationContext bean provides the logout() method to initiate the logout process programmatically. For example, inside a button click-listener:

@Route(value = "private")
public class ProfileView extends VerticalLayout {
    public ProfileView(AuthenticationContext authContext) {
        add(new Button("Logout", e -> authContext.logout()));
    // ...

After a successful logout, the user is redirected to the configured logout redirect route. That can be set with the vaadin.sso.logout-redirect-route property:


The default value of this property is the application root.

5.2. Back-Channel Logout

Back-Channel Logout is a feature that enables the provider to close user sessions from outside the application. For example, it can be done from the provider’s user dashboard or from another application. To enable this feature, you need to set the vaadin.sso.back-channel property to true:


Once that’s done, the client should be configured on the provider’s dashboard to send logout requests to a specific application URL: /logout/back-channel/{registration-key}, where {registration-key} is the provider key.