* feat(backend): implemented unzipping for http requests with gzip content-type * fix(tracker): rm unused import * change(tracker): configure automatic headers, compress anything bigger than 24k, add third party lib to list * feat(backend): using custom library for unzipping request body * feat(backend): added extra logs * feat(backend): more debug logs * feat(backend): added compression threshold to start request * change(tracker): support compressionThreshold in tracker * feat(backend): debug log for body content * feat(backend): removed debug logs in http methods * change(tracker): fix priority sending, remove dead code, * feat(backend): removed debug logs in http methods * Enable session encryption (#1121) * feat(backend): enable session encryption * feat(backend): fixed updated method name in failover algo * feat(backend): disable encryption by default * change(tracker): fix iframe network handling * change(ui): add toast for recording error * Encryption metrics (#1151) * feat(backend): added metric to measure the duration of session encryption * feat(backend): enabled ecnryption * feat(backend): fixed typo issue in packSession method * change(ui): change error toast for rec * change(ui): add tooltip for added live sessions * chore(helm): disabling redis string if not enabled (#1153) Signed-off-by: rjshrjndrn <rjshrjndrn@gmail.com> * change(player): fix typos; priority for 1st dom file * fix(player): priority and await for message processing * change(ui) - player improvements (#1164) * change(ui) - player - back button spacing * change(ui) - onboarding - changes * change(ui) - onboarding - changes * change(ui) - integrations gap-4 * change(ui) - install script copy button styles * change(ui) - copy button in account settings * fix(ui) - error details modal loader position * change(ui) - share popup styles * change(ui) - player improvements * change(ui) - player improvements - playback speed with menu * change(ui) - player improvements - current timezone * change(ui) - player improvements - autoplay options * fix(ui) - user sessions modal - navigation * feat(player): lazy JS DOM node creation; (need fixes for reaching full potential) * fix(player): drasticly reduce amount of node getter call during virtual node insertion * feat(player/VirtualDOM): OnloadVRoot & OnloadStyleSheet for lazy iframe innerContent initialisation & elimination of forceInsertion requirement in this case;; few renamings * style(player): few renamings; comments improved * feat(player/DOMManager): VirtualNodes insertion prioretization (for styles) * fix(player): cursor svg with light border for better visibility on dark backgrounds * change(ui) - session bookmarks remove from the list and copy options * chore(helm): Updating frontend image release (#1166) * chore(helm): Updating frontend image release * fix(helm): PG custom port Signed-off-by: rjshrjndrn <rjshrjndrn@gmail.com> --------- Signed-off-by: rjshrjndrn <rjshrjndrn@gmail.com> * fix(player): consider stringDict before any CreateDocument (fastfix) * style(player/DOMManager/safeCSSRules): depend on interfaces * fixup! fix(player): consider stringDict before any CreateDocument (fastfix) * fix(player): proper unmount * fix(helm): Variable override, prioriry to the user created one. (#1173) * fix(ui) - search url to wait for metadata to load * fix(tracker): optimise node counting * fix(tracker): changelog * fix(ui) - sessions reload (#1177) * fix(tracker): fix iframe network requests tracking * fix(ui) - check for error status and force logout (#1179) * fix(ui) - token expire * fix(ui) - token expire * change(player): manual decompression for encrypted files * change(player): detect gzip file after decoding * change(ui) - show projects in menu for all * [Storage] different order to compress and encrypt (#1182) * feat(backend): try to compress and encrypt in a new way * chore(helm): Update cors headers for http Signed-off-by: rjshrjndrn <rjshrjndrn@gmail.com> * fix(ui): fix assist tooltip * change(ui): add sleep icon for inactive assist users * fix(ui): fix player automatic jump and start issues * Update .env.sample * Update cli for fetch latest patches and kubeconfig file hierarchy (#1183) * chore(helm): Kubeconfig file hierarchy Signed-off-by: rjshrjndrn <rjshrjndrn@gmail.com> * chore(cli): openreplay -u fetches update from current version, unless flag set Signed-off-by: rjshrjndrn <rjshrjndrn@gmail.com> --------- Signed-off-by: rjshrjndrn <rjshrjndrn@gmail.com> * chore(cli): Updating comment (#1184) Signed-off-by: rjshrjndrn <rjshrjndrn@gmail.com> * chore(cli): Adding option to keep backup directories (#1185) Signed-off-by: rjshrjndrn <rjshrjndrn@gmail.com> * chore(cli): removing log message (#1186) Signed-off-by: rjshrjndrn <rjshrjndrn@gmail.com> * chore(cli): Updating comment (#1188) Signed-off-by: rjshrjndrn <rjshrjndrn@gmail.com> * chore(helm): Annotation inject order Signed-off-by: rjshrjndrn <rjshrjndrn@gmail.com> * fix(player): fix vroot context getter * feat(ui): display real session time * change(ui) - clearsearch styling on disable * change(ui) - session url changes * refactor(player/DOMManager): notMountedChildren rename * change(ui) - check if saved search present * change(ui) - player control icons and other changes * change(ui) - password validations * change(ui) - password validations * chore(helm): Override image pull policy (#1199) * change(ui) - player user steps improvements (#1201) * change(ui) - user steps * change(ui) - user steps * change(ui) - user steps * change(ui) - user steps - icon and other styles * fix(ui) - xray verticle line sync on resize * change(ui) - projects remove the status check * fix(cli): Proper git tag propegation (#1202) and logging of clone Signed-off-by: rjshrjndrn <rjshrjndrn@gmail.com> * Adding maintenance page * Improved session compression (#1200) * feat(backend): implemented new compression * chore(crons): Updating dockerfile Signed-off-by: rjshrjndrn <rjshrjndrn@gmail.com> * change(ui) - insights improvements * fix(ui) - url search params remove [] for keys * fix(player): fix dict reset * Remove message index from mob file (#1213) * feat(backend): removed message index from mob file messages * feat(backend): remove duplicated messages (by message index) * feat(backend): added MAX_INDEX at the begining of session to indicate a new version of mob file * feat(backend): added comments to code * change(ui): remove indexes from msgs * change(player): remove 8 byte skip for index * change(player): remove indexes * change(player): bugifx * change(tracker): update tests * change(tracker): remove batch writer changes * change(player): fix comments * feat(backend): updated go.mod file * change(player): change time str * feat(player): added mice trail * change(player): change trail color * change(player): change styles for buttons * chore(build): Don't commit chart change for ee patch (#1216) Signed-off-by: rjshrjndrn <rjshrjndrn@gmail.com> * change(ui) updated recaptcha lib - which causing an issue with state reading * change(ui) - no content icon updates from metadata and webhooks * change(player): make cursor icon bigger * fix(player): fix virtualization * fix(player): fix virtualization * fix(ui) - onboarding project edit * change(ui) - no content graphic for projects, and svg component changes * change(ui) - events filter placeholder * change(ui) - ui feedback on user steps * change(ui): add more detials to health status * [Storage] timestamp sorting and filtering (#1218) * feat(backend): combined sorting by index and timestamp * feat(backend): write the only last timestamp message in a row * change(ui) - textarea styles * change(ui) - button text color * change(ui): add more detials to health status * fix(ui): fix screen rec error handling * fix(ui): fix screen rec stopping * fix(tracker): fix q sender token mismatch during assist connection * change(ui) - assist recordings pagination api * change(ui) - assist recordings pagination api * fix(ui) - not popup conflict with timeline tooltip * Updating version * change(tracker): 7.0.0. set max amount on restarts for compression error * fix(ui) - active menu link * fix redis endpoint and chalice health endpoints (#1138) * chore(helm): Adding redis string from global config Signed-off-by: rjshrjndrn <rjshrjndrn@gmail.com> * fix(chalice): health check url for alerts and assist Signed-off-by: rjshrjndrn <rjshrjndrn@gmail.com> --------- Signed-off-by: rjshrjndrn <rjshrjndrn@gmail.com> * fix(ee): chalice health check (#1142) Signed-off-by: rjshrjndrn <rjshrjndrn@gmail.com> * chore(cli): Adding verbose logging (#1144) Signed-off-by: rjshrjndrn <rjshrjndrn@gmail.com> * chore(helm): Adding option for records bucket (#1146) Signed-off-by: rjshrjndrn <rjshrjndrn@gmail.com> * chore(build): Bump image version of frontend assets while building (#1149) Signed-off-by: rjshrjndrn <rjshrjndrn@gmail.com> * feat(chalice): fixed jobs execution * feat(chalice): configurable mobs expiration * feat(chalice): changes * feat(chalice): refactored Jobs feat(chalice): added limits on Jobs * chore(build): test patch branch * chore(build): testing EE cron-Jobs * Add files via upload (#1156) * Add files via upload (#1157) * chore(helm): Enabling redis string for helm template variable (#1159) fix #1158 Signed-off-by: rjshrjndrn <rjshrjndrn@gmail.com> * Changing default encryption to false (#1161) * Updated hero * feat(chalice): return all records if date is not specified * feat(chalice): refactored records list * Moving cli to scripts folder (#1196) * Revert "Moving cli to scripts folder (#1196)" (#1197) This reverts commitc947e48d99. * feat(chalice): support old FilterType * fix(ui) - alert form crash * fix(ui) - alert form crash * fix(ui) - assist menu status * Redshift connector (#1170) * Updated dependancies for redshift connector, changed os module for python-decouple module * Updated service and images * Updated message protocol, added exception for BatchMetadata when version is 0 (we apply old read method) * fixed load error from s3 to redshift. null values for string columns are now empty strings ("") * Added file test consumer_async.py: reads every 3 minutes kafka raw and send task in background to upload to cloud * Added method to skip messages that are not inserted to cloud * Added logs into consumer_async. Changed urls and issues in sessions table from list to string * Split between messages for sessions table and for events table * Updated redshift tables * Fixed small issue in query redshift_sessions.sql * Updated Dockerfiles. Cleaned logs of consumer_async. Updated/Fixed tables. Transformed Nan as NULL for VARCHAR columns * Added error handler for sql dropped connection * chore(docker): Optimize docker builds Signed-off-by: rjshrjndrn <rjshrjndrn@gmail.com> * Variables renamed * Adding compression libraries * Set default value of count events to 0 (instead of NULL) when event did not occur * Added support specific project tracking. Added PG handler to connect to sessions table * Added method to update values in db connection for sessions ended and restarted * Removing intelligent file copying * chore(connector): Build file Signed-off-by: rjshrjndrn <rjshrjndrn@gmail.com> * Adding connection pool for pg * Renaming and optimizing * Fixed issue of missing information of sessions --------- Signed-off-by: rjshrjndrn <rjshrjndrn@gmail.com> Co-authored-by: rjshrjndrn <rjshrjndrn@gmail.com> * fix(build): Parallel build Signed-off-by: rjshrjndrn <rjshrjndrn@gmail.com> * feat(chalice): changed release version feat(assist): changed release version feat(peers): changed release version feat(sourcemaps-reader): changed release version feat(chalice): enhanced health-check feat(DB): sessions_count table to keep status * feat(chalice): changed release version * feat(chalice): refactored projects code * feat(chalice): refactored projects code feat(chalice): sessions-check-flag every hour feat(chalice): sessions-check-delta set to 4 hours * feat(chalice): use experimental session search for metrics * feat(chalice): projects stats for health-check feat(DB): projects stats for health-check feat(crons): projects stats for health-check * feat(chalice): changed projects stats for health-check feat(crons): cahnged projects stats for health-check chore(helm): projectStats cron every 18 min chore(helm): projectStats-fix cron every Sunday at 5am * feat(crons): reorganized crons * feat(chalice): fixed typo * feat(chalice): changed health-check response * feat(crons): changed health-check response * (feat): Chalice - Allow SAML users to login with non-password methods as well as the usual password method, for example Windows Integrated Authentication * Move security field to correct area under SAML2 settings * feat(chalice): format code * feat(chalice): changed recordings response * feat(crons): fixed health check cron feat(crons): refactored main * feat(chalice): changed recordings response feat(chalice): updated dependencies feat(crons): updated dependencies feat(alerts): updated dependencies * feat(chalice): fixed recordings response recursion error * feat(assist): updated dependencies feat(sourcemaps-reader): upgraded dependencies * change(ui) - user event text change * fix(ui): fix events merging * fix(connector): handle db connection drop (#1223) * Added compatibility with SaaS, added reboot of connection if connection droped * Small fix * fix(backend): disabled debug log in http handler * fix(player): fix autopause on tabs * Updated python template to read messages with BatchMeta with old version (#1225) * change(ui) - user events text change * change(ui) - webhooks no content icon size * chore(backend): upgraded go to 1.19 and ClickHouse to 2.9.1 * fix(player): fix frustrations ingestion * fix(tracker): fix email detection performance * fix(tracker): fix email masking length * fix(player): fix fullview prop passing to children (live pl) * feat(chalice): reduce issues for replay (#1227) * change(ui) - bugreport modal title color * fix(ui) - elastic config validation rules * change(ui) - issue form and share popup titles * change(ui) - placeholder text change * change(ui) - filter user events text change * feat(chalice): include enforceSSO in signup status (#1228) * Updating kyverno * chore(cli): Override GH repo Signed-off-by: rjshrjndrn <rjshrjndrn@gmail.com> * chore(helm): Update kafka chart Enable metrics and increased storage * change(ui) - enforce sso * Api v1.12.0 (#1230) * feat(chalice): include enforceSSO in signup status * feat(chalice): changed 1-time health-check * fix(helm): typo Signed-off-by: rjshrjndrn <rjshrjndrn@gmail.com> * change(ui) - support icon border * chore(helm): enable kafka jmx metrics Signed-off-by: rjshrjndrn <rjshrjndrn@gmail.com> * change(ui) - fetch details modal - no content text size * change(ui) - playback timemode alignment * fix(connector): fixed bug of cache dict size error (#1226) * change(ui) - text chante on create issue and share popups * change(ui) - share popup styles * change(ui) - user events visit event padding * feat(crons): include fastapi (#1231) * New env variable CLOUD (aws by default) (#1232) * feat(backend): added new env variable CLOUD (aws by default) * chore(backend): Adding env variable for CLOUD Signed-off-by: rjshrjndrn <rjshrjndrn@gmail.com> --------- Signed-off-by: rjshrjndrn <rjshrjndrn@gmail.com> Co-authored-by: rjshrjndrn <rjshrjndrn@gmail.com> * Compression worker (#1233) * feat(backend): added extra worker for session compression * feat(backend): debug logs * feat(backend): added compression ratio metric * feat(backend): reduced number of duplicate logs * feat(backend): rewrite workers managment * chore(minio): changed lifecycle rules to support delete-jobs (#1235) * fix(backend): correct compression ratio value * fix(backend): reduced ender tick duration * feat(backend): insert referrer to sessions table (#1237) * chore(cli): Adding separate query for ee cleanup Signed-off-by: rjshrjndrn <rjshrjndrn@gmail.com> * fix(connector): Added checkpoints and sigterm handler (#1234) * fix(connector): fixed bug of cache dict size error * fix(connector): Added method to save state in s3 for redshift if sigterm arise * fix(connector): Added exit signal handler and checkpoint method * Added sslmode selection for connection to database, added use_ssl parameter for S3 connection * fix(cli): Override cli options (#1239) Signed-off-by: rjshrjndrn <rjshrjndrn@gmail.com> * fix(player): fix first 8 byte checker * fix(player): remove logs * Update .env.sample * fix(ui) - search init - wait for filters (#1241) * fix(player): fix first 8 byte checker * chore(cron): Adding missing deps Signed-off-by: rjshrjndrn <rjshrjndrn@gmail.com> * fix(player): fix commit conflict * fix(backend): added Content-Encoding to CORS for http service * fix(backend): added COMPRESSION_THRESHOLD env variable to Dockerfile * fix(player): ensure that player is cleaned on unmount * chore(helm): Updating frontend image release (#1243) * Update README.md * feat(chalice): fixed trace payload parsing * feat(player): player file loader refactoring (#1203) * change(ui): refactor mob loading * refactor(player): split message loader into separate file, remove toast dependency out of player lib, fix types, fix inspector and screen context * refactor(player): simplify file loading, add safe error throws * refactor(player): move loading status changers to the end of the flow * change(ui) - assist call to use iceTransportPolicy all * change(ui) - removed errors route * chore(helm): enablig pg_stat for metrics Signed-off-by: rjshrjndrn <rjshrjndrn@gmail.com> * fix(tracker): fix time inputs capturing * change(ui) - antd dependency * fix(player): clear selection manger on clicks; display frustrations row on xray by default * fix(player): add option todisable network in iframes * refactor(cli): In old clusters kyverno upgrade won't work. So we'll have to upgrade OR only. Signed-off-by: rjshrjndrn <rjshrjndrn@gmail.com> * feat(tracker): new axios capturing; tracker 7.0.1 * feat(chalice) - feature flags (#1252) * feat(api) - feature flags - schema * feat(api) - feature flags - wip * feat(api) - feature flags * feat(api) - feature flags - set back root path * feat(api) - feature flags * feat(api) - feature flags * feat(api) - feature flags - review * feat(DB): feature flags DB structure * feat(chalice): feature flags permissions support feat(chalice): feature flags changed code * feat(chalice): feature flags add permissions to DB --------- Co-authored-by: Taha Yassine Kraiem <tahayk2@gmail.com> * [sourcemaps-reader] Azure blob storage support (#1259) * feat(sourcemaps-reader): implemented azure blob storage support for sourcemaps reader * feat(sourcemaps-reader): azure blob storage support - cleaned code --------- Co-authored-by: Taha Yassine Kraiem <tahayk2@gmail.com> * fix(player): fix selection manager styles and reset * fix(cli): KUBECONFIG PATH override (#1266) Signed-off-by: rjshrjndrn <rjshrjndrn@gmail.com> * chore(cli): Adding info on which kubeconfig is getting used (#1261) Signed-off-by: rjshrjndrn <rjshrjndrn@gmail.com> * feat(ui) - enforce pwd during signup (#1271) * fix(helm): SITE_URL injection * fix(player): hide empty index prop * change(repo): ignore precommit config * change(repo): precommit config * feat(chalice): faster projects response * fix(chalice): ignore SSO for testing * feat(chalice): added PyLint for dev purposes * feat(DB): support tab_id for all events * feat(chalice): removed PyLint * fix(chalice): include metadata in sessions exp search (#1291) (cherry picked from commit07dd9da820) * refactor(chalice): upgraded dependencies refactor(alerts): upgraded dependencies refactor(crons): upgraded dependencies * feat(DB): added tab_id in creation queries feat(DB): added user_city feat(DB): added user_state * feat(DB): added user_city feat(DB): added user_state * feat(DB): create index for user_city feat(DB): create index for user_state * feat(chalice): search sessions by user_city feat(chalice): search sessions by user_state * fix(chalice): install SSO dependencies --------- Signed-off-by: rjshrjndrn <rjshrjndrn@gmail.com> Co-authored-by: Alexander Zavorotynskiy <zavorotynskiy@pm.me> Co-authored-by: nick-delirium <nikita@openreplay.com> Co-authored-by: Rajesh Rajendran <rjshrjndrn@users.noreply.github.com> Co-authored-by: Shekar Siri <sshekarsiri@gmail.com> Co-authored-by: Alex Kaminskii <alex@openreplay.com> Co-authored-by: rjshrjndrn <rjshrjndrn@gmail.com> Co-authored-by: Mehdi Osman <estradino@users.noreply.github.com> Co-authored-by: MauricioGarciaS <47052044+MauricioGarciaS@users.noreply.github.com> Co-authored-by: Dayan Graham <d.graham50@hotmail.co.uk>
250 lines
11 KiB
Python
250 lines
11 KiB
Python
# TODO: enable after xmlsec fix
|
|
from fastapi import HTTPException, Request, Response, status
|
|
|
|
# from chalicelib.utils import SAML2_helper
|
|
# from chalicelib.utils.SAML2_helper import prepare_request, init_saml_auth
|
|
from routers.base import get_routers
|
|
|
|
public_app, app, app_apikey = get_routers()
|
|
# from decouple import config
|
|
#
|
|
# from onelogin.saml2.auth import OneLogin_Saml2_Logout_Request
|
|
#
|
|
# from chalicelib.core import users, tenants, roles
|
|
# from starlette.responses import RedirectResponse
|
|
#
|
|
#
|
|
# @public_app.get("/sso/saml2", tags=["saml2"])
|
|
# @public_app.get("/sso/saml2/", tags=["saml2"])
|
|
# async def start_sso(request: Request):
|
|
# request.path = ''
|
|
# req = await prepare_request(request=request)
|
|
# auth = init_saml_auth(req)
|
|
# sso_built_url = auth.login()
|
|
# return RedirectResponse(url=sso_built_url)
|
|
#
|
|
#
|
|
# @public_app.post('/sso/saml2/acs', tags=["saml2"])
|
|
# @public_app.post('/sso/saml2/acs/', tags=["saml2"])
|
|
# async def process_sso_assertion(request: Request):
|
|
# req = await prepare_request(request=request)
|
|
# session = req["cookie"]["session"]
|
|
# auth = init_saml_auth(req)
|
|
#
|
|
# request_id = None
|
|
# if 'AuthNRequestID' in session:
|
|
# request_id = session['AuthNRequestID']
|
|
#
|
|
# auth.process_response(request_id=request_id)
|
|
# errors = auth.get_errors()
|
|
# user_data = {}
|
|
# if len(errors) == 0:
|
|
# if 'AuthNRequestID' in session:
|
|
# del session['AuthNRequestID']
|
|
# user_data = auth.get_attributes()
|
|
# elif auth.get_settings().is_debug_active():
|
|
# error_reason = auth.get_last_error_reason()
|
|
# print("SAML2 error:")
|
|
# print(error_reason)
|
|
# return {"errors": [error_reason]}
|
|
#
|
|
# email = auth.get_nameid()
|
|
# print("received nameId:")
|
|
# print(email)
|
|
# existing = users.get_by_email_only(auth.get_nameid())
|
|
#
|
|
# internal_id = next(iter(user_data.get("internalId", [])), None)
|
|
# tenant_key = user_data.get("tenantKey", [])
|
|
# if len(tenant_key) == 0:
|
|
# print("tenantKey not present in assertion, please check your SP-assertion-configuration")
|
|
# return {"errors": ["tenantKey not present in assertion, please check your SP-assertion-configuration"]}
|
|
# else:
|
|
# t = tenants.get_by_tenant_key(tenant_key[0])
|
|
# if t is None:
|
|
# print("invalid tenantKey, please copy the correct value from Preferences > Account")
|
|
# return {"errors": ["invalid tenantKey, please copy the correct value from Preferences > Account"]}
|
|
# print(user_data)
|
|
# role_name = user_data.get("role", [])
|
|
# if len(role_name) == 0:
|
|
# print("No role specified, setting role to member")
|
|
# role_name = ["member"]
|
|
# role_name = role_name[0]
|
|
# role = roles.get_role_by_name(tenant_id=t['tenantId'], name=role_name)
|
|
# if role is None:
|
|
# return {"errors": [f"role {role_name} not found, please create it in openreplay first"]}
|
|
#
|
|
# admin_privileges = user_data.get("adminPrivileges", [])
|
|
# admin_privileges = not (len(admin_privileges) == 0
|
|
# or admin_privileges[0] is None
|
|
# or admin_privileges[0].lower() == "false")
|
|
#
|
|
# if existing is None:
|
|
# deleted = users.get_deleted_user_by_email(auth.get_nameid())
|
|
# if deleted is not None:
|
|
# print("== restore deleted user ==")
|
|
# users.restore_sso_user(user_id=deleted["userId"], tenant_id=t['tenantId'], email=email,
|
|
# admin=admin_privileges, origin=SAML2_helper.get_saml2_provider(),
|
|
# name=" ".join(user_data.get("firstName", []) + user_data.get("lastName", [])),
|
|
# internal_id=internal_id, role_id=role["roleId"])
|
|
# else:
|
|
# print("== new user ==")
|
|
# users.create_sso_user(tenant_id=t['tenantId'], email=email, admin=admin_privileges,
|
|
# origin=SAML2_helper.get_saml2_provider(),
|
|
# name=" ".join(user_data.get("firstName", []) + user_data.get("lastName", [])),
|
|
# internal_id=internal_id, role_id=role["roleId"])
|
|
# else:
|
|
# if t['tenantId'] != existing["tenantId"]:
|
|
# print("user exists for a different tenant")
|
|
# return {"errors": ["user exists for a different tenant"]}
|
|
# if existing.get("origin") is None:
|
|
# print(f"== migrating user to {SAML2_helper.get_saml2_provider()} ==")
|
|
# users.update(tenant_id=t['tenantId'], user_id=existing["id"],
|
|
# changes={"origin": SAML2_helper.get_saml2_provider(), "internal_id": internal_id})
|
|
# expiration = auth.get_session_expiration()
|
|
# expiration = expiration if expiration is not None and expiration > 10 * 60 \
|
|
# else int(config("sso_exp_delta_seconds", cast=int, default=24 * 60 * 60))
|
|
# jwt = users.authenticate_sso(email=email, internal_id=internal_id, exp=expiration)
|
|
# if jwt is None:
|
|
# return {"errors": ["null JWT"]}
|
|
# return Response(
|
|
# status_code=status.HTTP_302_FOUND,
|
|
# headers={'Location': SAML2_helper.get_landing_URL(jwt)})
|
|
#
|
|
#
|
|
# @public_app.post('/sso/saml2/acs/{tenantKey}', tags=["saml2"])
|
|
# @public_app.post('/sso/saml2/acs/{tenantKey}/', tags=["saml2"])
|
|
# async def process_sso_assertion_tk(tenantKey: str, request: Request):
|
|
# req = await prepare_request(request=request)
|
|
# session = req["cookie"]["session"]
|
|
# auth = init_saml_auth(req)
|
|
#
|
|
# request_id = None
|
|
# if 'AuthNRequestID' in session:
|
|
# request_id = session['AuthNRequestID']
|
|
#
|
|
# auth.process_response(request_id=request_id)
|
|
# errors = auth.get_errors()
|
|
# user_data = {}
|
|
# if len(errors) == 0:
|
|
# if 'AuthNRequestID' in session:
|
|
# del session['AuthNRequestID']
|
|
# user_data = auth.get_attributes()
|
|
# elif auth.get_settings().is_debug_active():
|
|
# error_reason = auth.get_last_error_reason()
|
|
# print("SAML2 error:")
|
|
# print(error_reason)
|
|
# return {"errors": [error_reason]}
|
|
#
|
|
# email = auth.get_nameid()
|
|
# print("received nameId:")
|
|
# print(email)
|
|
# existing = users.get_by_email_only(auth.get_nameid())
|
|
#
|
|
# internal_id = next(iter(user_data.get("internalId", [])), None)
|
|
#
|
|
# t = tenants.get_by_tenant_key(tenantKey)
|
|
# if t is None:
|
|
# print("invalid tenantKey, please copy the correct value from Preferences > Account")
|
|
# return {"errors": ["invalid tenantKey, please copy the correct value from Preferences > Account"]}
|
|
# print(user_data)
|
|
# role_name = user_data.get("role", [])
|
|
# if len(role_name) == 0:
|
|
# print("No role specified, setting role to member")
|
|
# role_name = ["member"]
|
|
# role_name = role_name[0]
|
|
# role = roles.get_role_by_name(tenant_id=t['tenantId'], name=role_name)
|
|
# if role is None:
|
|
# return {"errors": [f"role {role_name} not found, please create it in openreplay first"]}
|
|
#
|
|
# admin_privileges = user_data.get("adminPrivileges", [])
|
|
# admin_privileges = not (len(admin_privileges) == 0
|
|
# or admin_privileges[0] is None
|
|
# or admin_privileges[0].lower() == "false")
|
|
#
|
|
# if existing is None:
|
|
# deleted = users.get_deleted_user_by_email(auth.get_nameid())
|
|
# if deleted is not None:
|
|
# print("== restore deleted user ==")
|
|
# users.restore_sso_user(user_id=deleted["userId"], tenant_id=t['tenantId'], email=email,
|
|
# admin=admin_privileges, origin=SAML2_helper.get_saml2_provider(),
|
|
# name=" ".join(user_data.get("firstName", []) + user_data.get("lastName", [])),
|
|
# internal_id=internal_id, role_id=role["roleId"])
|
|
# else:
|
|
# print("== new user ==")
|
|
# users.create_sso_user(tenant_id=t['tenantId'], email=email, admin=admin_privileges,
|
|
# origin=SAML2_helper.get_saml2_provider(),
|
|
# name=" ".join(user_data.get("firstName", []) + user_data.get("lastName", [])),
|
|
# internal_id=internal_id, role_id=role["roleId"])
|
|
# else:
|
|
# if t['tenantId'] != existing["tenantId"]:
|
|
# print("user exists for a different tenant")
|
|
# return {"errors": ["user exists for a different tenant"]}
|
|
# if existing.get("origin") is None:
|
|
# print(f"== migrating user to {SAML2_helper.get_saml2_provider()} ==")
|
|
# users.update(tenant_id=t['tenantId'], user_id=existing["id"],
|
|
# changes={"origin": SAML2_helper.get_saml2_provider(), "internal_id": internal_id})
|
|
# expiration = auth.get_session_expiration()
|
|
# expiration = expiration if expiration is not None and expiration > 10 * 60 \
|
|
# else int(config("sso_exp_delta_seconds", cast=int, default=24 * 60 * 60))
|
|
# jwt = users.authenticate_sso(email=email, internal_id=internal_id, exp=expiration)
|
|
# if jwt is None:
|
|
# return {"errors": ["null JWT"]}
|
|
# return Response(
|
|
# status_code=status.HTTP_302_FOUND,
|
|
# headers={'Location': SAML2_helper.get_landing_URL(jwt)})
|
|
#
|
|
#
|
|
# @public_app.get('/sso/saml2/sls', tags=["saml2"])
|
|
# @public_app.get('/sso/saml2/sls/', tags=["saml2"])
|
|
# async def process_sls_assertion(request: Request):
|
|
# req = await prepare_request(request=request)
|
|
# session = req["cookie"]["session"]
|
|
# auth = init_saml_auth(req)
|
|
# request_id = None
|
|
# if 'LogoutRequestID' in session:
|
|
# request_id = session['LogoutRequestID']
|
|
#
|
|
# def dscb():
|
|
# session.clear()
|
|
#
|
|
# url = auth.process_slo(request_id=request_id, delete_session_cb=dscb)
|
|
#
|
|
# errors = auth.get_errors()
|
|
# if len(errors) == 0:
|
|
# if 'SAMLRequest' in req['get_data']:
|
|
# logout_request = OneLogin_Saml2_Logout_Request(auth.get_settings(), req['get_data']['SAMLRequest'])
|
|
# user_email = logout_request.get_nameid(auth.get_last_request_xml())
|
|
# to_logout = users.get_by_email_only(user_email)
|
|
#
|
|
# if len(to_logout) > 0:
|
|
# to_logout = to_logout[0]['id']
|
|
# users.change_jwt_iat(to_logout)
|
|
# else:
|
|
# print("Unknown user SLS-Request By IdP")
|
|
# else:
|
|
# print("Preprocessed SLS-Request by SP")
|
|
#
|
|
# if url is not None:
|
|
# return RedirectResponse(url=url)
|
|
#
|
|
# return RedirectResponse(url=config("SITE_URL"))
|
|
#
|
|
#
|
|
# @public_app.get('/sso/saml2/metadata', tags=["saml2"])
|
|
# @public_app.get('/sso/saml2/metadata/', tags=["saml2"])
|
|
# async def saml2_metadata(request: Request):
|
|
# req = await prepare_request(request=request)
|
|
# auth = init_saml_auth(req)
|
|
# settings = auth.get_settings()
|
|
# metadata = settings.get_sp_metadata()
|
|
# errors = settings.validate_metadata(metadata)
|
|
#
|
|
# if len(errors) == 0:
|
|
# return Response(
|
|
# status_code=status.HTTP_200_OK,
|
|
# content=metadata,
|
|
# headers={'Content-Type': 'text/xml'})
|
|
# else:
|
|
# raise HTTPException(
|
|
# status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
|
# detail=', '.join(errors))
|