How to open Xwiki Attachment link from JS?

Hello, i have linkto attachment
https://xwiki.olimp.dev/bin/download/somepage/WebHome/somefile.yaml?rev=1.1
i closed my wiki for not login users
when i login and click on link it will be open file content,
but when i try to get if from js i see can’t read file becouse haven’tr acess right.

i found out what i need use authorization. How can i get current user login / password or user key from cookie header via Velocity?