How to integrate Keycloak with older version of Django

Hi, I have a Django project and need to integrate Keycloak for SSO.
I google searched and found allauth library seem to be working, but it only work for Django 4.x and above, meanwhile, my Django version is 3.2
So is there another way to do it? I really really really don’t want to upgrade Django version of my project, because it was huge and has a lot dependencies

<conjecture>

You could either find an older version of allauth that works with Django 3.2, or you could “backport” the current version of allauth such that it works with Django 3.2.

You probably wouldn’t need to fix or convert everything, just the parts you need and ignore or delete the rest.

</conjecture>

1 Like

Use the python-keycloak library, which interacts with Keycloak’s REST API. Configure KeycloakOpenID with your Keycloak server URL, realm, client ID, and secret, then implement login by exchanging user credentials for a token using keycloak_openid.token(). Use the returned access_token to fetch user info via keycloak_openid.userinfo(), and map this information to Django’s user model for authentication. Alternatively, configure Keycloak as an OAuth2 provider using django-oauth-toolkit or deploy an external authentication proxy like Keycloak Gatekeeper to manage the SSO flow, passing authenticated user details to Django via headers. These approaches avoid upgrading while ensuring secure integration.

1 Like

@Isla011 can you give a detailed step by step guide?
sorry, I am just a beginner in both Django and Keycloak