Redirection Loop due to automatic Login

I am trying to write an authentication backend. After writing an authentication backend I am now trying to use a Cookie set by another application on the same domain. I tried to login a user like this:

        if ($user = $userManager->get($uid)) {
                $userSession->completeLogin($user, ['loginName'=>$uid, 'password'=>'Hallo Welt']);
                Util::writeLog('crowdsso', 'Logging in '. $user->getUid(), Util::DEBUG);
        };

I think the password in the loginDetails is not important, but I have no way to know for sure. My problem now is that this code triggers a redirection loop between two urls, each generating a new session…

Any ideas?