Skip to content

ubffm/ublabs-django-keycloak-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Readme

🔗 Accompanying code for the post of the UB Labs Blog. 🔗

This project is a copy of django-allauth/examples/regular-django (tag 64.0.0).

Changes:

  • settings.py
    • Disable (comment) all login provider execpt openid-connect
    • Add:
      SOCIALACCOUNT_PROVIDERS = {
          "openid_connect": {
              "APPS": [
                  {
                      "provider_id": os.getenv("KC_PROVIDER_ID", "keycloak"),
                      "name": "Keycloak",
                      "client_id": os.getenv("KC_CLIENT_ID", "django"),
                      "secret": os.getenv("KC_CLIENT_SECRET", "changeme"),
                      "settings": {
                          "server_url": os.getenv("KC_SERVER_URL", "http://localhost:8080/realms/example/.well-known/openid-configuration"),
                      },
                  }
              ]
          }
      }
      

Quickstart

Keycloak

cp template.env .env

docker compose up -d
# Login admin/password

Create realm example

  • Create realm example
  • Create client django
    • Lookup client credentials
    • Export client secret export KC_CLIENT_SECRET="changeme"

Enable user registration

  • Enable user registration in realm settings

Django

make venv
# Django             5.0.7
# django-allauth     64.0.0

source venv/bin/activate

export KC_CLIENT_SECRET="changeme"

./manage.py migrate

./manage.py runserver

Demo

Video

About

ublabs-django-keycloak-example

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published