Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion poukazky/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
OIDC_OP_AUTHORIZATION_ENDPOINT = "https://id.trojsten.sk/oauth/authorize/"
OIDC_OP_USER_ENDPOINT = "https://id.trojsten.sk/oauth/userinfo/"
OIDC_OP_TOKEN_ENDPOINT = "https://id.trojsten.sk/oauth/token/"
OIDC_RP_SCOPES = "openid email profile"
OIDC_RP_SCOPES = "openid email profile groups"
OIDC_RP_SIGN_ALGO = "RS256"
OIDC_RP_CLIENT_ID = env("OIDC_RP_CLIENT_ID", default="")
OIDC_RP_CLIENT_SECRET = env("OIDC_RP_CLIENT_SECRET", default="")
Expand Down
13 changes: 13 additions & 0 deletions poukazky/users/auth.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
from django.contrib.auth.models import Group
from mozilla_django_oidc.auth import OIDCAuthenticationBackend

from .models import User

ADMIN_OIDC_GROUP = "poukazky@iam.trojsten.sk"
ADMIN_DJANGO_GROUP = "admin"


def logout_url(request):
return "https://id.trojsten.sk/oauth/logout"
Expand Down Expand Up @@ -33,3 +37,12 @@ def _update_user(self, user, claims):
user.username = claims.get("preferred_username")
user.first_name = claims.get("given_name", "")
user.last_name = claims.get("family_name", "")

oidc_groups = claims.get("groups", [])
is_admin = ADMIN_OIDC_GROUP in oidc_groups
user.is_staff = is_admin

if is_admin:
admin_group, _ = Group.objects.get_or_create(name=ADMIN_DJANGO_GROUP)
user.save() # when creating user, he will not exist at this time, so we need to save him.
user.groups.add(admin_group)
Loading