-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from N5GEH/5-add-oidc-auth
add oidc auth
- Loading branch information
Showing
53 changed files
with
943 additions
and
195 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Django | ||
DJANGO_SECRET_KEY= | ||
DJANGO_DEBUG=False | ||
ALLOWED_HOSTS=["localhost","127.0.0.1"] | ||
LANGUAGE_CODE=en-us | ||
TIME_ZONE=Europe/Berlin | ||
|
||
# JS/SCSS compression | ||
COMPRESS_ENABLED=True | ||
|
||
# OIDC | ||
LOGIN_URL=/oidc/authenticate | ||
LOGIN_REDIRECT_URL=/oidc/callback/ | ||
LOGOUT_REDIRECT_URL=/ | ||
OIDC_OP_AUTHORIZATION_ENDPOINT= | ||
OIDC_OP_JWKS_ENDPOINT= | ||
OIDC_OP_TOKEN_ENDPOINT= | ||
OIDC_OP_USER_ENDPOINT= | ||
OIDC_RP_CLIENT_ID= | ||
OIDC_RP_CLIENT_SECRET= | ||
OIDC_SUPER_ADMIN_ROLE=super_admin | ||
OIDC_SERVER_ADMIN_ROLE=server_admin | ||
OIDC_PROJECT_ADMIN_ROLE=project_admin | ||
OIDC_USER_ROLE=user | ||
OIDC_TOKEN_ROLE_FIELD=roles |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from django.contrib import admin | ||
|
||
from alarming.models import Subscription | ||
|
||
admin.site.register(Subscription) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class AlarmingConfig(AppConfig): | ||
default_auto_field = "django.db.models.BigAutoField" | ||
name = "alarming" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from django.db import models | ||
|
||
from utils.generators import generate_uuid | ||
|
||
from projects.models import Project | ||
|
||
|
||
class Subscription(models.Model): | ||
uuid = models.CharField( | ||
unique=True, max_length=64, default=generate_uuid, primary_key=True | ||
) # later uuid from cb | ||
name = models.CharField(max_length=64) | ||
|
||
project = models.ForeignKey(Project, on_delete=models.CASCADE) | ||
|
||
def __str__(self): | ||
return self.name | ||
|
||
class Meta: | ||
ordering = ["name"] |
9 changes: 9 additions & 0 deletions
9
app/Entirety/alarming/templates/alarming/subscription_list.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{% extends '_base.html' %} | ||
|
||
{% block title %}Subscriptions{% endblock %} | ||
|
||
{% block content %} | ||
{% for subscription in subscription_list %} | ||
{{ subscription.name }} | ||
{% endfor %} | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.test import TestCase | ||
|
||
# Create your tests here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from django.contrib.auth.decorators import login_required | ||
from django.urls import path | ||
from django.views.generic.base import RedirectView | ||
|
||
from alarming.views import SubscriptionList | ||
|
||
urlpatterns = [ | ||
path("subscriptions/", SubscriptionList.as_view(), name="subscriptions"), | ||
path("", RedirectView.as_view(pattern_name="subscriptions")), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from django.shortcuts import render | ||
from django.views.generic import ListView | ||
|
||
from alarming.models import Subscription | ||
from projects.mixins import ProjectContextMixin | ||
|
||
|
||
class SubscriptionList(ProjectContextMixin, ListView): | ||
model = Subscription | ||
|
||
def get_queryset(self): | ||
return Subscription.objects.filter(project=self.project) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
from mozilla_django_oidc.auth import OIDCAuthenticationBackend | ||
from django.conf import settings | ||
|
||
|
||
class CustomOIDCAB(OIDCAuthenticationBackend): | ||
def create_user(self, claims): | ||
user = super(CustomOIDCAB, self).create_user(claims) | ||
|
||
return self.__set_user_values(user, claims) | ||
|
||
def update_user(self, user, claims): | ||
return self.__set_user_values(user, claims) | ||
|
||
def __set_user_values(self, user, claims): | ||
roles = claims.get("roles", []) | ||
|
||
user.first_name = claims.get("given_name", "") | ||
user.last_name = claims.get("family_name", "") | ||
user.username = claims.get("preferred_username", "") | ||
|
||
user.is_superuser = user.is_staff = settings.OIDC_SUPER_ADMIN_ROLE in roles | ||
user.is_server_admin = settings.OIDC_SERVER_ADMIN_ROLE in roles | ||
user.is_project_admin = settings.OIDC_PROJECT_ADMIN_ROLE in roles | ||
|
||
user.save() | ||
|
||
return user | ||
|
||
def verify_claims(self, claims): | ||
verified = super(CustomOIDCAB, self).verify_claims(claims) | ||
is_user = settings.OIDC_USER_ROLE in claims.get( | ||
settings.OIDC_TOKEN_ROLE_FIELD, [] | ||
) | ||
return verified and is_user |
Oops, something went wrong.