diff --git a/README.rst b/README.rst index f8d549f..ca1e7c0 100644 --- a/README.rst +++ b/README.rst @@ -98,13 +98,36 @@ This will add these paths to Django: * ``/oauth2/callback`` where ADFS redirects back to after login. So make sure you set the redirect URI on ADFS to this. * ``/oauth2/logout`` which logs out the user from both Django and ADFS. -You can use them like this in your django templates: - -.. code-block:: html - - Logout - Login - Login (no SSO) +Below is sample Django template code to use these paths depending if +you'd like to use GET or POST requests. Logging out was deprecated in +`Django 4.1 `_. + +- Using GET requests: + + .. code-block:: html + + Logout + Login + Login (no SSO) + +- Using POST requests: + + .. code-block:: html+django + +
+ {% csrf_token %} + +
+
+ {% csrf_token %} + + +
+
+ {% csrf_token %} + + +
Contributing ------------ diff --git a/django_auth_adfs/config.py b/django_auth_adfs/config.py index ce843fd..317781f 100644 --- a/django_auth_adfs/config.py +++ b/django_auth_adfs/config.py @@ -337,7 +337,10 @@ def build_authorization_endpoint(self, request, disable_sso=None, force_mfa=Fals """ self.load_config() - redirect_to = request.GET.get(REDIRECT_FIELD_NAME, None) + if request.method == 'POST': + redirect_to = request.POST.get(REDIRECT_FIELD_NAME, None) + else: + redirect_to = request.GET.get(REDIRECT_FIELD_NAME, None) if not redirect_to: redirect_to = django_settings.LOGIN_REDIRECT_URL redirect_to = base64.urlsafe_b64encode(redirect_to.encode()).decode() diff --git a/django_auth_adfs/views.py b/django_auth_adfs/views.py index 3b944de..747321d 100644 --- a/django_auth_adfs/views.py +++ b/django_auth_adfs/views.py @@ -84,6 +84,15 @@ def get(self, request): """ return redirect(provider_config.build_authorization_endpoint(request)) + def post(self, request): + """ + Initiates the OAuth2 flow and redirect the user agent to ADFS + + Args: + request (django.http.request.HttpRequest): A Django Request object + """ + return redirect(provider_config.build_authorization_endpoint(request)) + class OAuth2LoginNoSSOView(View): def get(self, request): @@ -95,6 +104,15 @@ def get(self, request): """ return redirect(provider_config.build_authorization_endpoint(request, disable_sso=True)) + def post(self, request): + """ + Initiates the OAuth2 flow and redirect the user agent to ADFS + + Args: + request (django.http.request.HttpRequest): A Django Request object + """ + return redirect(provider_config.build_authorization_endpoint(request, disable_sso=True)) + class OAuth2LoginForceMFA(View): def get(self, request): @@ -106,6 +124,15 @@ def get(self, request): """ return redirect(provider_config.build_authorization_endpoint(request, force_mfa=True)) + def post(self, request): + """ + Initiates the OAuth2 flow and redirect the user agent to ADFS + + Args: + request (django.http.request.HttpRequest): A Django Request object + """ + return redirect(provider_config.build_authorization_endpoint(request, force_mfa=True)) + class OAuth2LogoutView(View): def get(self, request): @@ -117,3 +144,13 @@ def get(self, request): """ logout(request) return redirect(provider_config.build_end_session_endpoint()) + + def post(self, request): + """ + Logs out the user from both Django and ADFS + + Args: + request (django.http.request.HttpRequest): A Django Request object + """ + logout(request) + return redirect(provider_config.build_end_session_endpoint()) diff --git a/docs/install.rst b/docs/install.rst index 09a9381..95e38b1 100644 --- a/docs/install.rst +++ b/docs/install.rst @@ -102,10 +102,33 @@ This will add these paths to Django: * ``/oauth2/callback`` where ADFS redirects back to after login. So make sure you set the redirect URI on ADFS to this. * ``/oauth2/logout`` which logs out the user from both Django and ADFS. -You can use them like this in your django templates: - -.. code-block:: html - - Logout - Login - Login (no SSO) +Below is sample Django template code to use these paths depending if +you'd like to use GET or POST requests. Logging out was deprecated in +`Django 4.1 `_. + +- Using GET requests: + + .. code-block:: html + + Logout + Login + Login (no SSO) + +- Using POST requests: + + .. code-block:: html+django + +
+ {% csrf_token %} + +
+
+ {% csrf_token %} + + +
+
+ {% csrf_token %} + + +