from curl_cffi import requests
import json
base='https://mein-portal-registrierung.baloise.de/auth'
s=requests.Session(impersonate='chrome')
ident={'X-Bug-Bounty':'dwbzn'}

def show(tag,r):
    print('\n###',tag,'id=',getattr(r,'toadex_exchange_id',None),'status=',r.status_code)
    print('headers', {k:v for k,v in r.headers.items() if k.lower() in ['location','set-cookie','www-authenticate','x-forward-url','content-type']})
    print(r.text[:10000])

r=s.get(base+'/ui/app',headers=ident,timeout=30);show('ui',r)
csrf=s.cookies.get('CSRFT759-S') or ''
common={**ident,'X-Same-Domain':'1','X-CSRFT759':csrf,'Accept':'application/json, application/vnd.api+json','Content-Type':'application/json'}
r=s.delete(base+'/rest/public/user-self-registration/flow',headers=common,timeout=30);show('delete flow',r)
r=s.post(base+'/rest/public/user-self-registration/default-flow/select',headers=common,data=b'null',timeout=30);show('default registration select',r)
# Also try generic registration config endpoints without changing flow.
for path in ['/rest/public/user-self-registration/selection/options/retrieve','/rest/public/user-self-registration/ui/on-completed/default','/rest/public/ui/static/configuration']:
    method='post' if path.endswith('retrieve') else 'get'
    rr=getattr(s,method)(base+path,headers=common,data=b'null' if method=='post' else None,timeout=30)
    show(path,rr)
