Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

Fix/token exp when exchange main (#26708)

Xiyuan Chenaead192743a4
diff --git a/api/controllers/web/passport.py b/api/controllers/web/passport.py
index 6f7105a7247..7190f06426f 100644
--- a/api/controllers/web/passport.py
+++ b/api/controllers/web/passport.py
@@ -126,6 +126,8 @@ def exchange_token_for_existing_web_user(app_code: str, enterprise_user_decoded:
end_user_id = enterprise_user_decoded.get("end_user_id")
session_id = enterprise_user_decoded.get("session_id")
user_auth_type = enterprise_user_decoded.get("auth_type")
+ exchanged_token_expires_unix = enterprise_user_decoded.get("exp")
+
if not user_auth_type:
raise Unauthorized("Missing auth_type in the token.")
@@ -169,8 +171,11 @@ def exchange_token_for_existing_web_user(app_code: str, enterprise_user_decoded:
)
db.session.add(end_user)
db.session.commit()
- exp_dt = datetime.now(UTC) + timedelta(minutes=dify_config.ACCESS_TOKEN_EXPIRE_MINUTES)
- exp = int(exp_dt.timestamp())
+
+ exp = int((datetime.now(UTC) + timedelta(minutes=dify_config.ACCESS_TOKEN_EXPIRE_MINUTES)).timestamp())
+ if exchanged_token_expires_unix:
+ exp = int(exchanged_token_expires_unix)
+
payload = {
"iss": site.id,
"sub": "Web API Passport",