I have an application, which uses com.microsoft.graph.requests.GraphServiceClient (microsoft-graph artifact version 5.28.0) for downloading files from SharePoint. I construct my GraphServiceClient instance with pfx certificate through ClientCertificateCredentialBuilder.
I then pass those credentials into TokenCredentialAuthProvider with the list of scopes and use it to build my client.
I then use the client to download the content of file through its sharing URL.
String encodeUrl = getEncodedUrlForShare(sharingUrl);
InputStream content = graphClient.shares(encodedUrl)
Unfortunately, I'm intermittently getting this error when trying to download an existing file:
(ClientCertificateCredential) - Azure Identity => getToken() result for scopes [https://graph.microsoft.com/.default]: SUCCESS
SEVERE: CoreHttpProvider[sendRequestInternal] - 408Graph service exception
SEVERE: Throwable detail: com.microsoft.graph.http.GraphServiceException: Error code: unauthenticated
Error message: The caller is not authenticated
SdkVersion : graph-java/v5.28.0
[Some information was truncated for brevity, enable debug logging for more details]
What's interesting is that when I try to download the file A.pdf, it fails with this error and if I try it once again immediately after error, it's successful.
My app has Read-Write permissions for the sites, in which my files are located.
I tried to set Thread.sleep, but it didn't help - still the first attempt is unsuccessful.
I'm also thinking about repeating this request until it succeeds, but want to know, what's the root cause and if there's any better solution.