src/Controller/Component/AuthUtilsComponent.php
public function autoLogin(EntityInterface $user): ?Response
    {
        $controller = $this->getController();
        $request = $controller->request;
        $token = $request->getQuery('t');
        if (empty($token)) {
            return null;
        }

        $this->Auth->logout();
        $tokenData = $user->validateLoginToken($token, $user->getKey(), $user->getSalt());
        if (!is_array($tokenData)) {
            return null;
        }
        if (!empty($tokenData['addRememberMeCookie']) && $tokenData['addRememberMeCookie']) {
            $this->addRememberMeCookie((string)$user->id);
        }
        $userData = $user->toArray();
        $userData['user'] = $user;
        $this->Auth->setUser($userData);
        if (!empty($tokenData['url'])) {
            return $controller->redirect($tokenData['url']);
        }

        return $controller->redirect($this->getConfig('defaultRedirect'));
    }
public function autoLogin(EntityInterface $user): ?Response
    {
        $controller = $this->getController();
        $request = $controller->request;
        $token = $request->getQuery('t');
        if (empty($token)) {
            return null;
        }

        $this->Auth->logout();
        $tokenData = $user->validateLoginToken($token, $user->getKey(), $user->getSalt());
        if (!is_array($tokenData)) {
            return null;
        }
        if (!empty($tokenData['addRememberMeCookie']) && $tokenData['addRememberMeCookie']) {
            $this->addRememberMeCookie((string)$user->id);
        }
        $userData = $user->toArray();
        $userData['user'] = $user;
        $this->Auth->setUser($userData);
        if (!empty($tokenData['url'])) {
            return $controller->redirect($tokenData['url']);
        }

        return $controller->redirect($this->getConfig('defaultRedirect'));
    }
Attempts to auto login a user and returns a redirect on success.

@param \Cake\Datasource\EntityInterface $user User
@return \Cake\Http\Response|null