Skip to content

Commit

Permalink
Add checklogin route
Browse files Browse the repository at this point in the history
  • Loading branch information
manisandro committed Jul 24, 2024
1 parent 32e9597 commit 3bfc8d1
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,37 @@ def login():
target_url = urlunparse(parts)
return make_response(redirect(target_url))

@app.route('/checklogin', methods=['GET'])
@optional_auth
def checklogin():
config_handler = RuntimeConfig("mysochAuth", app.logger)
tenant = tenant_handler.tenant()
config = config_handler.tenant_config(tenant)

identity = get_identity()
target_url = request.args.get('url')
if isinstance(identity, dict) and identity.get("user_infos", {}).get("mysoch", False):
tenant_header_name = config.get("tenant_header_name", "")
tenant_header_value = config.get("tenant_header_value", "")
parts = urlparse(target_url)
target_query = dict(parse_qsl(parts.query))
if tenant_header_name:
target_query.update({'config:tenant': tenant_header_name + "=" + tenant_header_value})
target_query.update({'config:autologin': 1})
parts = parts._replace(query=urlencode(target_query))
target_url = urlunparse(parts)
resp = make_response(redirect(target_url))
print(tenant_header_name + "=" + tenant_header_value)
if tenant_header_name:
app.logger.debug("Setting header %s=%s" % (tenant_header_name, tenant_header_value))
resp.headers[tenant_header_name] = tenant_header_value
return resp
else:
resp = make_response(redirect(target_url))
if identity:
unset_jwt_cookies(resp)
return resp

@app.route('/logout', methods=['GET'])
@optional_auth
def logout():
Expand Down

0 comments on commit 3bfc8d1

Please sign in to comment.