SDKs
...
Tutorials
Advanced Usage

Single Sign-On

10min

Single sign-on is a useful feature that allows users to log in to multiple applications and websites with one set of credentials. In this guide, we will explore how to integrate this functionality into your application using the LicenseSpring SDK.

Prerequisites

  1. Completed the Getting Started and User-Based Licensing tutorials, specifically:
    • Initialized LicenseManager (or LicenseHandler) with your configuration using the appropriate settings.
    • Activated the user-based license of any type.

SSO Configuration

To implement SSO activation, add a customer account code to the configuration. The account code can be found on your LicenseSpring account under Customer->Customer accounts:

Document image


When you have this value, set it to the configuration:

C++
C#
Swift


This value also can be set during the activation process, so you can use multiple customer accounts without reconfiguring the LicenseManager.

Authorization URL

You can choose the authorization method when getting the authorization URL. There are two methods:

  • Token: Implicit grant which attaches user pool tokens ( id_token, access_token, expires_in, and token_type ) to the redirect_uri once the user is verified.
  • Code: Authorization code grant method where the code query param is attached to the redirect URL instead of id_token. This code is sent in the request body when doing license activation.

If you do not want to expose user tokens or the redirect URI is too long for your use case, we recommend using the code instead of the token. By default, the SDK returns the URL with the authorization code. To use the authorization token, pass the additional parameter to the getSSOUrl method:

C++
C#
Swift


Note that this method sets the passed customer account to the LicenseManager configuration.

Authorization

You can open the SSO URL in the system browser or within the application. After the user enters the login credentials, handle the redirect. 

System Browser

If you are using the system browser, you can implement reopening the application with the redirect URL as a parameter. To make the application open with the redirect link, add a script that edits the registry, enabling your application to handle LicenseSpring URLs, as a part of the installation process.

Here’s an example of edited registry:

Document image

Document image


Browsing Within the Application

This functionality can be implemented using various libraries and tools such as Qt WebEngine or .NET WebBrowser control. The goal is to wait until the URL changes and retrieve this redirect link.

To learn more about both approaches, see the SSO sample projects we provide along with C++ and .Net SDKs.

License Activation

When you have the redirect URL, extract the authorization code or token.

C++
C#
Swift


Then pass the authorizationData value to the activation method. It allows setting the customer account and specifying whether the authorization data is a code or a token.

C++
C#
Swift


Common Errors

This type of license activation can throw the same errors as a regular activation. 

In addition, there are errors specific to single sign-on:

  • SSOException - In case the customer was not found or SSO is not enabled.
  • SSOTokenException - In case the SSO token is invalid or expired.