Sample project for how to use Django with OAuth2 Proxy
https://blog.xn--blz-sna.eu/django-single-sign-on-with-oauth2-proxy.html
- Python 100%
| myproject | ||
| .flake8 | ||
| .gitignore | ||
| LICENSE | ||
| manage.py | ||
| poetry.lock | ||
| pyproject.toml | ||
| README.md | ||
| requirements.txt | ||
django-oauth2proxy-sample
This is an example for how to use Django with OAuth2 Proxy. See this blog post for details.
To add OpenID Connect authentication to your Django development server, set up a client application in your identity provider, and run the following command:
$ oauth2-proxy \ --cookie-secret=insecure12345678 \ --provider=oidc \ --client-id=dev \ --client-secret=[…] \ --redirect-url=http://127.0.0.1:4180/oauth2/callback \ --oidc-issuer-url=https://auth.example.org/realms/testing \ --email-domain="*" \ --code-challenge-method=S256 \ --upstream=http://127.0.0.1:8000Then, open
127.0.0.1:4180instead of127.0.0.1:8000in your browser, and you'll be asked to sign in before you can access your site.
In addition to setting the proper header for use with OAuth2 Proxy as described in the blog post, myproject.auth.middleware.CustomRemoteUserMiddleware updates the users' is_staff and is_superuser fields based on membership in the group admin, thus allowing users that are members of this group in the identity provider to access the admin.