ashb commented on a change in pull request #14219:
URL: https://github.com/apache/airflow/pull/14219#discussion_r599465261



##########
File path: airflow/api_connexion/openapi/v1.yaml
##########
@@ -1490,6 +1490,48 @@ paths:
         '404':
           $ref: '#/components/responses/NotFound'
 
+  /login:
+    post:
+      summary: Webserver login
+      description: |
+        Verify user and set jwt token in cookies
+      x-openapi-router-controller: 
airflow.api_connexion.endpoints.auth_endpoint
+      operationId: login
+      tags: [WebserverAuth]
+
+      responses:
+        '200':
+          description: Success.
+          content:
+            application/json:
+              schema:
+                $ref: '#/components/schemas/User'
+        '400':
+          $ref: '#/components/responses/BadRequest'
+        '401':
+          $ref: '#/components/responses/Unauthenticated'
+
+  /logout:
+    post:
+      summary: Webserver logout
+      description: Logout user by unsetting cookies
+      x-openapi-router-controller: 
airflow.api_connexion.endpoints.auth_endpoint
+      operationId: logout
+      tags: [WebserverAuth]

Review comment:
       ```suggestion
         tags: [Authentication]
   ```

##########
File path: airflow/api_connexion/webserver_auth.py
##########
@@ -0,0 +1,57 @@
+# 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.
+
+import logging
+from typing import Callable, TypeVar
+
+from flask import current_app, request
+from flask_appbuilder.const import AUTH_LDAP
+from flask_jwt_extended import verify_jwt_in_request
+from flask_login import login_user
+
+from airflow.configuration import conf
+
+SECRET = conf.get("webserver", "secret_key")
+T = TypeVar("T", bound=Callable)  # pylint: disable=invalid-name
+
+log = logging.getLogger(__name__)
+
+
+def auth_current_user():

Review comment:
       This isn't strictly only tied to webserver use of the API, so lets have 
this function live in security.py

##########
File path: airflow/api_connexion/security.py
##########
@@ -14,24 +14,27 @@
 # KIND, either express or implied.  See the License for the
 # specific language governing permissions and limitations
 # under the License.
-
 from functools import wraps
 from typing import Callable, Optional, Sequence, Tuple, TypeVar, cast
 
 from flask import Response, current_app
 
 from airflow.api_connexion.exceptions import PermissionDenied, Unauthenticated
+from airflow.api_connexion.webserver_auth import auth_current_user
 
 T = TypeVar("T", bound=Callable)  # pylint: disable=invalid-name
 
 
 def check_authentication() -> None:
     """Checks that the request has valid authorization information."""
     response = current_app.api_auth.requires_authentication(Response)()
-    if response.status_code != 200:
-        # since this handler only checks authentication, not authorization,
-        # we should always return 401
-        raise Unauthenticated(headers=response.headers)
+    if response.status_code == 200:
+        return
+    if auth_current_user():

Review comment:
       By having this here, it means that any/all requests would accept and 
process `Authorization` headers, which is probably not what we want?

##########
File path: airflow/api_connexion/openapi/v1.yaml
##########
@@ -1490,6 +1490,48 @@ paths:
         '404':
           $ref: '#/components/responses/NotFound'
 
+  /login:
+    post:
+      summary: Webserver login
+      description: |
+        Verify user and set jwt token in cookies
+      x-openapi-router-controller: 
airflow.api_connexion.endpoints.auth_endpoint
+      operationId: login
+      tags: [WebserverAuth]

Review comment:
       ```suggestion
         tags: [Authentication]
   ```




-- 
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.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to