Hey,
does anyone managed to obtain a fedauth cookie for a publicly shared sharepoint link, i want to download the stuff behind it.
I´m getting a 403 when trying it without the fedauth cookie, which i stole from pythons request lib, but i dont know to obtain one for a publicly shared link and why i´m forced to even get one.
More info about fedauth: SharePoint authentication - SharePoint in Microsoft 365 | Microsoft Learn
here is my code:
sharepoint_download_link =
doc_api_link
|> Kernel.<>("?download=1")
case sharepoint_download_link
|> download_pdf() do
{:ok, file_content} ->
conn
|> send_download({:binary, file_content},
filename: "document.pdf",
disposition: :inline,
charset: "utf-8"
)
{:error, status_code, reason} ->
conn
|> put_status(status_code)
|> json(%{message: reason})
end
def download_pdf(pdf_url) do
headers =
[
# {"User-Agent", ~c"python-requests/2.32.2"},
# {~c"Accept-Encoding", "gzip, deflate"},
# {"Accept", "*/*"},
# {"Connection", ~c"keep-alive"},
{~c"Cookie",
~c"FedAuth="}
# {}'accept': 'application/json;odata=verbose'
]
case HTTPoison.get(pdf_url, headers, follow_redirect: true) do
{:ok, %HTTPoison.Response{status_code: status_code, body: body}} ->
case status_code do
200 ->
{:ok, body}
_ ->
Logger.error(
"Error downloading PDF from SharePoint. Status code: #{status_code}, Body: #{body}"
)
{:error, status_code, body}
end
{:error, %HTTPoison.Error{reason: reason}} ->
Logger.error("Error downloading PDF from SharePoint: #{reason}")
{:error, "Error downloading PDF: #{reason}"}
end
end
Thx