Error calling SynchronizeServerProjectData

Hi,

I receive this error in the API when I try to synchronize a project already uploaded to GS 2017 before (Studio 2015 SR3):

System.InvalidOperationException: No credentials specified for server 'http://XXXXXXX/'.
at Sdl.Enterprise2.Platform.Client.IdentityModel.IssuedTokenClientBase`1.CreateChannelFactory()
at Sdl.Enterprise2.Platform.Client.IdentityModel.IssuedTokenClientBase`1.GetProxy()
at Sdl.StudioServer.ProjectServer.Client.Service.InternalProjectServerClient.InitiateSynchronizationDataDownload(Guid projectId, Nullable`1 latestManifestTimestamp)
at Sdl.StudioServer.ProjectServer.Client.ProjectServerClient.InitiateSynchronizationDataDownload(Guid projectId, Nullable`1 latestManifestTimestamp)
at Sdl.ProjectServer.Commute.ProjectServerCommuteClient.DownloadSynchronizationPackageCore(Guid projectId, Stream packageStream, Nullable`1 latestPackageTimeStamp, EventHandler`1 progressEventHandler)
at Sdl.ProjectServer.Commute.ProjectServerCommuteClient.DownloadSynchronizationPackage(Guid projectId, Stream packageStream, DateTime latestPackageTimeStamp, EventHandler`1 progressEventHandler)
at Sdl.ProjectApi.Implementation.Server.ProjectSyncOperation.Execute()
at Sdl.ProjectApi.Implementation.Project.SynchronizeServerProjectData()
at Sdl.ProjectAutomation.FileBased.FileBasedProject.SynchronizeServerProjectData()

I tried adding the credential using _sdlProject.Credentials.AddCredential(), but it didn't help. 

Then I digged deeper, and found that the credentials should exist in the IdentityCache of ProjectServerClient of this project. I added the credential using reflection, and the Synchronization worked afterwards. But, of course, this is probably not a future-proof solution. Is there maybe a better way to do this?

Thanks,

Tamas