Skip to content

Commit

Permalink
setting up sso client authentication integration
Browse files Browse the repository at this point in the history
  • Loading branch information
oyeniyipa committed Nov 14, 2024
1 parent 905da4b commit 85e195a
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 2 deletions.
10 changes: 9 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,12 @@ VITE_DEV=True
VITE_DEV_SERVER_URL=http://localhost:5173

# Sentry
SENTRY_DSN=
SENTRY_DSN=

# authbroker config
AUTHBROKER_URL=speak-to-webops-team-for-access
AUTHBROKER_CLIENT_ID=speak-to-webops-team-for-access
AUTHBROKER_CLIENT_SECRET=speak-to-webops-team-for-access
AUTHBROKER_STAFF_SSO_SCOPE=any-additional-scope-values
AUTHBROKER_ANONYMOUS_PATHS=(Tuple/list of paths that should be unprotected)
AUTHBROKER_ANONYMOUS_URL_NAMES=(list of url names that should be unprotected)
22 changes: 22 additions & 0 deletions config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import sentry_sdk
from dbt_copilot_python.database import database_url_from_env
from dbt_copilot_python.network import is_copilot, setup_allowed_hosts
from django.urls import reverse_lazy
from sentry_sdk.integrations.django import DjangoIntegration
from sentry_sdk.integrations.redis import RedisIntegration

Expand Down Expand Up @@ -60,6 +61,7 @@
"django.contrib.staticfiles",
"django.contrib.postgres",
"core.apps.CoreConfig",
"authbroker_client",
]

MIDDLEWARE: list[str] = [
Expand All @@ -70,6 +72,7 @@
"django.contrib.auth.middleware.AuthenticationMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
"authbroker_client.middleware.ProtectAllViewsMiddleware",
]

TEMPLATES: list[dict[str, Any]] = [
Expand All @@ -88,6 +91,25 @@
},
]

AUTHENTICATION_BACKENDS = [
"django.contrib.auth.backends.ModelBackend",
"authbroker_client.backends.AuthbrokerBackend",
]


LOGIN_URL = reverse_lazy("authbroker_client:login")
LOGIN_REDIRECT_URL = "/"


# authbroker config
AUTHBROKER_URL = env("AUTHBROKER_URL")
AUTHBROKER_CLIENT_ID = env("AUTHBROKER_CLIENT_ID")
AUTHBROKER_CLIENT_SECRET = env("AUTHBROKER_CLIENT_SECRET")
AUTHBROKER_STAFF_SSO_SCOPE = env("AUTHBROKER_STAFF_SSO_SCOPE")
AUTHBROKER_ANONYMOUS_PATHS = env("AUTHBROKER_ANONYMOUS_PATHS")
AUTHBROKER_ANONYMOUS_URL_NAMES = env("AUTHBROKER_ANONYMOUS_URL_NAMES")


# Sentry
# https://docs.sentry.io/platforms/python/integrations/django/
SENTRY_DSN: str = env.str("SENTRY_DSN")
Expand Down
1 change: 1 addition & 0 deletions config/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@
urlpatterns = [
path("", include("core.urls")),
path("admin/", admin.site.urls),
path("auth/", include("authbroker_client.urls")),
]
2 changes: 2 additions & 0 deletions core/views.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from django.contrib.auth.decorators import login_required
from django.shortcuts import render


@login_required
def index(request):
return render(request, "core/base.html")

Expand Down
54 changes: 53 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ sentry-sdk = "^2.16.0"
dbt-copilot-python = "^0.2.2"
dj-database-url = "^2.2.0"
granian = "^1.6.3"
django-staff-sso-client = "^4.3.0"

[tool.poetry.group.dev.dependencies]
black = "^24.10.0"
Expand Down

0 comments on commit 85e195a

Please sign in to comment.