Skip to content
Snippets Groups Projects
Commit 41be2555 authored by Sylvain Le Bon's avatar Sylvain Le Bon Committed by Benoit Alessandroni
Browse files

update: Django 4.2 compatibility

parent 7ea22239
No related branches found
No related tags found
1 merge request!111Django4
...@@ -6,6 +6,7 @@ from djangoldp_account.models import LDPUser ...@@ -6,6 +6,7 @@ from djangoldp_account.models import LDPUser
from .models import Account, ChatProfile from .models import Account, ChatProfile
@admin.register(Account, ChatProfile)
class EmptyAdmin(admin.ModelAdmin): class EmptyAdmin(admin.ModelAdmin):
def get_model_perms(self, request): def get_model_perms(self, request):
return {} return {}
...@@ -28,6 +29,7 @@ class ChatProfileInline(admin.StackedInline): ...@@ -28,6 +29,7 @@ class ChatProfileInline(admin.StackedInline):
extra = 0 extra = 0
@admin.register(LDPUser)
class LDPUserAdmin(DjangoLDPUserAdmin): class LDPUserAdmin(DjangoLDPUserAdmin):
exclude = ('is_backlink', 'allow_create_backlink') exclude = ('is_backlink', 'allow_create_backlink')
form = LDPUserChangeForm form = LDPUserChangeForm
...@@ -45,6 +47,3 @@ class LDPUserAdmin(DjangoLDPUserAdmin): ...@@ -45,6 +47,3 @@ class LDPUserAdmin(DjangoLDPUserAdmin):
) )
admin.site.register(LDPUser, LDPUserAdmin)
admin.site.register(Account, EmptyAdmin)
admin.site.register(ChatProfile, EmptyAdmin)
\ No newline at end of file
...@@ -157,8 +157,8 @@ class ExternalUserBackend(ModelBackend): ...@@ -157,8 +157,8 @@ class ExternalUserBackend(ModelBackend):
return self._get_or_create_then_authenticate({}, jwt['webid']) return self._get_or_create_then_authenticate({}, jwt['webid'])
def authenticate(self, request, username=None, password=None, **kwargs): def authenticate(self, request, username=None, password=None, **kwargs):
if 'HTTP_AUTHORIZATION' in request.META: if 'authorization' in request.headers:
jwt = request.META['HTTP_AUTHORIZATION'] jwt = request.headers['authorization']
if jwt.lower().startswith("dpop"): if jwt.lower().startswith("dpop"):
jwt = jwt[5:] jwt = jwt[5:]
return self.validate_dpop_token(request, jwt) return self.validate_dpop_token(request, jwt)
......
...@@ -34,16 +34,16 @@ urlpatterns = [ ...@@ -34,16 +34,16 @@ urlpatterns = [
name='django_registration_register', name='django_registration_register',
), ),
path('auth/login/', LDPAccountLoginView.as_view(),name='login'), path('auth/login/', LDPAccountLoginView.as_view(),name='login'),
re_path(r'^auth/', include('django_registration.backends.activation.urls')), path('auth/', include('django_registration.backends.activation.urls')),
re_path(r'^auth/', include('django.contrib.auth.urls')), path('auth/', include('django.contrib.auth.urls')),
re_path(r'^accounts/', LDPViewSet.urls(model=Account, permission_classes=[LDPPermissions], model_prefix='pk_lookup', path('accounts/', LDPViewSet.urls(model=Account, permission_classes=[LDPPermissions], model_prefix='pk_lookup',
lookup_field='pk')), lookup_field='pk')),
re_path(r'^chat-profile/', LDPViewSet.urls(model=ChatProfile, permission_classes=[LDPPermissions], path('chat-profile/', LDPViewSet.urls(model=ChatProfile, permission_classes=[LDPPermissions],
model_prefix='pk_lookup', lookup_field='pk')), model_prefix='pk_lookup', lookup_field='pk')),
re_path(r'^oidc/login/callback/?$', RPLoginCallBackView.as_view(), name='oidc_login_callback'), re_path(r'^oidc/login/callback/?$', RPLoginCallBackView.as_view(), name='oidc_login_callback'),
re_path(r'^oidc/login/?$', RPLoginView.as_view(), name='oidc_login'), re_path(r'^oidc/login/?$', RPLoginView.as_view(), name='oidc_login'),
re_path(r'^userinfo/?$', csrf_exempt(userinfocustom)), re_path(r'^userinfo/?$', csrf_exempt(userinfocustom)),
re_path(r'^check-user/?$', csrf_exempt(check_user)), re_path(r'^check-user/?$', csrf_exempt(check_user)),
re_path(r'^redirect-default/$', RedirectView.as_view(),name='redirect-default'), path('redirect-default/', RedirectView.as_view(),name='redirect-default'),
re_path(r'^', include('oidc_provider.urls', namespace='oidc_provider')) path('', include('oidc_provider.urls', namespace='oidc_provider'))
] ]
...@@ -10,7 +10,7 @@ if hasattr(settings, 'XMPP_SERVER_IP'): ...@@ -10,7 +10,7 @@ if hasattr(settings, 'XMPP_SERVER_IP'):
XMPP_SERVERS = XMPP_SERVERS.union(getattr(settings, 'XMPP_SERVER_IP')) XMPP_SERVERS = XMPP_SERVERS.union(getattr(settings, 'XMPP_SERVER_IP'))
def check_client_ip(request): def check_client_ip(request):
x_forwarded_for = request.META.get('HTTP_X_FORWARDED_FOR') x_forwarded_for = request.headers.get('x-forwarded-for')
if x_forwarded_for: if x_forwarded_for:
ip = x_forwarded_for.replace(' ', '').split(',') ip = x_forwarded_for.replace(' ', '').split(',')
else: else:
......
...@@ -37,7 +37,7 @@ def check_user(request, *args, **kwargs): ...@@ -37,7 +37,7 @@ def check_user(request, *args, **kwargs):
'''Returns user if they are authenticated with this server, else 404''' '''Returns user if they are authenticated with this server, else 404'''
response = HttpResponse({}, status=200) response = HttpResponse({}, status=200)
if request.method in ['GET', 'HEAD', 'OPTIONS']: if request.method in ['GET', 'HEAD', 'OPTIONS']:
response['Access-Control-Allow-Origin'] = request.META.get('HTTP_ORIGIN') response['Access-Control-Allow-Origin'] = request.headers.get('origin')
response["Access-Control-Allow-Headers"] = \ response["Access-Control-Allow-Headers"] = \
oidc_settings.get('OIDC_ACCESS_CONTROL_ALLOW_HEADERS') oidc_settings.get('OIDC_ACCESS_CONTROL_ALLOW_HEADERS')
response["Access-Control-Allow-Credentials"] = 'true' response["Access-Control-Allow-Credentials"] = 'true'
...@@ -54,7 +54,7 @@ def check_user(request, *args, **kwargs): ...@@ -54,7 +54,7 @@ def check_user(request, *args, **kwargs):
response_body['dpop'] = request.headers['Dpop'] response_body['dpop'] = request.headers['Dpop']
response = JsonResponse(settings.userinfo(response_body, request.user)) response = JsonResponse(settings.userinfo(response_body, request.user))
response['Access-Control-Allow-Origin'] = request.META.get('HTTP_ORIGIN') response['Access-Control-Allow-Origin'] = request.headers.get('origin')
response["Access-Control-Allow-Headers"] = \ response["Access-Control-Allow-Headers"] = \
oidc_settings.get('OIDC_ACCESS_CONTROL_ALLOW_HEADERS') oidc_settings.get('OIDC_ACCESS_CONTROL_ALLOW_HEADERS')
response["Access-Control-Expose-Headers"] = "Location, User" response["Access-Control-Expose-Headers"] = "Location, User"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment