Custom Login Controller

Hi,
Im trying to create an app for automatic Login. So I read the Development Documentation, but cant figure out, how to actually login.
I made an controller and set the route, I also took the UserService Class/Service/Container. etz.

For simplicity i linked the route to the controller, which starts App/Container. For now i also “hard-coded” username and password. So when returning $userSession->login(“username”,“password” i get true if the pw is right and false if the pw is wrong. so basically the code seems to work. but i dont know what to do to actually login (that means getting redirected to the file-listing) i noticed, that no cookies are set. can anybody help me?

could you elaborate on what exactly you’re trying to achieve?

Hi Christoph,
I have some users and a preauthentification that sets cookies for authentificated users.
I’m trying to achive autologon in nextcloud, so the users dont have to login several times. the preauth-system is cookie-based, unfortunately no OAuth etc…

So ultimately i would like to have a mechanism like this:
Request (unauthentificated user) comes in, Nextcloud sends to login page. Here i would like to have a mechanism that checks for a certain cookie. if this is present, read the cookie and match the content against a usertable-variable i set in OC-settings. so i map a user and do auto-login.

what i already know:
Creating a public page and linking it to a controller where OC\Authetification\Login\LoginData and OC\Authetification\Login\Chain is extended i can login a user-uid with a password. I read the cookie with IRequest, make some mapping and then create an LoginData-object and call the Login-Chain-Method on it. As far as i understand the login-process the credentials are beeing checked and then some further nc_cookies are beeing set. So i would like to go “passwordless” - having an existing user-uid i would like to directly login the user - set session cookies etc. but did not find the right class for the task. can you help me out?

Second problem: right now i have this public page for authentification: is it posssible to call my function when the login-page is loaded? i read about hooks and middleware… But f.i. the pre_login()-hooks seems not to fit, since it again requires user-id and passwd… is there a better solution?