baptistegh commented on code in PR #75913:
URL: https://github.com/apache/airflow/pull/75913#discussion_r4617939485


##########
providers/keycloak/src/airflow/providers/keycloak/auth_manager/routes/login.py:
##########
@@ -112,6 +111,48 @@ def login(request: Request) -> RedirectResponse:
     return response
 
 
+@login_router.get(
+    "/login/cli",
+    responses=create_openapi_http_exception_doc(
+        [
+            status.HTTP_307_TEMPORARY_REDIRECT,
+            status.HTTP_400_BAD_REQUEST,
+            status.HTTP_503_SERVICE_UNAVAILABLE,
+        ]
+    ),
+)
+def login_cli(
+    redirect_uri: str,
+    state: Annotated[str, Query(min_length=1, max_length=512)],
+    # An S256 challenge is 43 base64url characters. ``auth_url`` does not 
encode its parameters,
+    # so nothing else may reach it.
+    code_challenge: Annotated[str, Query(pattern=r"^[A-Za-z0-9_-]{43}$")],
+    code_challenge_method: Literal["S256"],
+) -> RedirectResponse:
+    """Start the browser login of a command-line client."""
+    if not is_cli_authorization_code_enabled():
+        raise HTTPException(
+            status_code=status.HTTP_400_BAD_REQUEST,
+            detail="Browser login is not enabled for command-line clients",
+        )
+    if not is_cli_loopback_redirect_uri(redirect_uri):
+        raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, 
detail="Invalid redirect_uri")
+
+    client = KeycloakAuthManager.get_keycloak_client()
+    try:
+        # Fetches Keycloak's OpenID configuration.
+        auth_url = client.auth_url(
+            redirect_uri=quote(redirect_uri, safe=""),
+            scope="openid",
+            state=quote(state, safe=""),
+            code_challenge=code_challenge,
+            code_challenge_method=code_challenge_method,
+        )
+    except KeycloakConnectionError:

Review Comment:
   Follow up: #77252 



-- 
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: [email protected]

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

Reply via email to