vincbeck commented on code in PR #35488:
URL: https://github.com/apache/airflow/pull/35488#discussion_r1400855441


##########
airflow/providers/amazon/aws/auth_manager/views/auth.py:
##########
@@ -0,0 +1,145 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+from __future__ import annotations
+
+import logging
+from functools import cached_property
+
+from flask import make_response, redirect, request, session, url_for
+from flask_appbuilder import expose
+
+from airflow.configuration import conf
+from airflow.exceptions import AirflowException
+from airflow.providers.amazon.aws.auth_manager.constants import 
CONF_SAML_METADATA_URL_KEY, CONF_SECTION_NAME
+from airflow.providers.amazon.aws.auth_manager.user import AwsAuthManagerUser
+from airflow.www.app import csrf
+from airflow.www.views import AirflowBaseView
+
+try:
+    from onelogin.saml2.auth import OneLogin_Saml2_Auth
+    from onelogin.saml2.idp_metadata_parser import 
OneLogin_Saml2_IdPMetadataParser
+except ImportError:
+    raise ImportError(
+        "AWS auth manager requires the python3-saml library but it is not 
installed by default. "
+        "Please install the python3-saml library by running: "
+        "pip install apache-airflow-providers-amazon[python3-saml]"
+    )
+
+
+class AwsAuthManagerAuthenticationViews(AirflowBaseView):
+    """
+    Views specific to AWS auth manager authentication mechanism.
+
+    Some code below is inspired from
+    
https://github.com/SAML-Toolkits/python3-saml/blob/6988bdab7a203abfe8dc264992f7e350c67aef3d/demo-flask/index.py
+    """
+
+    @cached_property
+    def idp_data(self) -> dict:
+        saml_metadata_url = conf.get_mandatory_value(CONF_SECTION_NAME, 
CONF_SAML_METADATA_URL_KEY)
+        return OneLogin_Saml2_IdPMetadataParser.parse_remote(saml_metadata_url)
+
+    @expose("/login")
+    def login(self):
+        """Start login process."""
+        saml_auth = self._init_saml_auth()
+        return redirect(saml_auth.login())
+
+    @expose("/logout")
+    def logout(self):
+        """Start logout process."""
+        session.clear()
+        saml_auth = self._init_saml_auth()
+
+        return redirect(saml_auth.logout())
+
+    @csrf.exempt

Review Comment:
   Just added a very simple comment. I only know I need to disable CSRF 
otherwise Identity center redirection wont work :)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@airflow.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to