Apache Superset Integration with Keycloak
@apache_superset_biInitial source: https://blog.devgenius.io/apache-superset-integration-with-keycloak-3571123e0acf
Keycloak Version: 21.0, Apache Superset: 3.0.2
Brief
Apache superset is a BI tool built in Python using a Flask framework that enables you to visualize data from almost any data source, you can read more here. And Keycloak on the other hand is an IAM tool that gives you SSO and various other features. Here we will try to integrate superset with Keycloak to facilitate its capability so that in case you want to integrate your existing users or application with superset using SSO you can do it within minutes. We will do this using Flask-AppBuilder (FAB) and Authlib library.
Prerequisites
Apache Superset: Follow this link to install superset from scratch
You can use docker as well. (I personally while exploring tools prefer otherwise) . In case you face some issues around versioning, fix by installing superset by following this link, it installs the exact dependencies for Apache Superset.
Keycloak: Follow this link to download keycloak.
Demo
- Create a new realm in Keycloak, create a client, and add users whom you want to log in from superset (say admin/admin)
- Configure URIs in client, refer screenshot below (superset-domain/oauth-authorized/keycloak)

3. In Python virtual env where you have installed superset, install Authlib and Flask OAuth lib plugin.
pip install Flask-OAuthlib Authlib
4. Now update superset_config.py (create one and set its path if you haven’t created it during secret key initialization ). Update the URL and other details mentioned here with keycloak configurations you did in step 1.
Link to code on the github: https://gist.github.com/Kritika/0bdfe9cd4575a39c68a5704ac7e9b2c5#file-superset_config-py
from flask_appbuilder.security.manager import AUTH_OAUTH
SECRET_KEY='xQXsITfo74ALPPAcC6i5yRiQZOFjULAv0QgPEUA57k0jl0RZ70HKSPJP'
# Enable OAuth authentication
AUTH_TYPE = AUTH_OAUTH
LOGOUT_REDIRECT_URL='http://localhost:8080/realms/{realmName}/protocol/openid-connect/logout'
AUTH_USER_REGISTRATION = True
AUTH_USER_REGISTRATION_ROLE = 'Gamma'
# OAuth provider configuration for Keycloak
OAUTH_PROVIDERS = [
{
'name': 'keycloak',
'icon': 'fa-key',
'token_key': 'access_token', # Keycloak uses 'access_token' for the access token
'remote_app': {
'client_id': 'client-name',
'client_secret': 'client-password',
'client_kwargs': {
'scope': 'openid profile email',
},
'server_metadata_url': 'http://localhost:8080/realms/{realmName}/.well-known/openid-configuration',
'api_base_url': 'http://localhost:8080/realms/{realmName}/protocol/',
},
}
]
5. Use the above file by updating the path in the superset’s config using the below command.
export SUPERSET_CONFIG_PATH={your-config-location}/superset_config.py
6. Restart superset, you will see the Keycloak's screen if your configurations are correct (Follow the video in case missed something, it has a detailed explanation)

7. Check log out by clicking on the logout button, you will be redirected to keycloak again.
