vincbeck commented on code in PR #51657:
URL: https://github.com/apache/airflow/pull/51657#discussion_r2228692961
##########
airflow-core/src/airflow/api_fastapi/core_api/routes/public/auth.py:
##########
@@ -55,3 +55,23 @@ def logout(request: Request, next: None | str = None) ->
RedirectResponse:
logout_url = request.app.state.auth_manager.get_url_login()
return RedirectResponse(logout_url)
+
+
+@auth_router.get(
+ "/refresh",
+
responses=create_openapi_http_exception_doc([status.HTTP_307_TEMPORARY_REDIRECT]),
+)
+def refresh(request: Request, next: None | str = None) -> RedirectResponse:
+ """Refresh the authentication token."""
+ refresh_url = request.app.state.auth_manager.get_url_refresh()
+
+ if not refresh_url:
+ return
RedirectResponse(request.app.state.auth_manager.get_url_logout())
Review Comment:
There is a route in core Airflow for logout, you should redirect to this
one. It uses underneath the `get_url_logout` form auth manager
##########
providers/keycloak/src/airflow/providers/keycloak/auth_manager/routes/login.py:
##########
@@ -70,3 +72,25 @@ def login_callback(request: Request):
secure = bool(conf.get("api", "ssl_cert", fallback=""))
response.set_cookie(COOKIE_NAME_JWT_TOKEN, token, secure=secure)
return response
+
+
+@login_router.get("/refresh")
+def refresh(
+ request: Request, user: Annotated[KeycloakAuthManagerUser,
Depends(get_user)]
+) -> RedirectResponse:
+ """Refresh the token."""
+ client = KeycloakAuthManager.get_keycloak_client()
+
+ if not user or not user.refresh_token:
+ raise HTTPException(status_code=400, detail="User is empty or has no
refresh token")
+
+ tokens = client.refresh_token(user.refresh_token)
+ user.refresh_token = tokens["refresh_token"]
Review Comment:
You should update the access_token as well, that's the main purpose :)
--
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]