I have a custom SPE script that is executed from the Reporting Tools on the Sitecore start menu. The script writes a csv file to the app_data\temp directory, then calls Get-Item $filePath | Out-Download to download the file.
Recently, I've found that the file is no longer downloading and returning the following error : "Attempt to call the 'handleDownload' service failed as user 'xxxx\Anonymous' was not authorized."
I'm logged in as sitecore\Admin to run the script, so i'm not sure how i'm getting the anonymous user account.
During investigation, as the script completes in the browser while viewing the dev console, it appears to redirect to the login page with a returnUrl parameter in the query string:
"/login?ReturnUrl=%2f-%2fscript%2fhandle%2fAA8204B5D76D425A850C69B12D6CFE38"
The script was originally written in Sitecore 8.x and SPE 4.7. Now running 9.1 and SPE 5.1.
Has anyone experienced this behavior? Or maybe I missed some configuration with the new version. handleDownload is enabled to the default roles.