Fix OAuth based replication

Hi,

sorry for such an ugly pull request, but it's intention is to actually open an issue and provide a salvation for the issue that results in a failing OAuth based replication.