Feat/webapp verified sso 260: fetch previous app session in public token exchange (#20740)

pull/20815/head
Xiyuan Chen 11 months ago committed by GitHub
parent 78cf376872
commit 512c1938c1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -113,7 +113,7 @@ def exchange_token_for_existing_web_user(app_code: str, enterprise_user_decoded:
app_auth_type = WebAppAuthService.get_app_auth_type(app_code=app_code) app_auth_type = WebAppAuthService.get_app_auth_type(app_code=app_code)
if app_auth_type == WebAppAuthType.PUBLIC: if app_auth_type == WebAppAuthType.PUBLIC:
return _exchange_for_public_app_token(app_model, site) return _exchange_for_public_app_token(app_model, site, enterprise_user_decoded)
elif app_auth_type == WebAppAuthType.EXTERNAL and user_auth_type != "external": elif app_auth_type == WebAppAuthType.EXTERNAL and user_auth_type != "external":
raise WebAppAuthRequiredError("Please login as external user.") raise WebAppAuthRequiredError("Please login as external user.")
elif app_auth_type == WebAppAuthType.INTERNAL and user_auth_type != "internal": elif app_auth_type == WebAppAuthType.INTERNAL and user_auth_type != "internal":
@ -164,17 +164,25 @@ def exchange_token_for_existing_web_user(app_code: str, enterprise_user_decoded:
} }
def _exchange_for_public_app_token(app_model, site): def _exchange_for_public_app_token(app_model, site, token_decoded):
end_user = EndUser( user_id = token_decoded.get("user_id")
tenant_id=app_model.tenant_id, end_user = None
app_id=app_model.id, if user_id:
type="browser", end_user = db.session.query(EndUser).filter(
is_anonymous=True, EndUser.app_id == app_model.id, EndUser.session_id == user_id
session_id=generate_session_id(), ).first()
)
if not end_user:
end_user = EndUser(
tenant_id=app_model.tenant_id,
app_id=app_model.id,
type="browser",
is_anonymous=True,
session_id=generate_session_id(),
)
db.session.add(end_user) db.session.add(end_user)
db.session.commit() db.session.commit()
payload = { payload = {
"iss": site.app_id, "iss": site.app_id,

Loading…
Cancel
Save