from curl_cffi import requests
import json
BASE='https://va.baloise.de/auth'
H={'X-Bug-Bounty':'dwbzn'}
s=requests.Session(impersonate='chrome')
r=s.get(BASE+'/ui/app',headers=H,allow_redirects=False,timeout=30)
csrf=s.cookies.get('CSRFT759-S') or ''
h={**H,'X-Same-Domain':'1','X-CSRFT759':csrf,'Accept':'application/json, application/vnd.api+json','Content-Type':'application/json'}
def show(stage,r):
    try: body=r.json()
    except Exception: body=r.text[:2000]
    print(json.dumps({'stage':stage,'status':r.status_code,'exchange':getattr(r,'toadex_exchange_id',None),'location':r.headers.get('Location'),'x_forward_url':r.headers.get('X-Forward-URL'),'body':body},ensure_ascii=False))
show('init',r)
r=s.post(BASE+'/rest/public/authentication/location/access',headers=h,data=json.dumps({'location':'https://va.baloise.de/SASJobExecution/'}),allow_redirects=False,timeout=30)
show('start',r)
r=s.post(BASE+'/rest/public/authentication/dynamic-steps/retrieve',headers=h,data='',allow_redirects=False,timeout=30)
show('retrieve-before',r)
r=s.post(BASE+'/rest/public/authentication/dynamic-steps/portal-redirect/activate',headers=h,data='',allow_redirects=False,timeout=30)
show('activate',r)
r=s.post(BASE+'/rest/public/authentication/dynamic-steps/retrieve',headers=h,data='',allow_redirects=False,timeout=30)
show('retrieve-after',r)
r=s.get(BASE+'/rest/public/flow',headers=h,allow_redirects=False,timeout=30)
show('flow-after',r)
