Manifest.json does not contain right cookies and SSO not working on first login

We have Nextcloud behind F5 loadbalancer and have authentication on the F5 so the user gets SSO to Nextcloud from it (username provided in HTTP_UID header and then in httpd.conf it is matched to RewriteRule .* - [E=REMOTE_USER:%{HTTP:UID}] ).

Now as user first time ever goes to the site with SSO he does not get in with SSO but is presented with the Nexcloud login page. When viewing that with browsers developer tools i can see that all other resources the browser downloads have the correct cookies (MRHSession) but the manifest.json does not contain it so F5 starts a new access session for it. Any ideas why the cookies are disappearing with that resource been loaded?

Now if user types in credentials to the login page once and successfully gets in to Nextcloud the SSO starts working on following times the user visits the site so what is created on the first login? We have AD (LDAP) and i can see all the users populated to the Nextcloud database and folders created to /var/www/html/nextcloud/data/ .

So two different problems here and the one that needs more attention is the SSO not working on first time visiting the app. Any ideas anyone? I can give more detailed information of our setup if needed. We are currently using nextcloud version 21.0.1.

Is the oc_authtoken table entries something that Nexcloud generates on the first login? If so, how can i generate those database entries before user first time logs in?