Hello everyone, I’m trying to manage access to my web app using RBAC
1- In keycloak I created manager role and I give it to the user
2- the authentication succeeded and I can get the user info like the email
the problem : I don’t know how to get the user role I tried the following code:
views.py
from django.shortcuts import render
from .models import Info
from django.contrib.auth.decorators import login_required, user_passes_test
from django.urls import reverse_lazy
# Create your views here.
@login_required(login_url=reverse_lazy('oidc_authentication_init'))
def is_manager(request):
roles = request.user.oidc_profile['realm_access']['roles']
# Check if the user has the 'manager' role
if 'Manager' in roles:
print("Manager")
else:
print("Not a manager")
but I got this error:
‘User’ object has no attribute ‘oidc_profile’