Skip to content
This repository has been archived by the owner on Jan 4, 2023. It is now read-only.

Commit

Permalink
feat: enable oidc authz code flow (#317)
Browse files Browse the repository at this point in the history
  • Loading branch information
vmttn authored Apr 15, 2021
2 parents 2455867 + 782baf4 commit 0a689ee
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 0 deletions.
16 changes: 16 additions & 0 deletions .template.env
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,19 @@ POSTGRES_USER=river
POSTGRES_PASSWORD=river
POSTGRES_HOST=localhost
POSTGRES_PORT=5432

###
### Mozilla OpenID Connect
###

OIDC_RP_CLIENT_ID=
OIDC_RP_CLIENT_SECRET=
OIDC_RP_EXTRA_SCOPES=
OIDC_RP_SIGN_ALGO=
# OIDC_OP_JWKS_ENDPOINT=
LOGIN_REDIRECT_URL=
LOGIN_REDIRECT_URL_FAILURE=
LOGOUT_REDIRECT_URL=
OIDC_OP_AUTHORIZATION_ENDPOINT=
OIDC_OP_TOKEN_ENDPOINT=
OIDC_OP_USER_ENDPOINT=
33 changes: 33 additions & 0 deletions django/river/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"rest_framework",
"corsheaders",
"django_filters",
"mozilla_django_oidc",
# 1st parties
"core",
"extractor",
Expand All @@ -65,6 +66,8 @@
"django.middleware.common.CommonMiddleware",
"django.middleware.csrf.CsrfViewMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware",
# Redirect requests to silently re-authenticated:
"mozilla_django_oidc.middleware.SessionRefresh",
"django.contrib.messages.middleware.MessageMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
]
Expand Down Expand Up @@ -114,6 +117,7 @@
# https://docs.djangoproject.com/en/3.1/topics/auth/customizing/#specifying-authentication-backends

AUTHENTICATION_BACKENDS = [
"mozilla_django_oidc.auth.OIDCAuthenticationBackend",
"django.contrib.auth.backends.ModelBackend",
]

Expand Down Expand Up @@ -247,3 +251,32 @@
# Prometheus

EXPORTER_PORT = os.environ.get("EXPORTER_PORT", 8001)

# Mozilla OpenID Connect
# https://mozilla-django-oidc.readthedocs.io/en/stable/settings.html

OIDC_STORE_ID_TOKEN = True
OIDC_STORE_ACCESS_TOKEN = True
# Silently re-authenticated after following time:
OIDC_RENEW_ID_TOKEN_EXPIRY_SECONDS = int(os.environ.get("OIDC_RENEW_ID_TOKEN_EXPIRY_SECONDS", 12 * 60 * 60))

# Relying party
OIDC_RP_CLIENT_ID = os.environ.get("OIDC_RP_CLIENT_ID")
OIDC_RP_CLIENT_SECRET = os.environ.get("OIDC_RP_CLIENT_SECRET")
OIDC_RP_EXTRA_SCOPES = os.environ.get("OIDC_RP_EXTRA_SCOPES", "").replace(",", " ").split(" ")
OIDC_RP_SCOPES = " ".join(["openid", *OIDC_RP_EXTRA_SCOPES])
OIDC_RP_SIGN_ALGO = os.environ.get("OIDC_RP_SIGN_ALGO")

LOGIN_REDIRECT_URL = os.environ.get("LOGIN_REDIRECT_URL")
LOGIN_REDIRECT_URL_FAILURE = os.environ.get("LOGIN_REDIRECT_URL_FAILURE")
LOGOUT_REDIRECT_URL = os.environ.get("LOGOUT_REDIRECT_URL")

# Provider
OIDC_OP_AUTHORIZATION_ENDPOINT = os.environ.get("OIDC_OP_AUTHORIZATION_ENDPOINT")
OIDC_OP_TOKEN_ENDPOINT = os.environ.get("OIDC_OP_TOKEN_ENDPOINT")
OIDC_OP_USER_ENDPOINT = os.environ.get("OIDC_OP_USER_ENDPOINT")

if OIDC_RP_SIGN_ALGO == "RS256":
OIDC_OP_JWKS_ENDPOINT = os.environ.get("OIDC_OP_JWKS_ENDPOINT")
elif OIDC_RP_SIGN_ALGO == "HS256":
pass
1 change: 1 addition & 0 deletions django/river/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
path("", include("pagai.urls")),
path("", include("pyrog.urls")),
path("", include("users.urls")),
path("oidc/", include("mozilla_django_oidc.urls")),
]

if settings.ADMIN_ENABLED:
Expand Down
13 changes: 13 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,19 @@ services:
- DJANGO_SUPERUSER_USERNAME=admin
- [email protected]
- DJANGO_SUPERUSER_PASSWORD=admin
- OIDC_RP_CLIENT_ID=
- OIDC_RP_CLIENT_SECRET=
- OIDC_RP_EXTRA_SCOPES=email
- OIDC_RP_SIGN_ALGO=HS256
- LOGIN_REDIRECT_URL=http://localhost:3000/
- LOGIN_REDIRECT_URL_FAILURE=http://localhost:3000/error/
- LOGOUT_REDIRECT_URL=http://localhost:3000/
# LPT: Always use 127.0.0.1 (not localhost) in public URLs redirecting to the provider
# This is to prevent cookies in the browser from being shared and overridden by
# different services running on the host.
- OIDC_OP_AUTHORIZATION_ENDPOINT=http://127.0.0.1:8001/o/authorize/
- OIDC_OP_TOKEN_ENDPOINT=http://127.0.0.1:8001/o/token/
- OIDC_OP_USER_ENDPOINT=http://127.0.0.1:8001/o/userinfo/

zookeeper:
image: zookeeper:3.4.10
Expand Down
1 change: 1 addition & 0 deletions requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ fhir.resources @ git+https://github.com/arkhn/[email protected]#egg=fhir.reso
fluent-logger==0.9.6
hiredis==1.1.0
jsonschema==3.0.2
mozilla-django-oidc==1.2.4
msgpack==0.6.2
prometheus-client==0.8.0
pyodbc==4.0.30
Expand Down

0 comments on commit 0a689ee

Please sign in to comment.