No integration for Keycloak and Django?

Hi,
I’m working with Django projects, and I wanted to integrate Keycloak to delegate authorization and authentication with Keycloak and OPENID.
I’m using Django 4.x and Keycloak 13.x
So far I found a lot of support for the Java family tools and frameworks, but almost nothing for Django. This is very very odd, as Django is one of the most popular Python frameworks.

Is there any way to do this integration in a relatively simple way?

Thank you!!

You found nothing because you don’t need a documentation related to Keycloak/Django but just a way to call openid endpoints to authenticate/authorize your users.

Also working with this combo without any effort.

An example here: Part 3 - OAuth2 token authentication — Django OAuth Toolkit 2.1.0 documentation but there are many others.

Hi,
Thank you very much for your answer!

I’ve seen this before, but somehow I understood that it was meant to work with your own Oauth provider (as part 1 is building your own provider)
Probably my bad, as I’m really new to Django and Security.

But from what you said, I assume that the provider could be anything, including Keycloak.
This example seems to be focused in authentication.
Will this cover also authorization too?

Let me summarize to see if I understood well.
1.You have your user credentials and roles/permissions created in Keycloak.
2.You configure the Django Oauth Toolkit to use Keycloak as OIDC provider,
3. Tthen when you try to log in to your app, you’ll be redirected to Keycloak login page
4. You enter your credentials,
5. Keycloak returns both authentication and authorization tokens
6. Django Oauth Toolkit handles them with the Authentication Backend.
7. To protect your resources you use things like @login_required or @permission_required in your code.
Am I even close?

Thank you !!

I have done this with Paperless. I wrote up how I got it working here: Adding OAuth to Paperless-ngx | Cipher Menial

Note that current release of django-allauth doesn’t appear to work with django 4.1. Installing the development version 0.52.0.dev0 does work.

hello, please can you guide me throw how you implemented keycloak with django @ciphermenial @RicardoFernandez-UY

1 Like