Sets a token which gets used instead of generate one

@param string $token

@throws TokenException
552204
public function setToken(string $token)
    {
        if (empty($selector)) {
            Throw new TokenException('Empty tokens are not allowed.');
        }

        $this->token = $token;
    }
374601
public function unsetRefreshToken($token)
    {
        $refreshTokenDataMapper = $this->getTokenDataMapper(Entity\RefreshToken::class);

        $refreshToken = $refreshTokenDataMapper->findByToken($token);

        if (! $refreshToken instanceof Entity\RefreshToken) {
            throw new InvalidArgumentException('Invalid token provided');
        }

        $refreshTokenDataMapper->remove($refreshToken);
    }
981023
public function setToken($token)
    {
        $this->token = $token instanceof Token ? $token : new Token($token);

        return $this;
    }
655839
public function setOAuthToken(AccessToken $token)
    {
        $this->access_token = $token->getToken();
        $this->access_token_expiration = $token->getExpires();
        $this->refresh_token = $token->getRefreshToken();
        $this->role = $token->getValues()['role'];
    }
233151
public function setAccessToken($token)
    {
        if (is_string($token)) {
            $token = new Token($token);
        }
        Requestor::setToken($token);
    }
1257439
public function setTokens(array $tokens = [])
    {
        $session = \PHPSession::singleton();
        $session->setAttribute(self::TOKEN_KEY, $tokens);
    }
1368450
protected function _setToken($token)
    {
        //Prevents an empty value is serialized
        if (!$token) {
            return $token;
        }
        $token = is_string($token) ? $token : serialize($token);

        return substr(Security::hash($token, 'sha1', Configure::read('Tokens.tokenSalt')), 0, 25);
    }
852558
public function setToken($token, $tokenSecret)
    {
        $this->token = $token;
        $this->tokenSecret = $tokenSecret;

        return $this;
    }
455926
public function resetUpdate($token)
    {
        $user = new User();
        if ($token === 'NULL' || $user->isResetToken($token) !== true) {
            Error::set(__printl('auth:error:token'), 'token');
        }
        if ($this->fail() !== true) {
            Success::set(true);
        }
    }
189158
public function tokenLoginAction($token)
    {
        $newSessionId = $this->loginTokenCache->get($token);
        $this->loginTokenCache->remove($token);

        if ($newSessionId === false) {
            $this->systemLogger->log(sprintf('Token-based login failed, non-existing or expired token %s', $token), LOG_WARNING);
            $this->redirect('index');
        }

        $this->systemLogger->log(sprintf('Token-based login succeeded, token %s', $token), LOG_DEBUG);

        $newSession = $this->sessionManager->getSession($newSessionId);
        if ($newSession->canBeResumed()) {
            $newSession->resume();
        }
        if ($newSession->isStarted()) {
            $newSession->putData('lastVisitedNode', null);
        } else {
            $this->systemLogger->log(sprintf('Failed resuming or starting session %s which was referred to in the login token %s.', $newSessionId, $token), LOG_ERR);
        }

        $this->replaceSessionCookie($newSessionId);
        $this->redirect('index', 'Backend\Backend');
    }
457718
public function authenticate($username, $token) {
        if (empty($username) || empty($token)) {
            throw new \ErrorException('No username or token supplied.');
        }
        
        $this->username = $username;
        $this->token = $token;
    }
268566
protected function store_token($token) {
        if (!$this->system) {
            parent::store_token($token);
            return;
        }

        $this->accesstoken = $token;

        // Create or update a DB record with the new token.
        $persistedtoken = access_token::get_record(['issuerid' => $this->issuer->get('id')]);
        if ($token !== null) {
            if (!$persistedtoken) {
                $persistedtoken = new access_token();
                $persistedtoken->set('issuerid', $this->issuer->get('id'));
            }
            // Update values from $token. Don't use from_record because that would skip validation.
            $persistedtoken->set('token', $token->token);
            if (isset($token->expires)) {
                $persistedtoken->set('expires', $token->expires);
            } else {
                // Assume an arbitrary time span of 1 week for access tokens without expiration.
                // The "refresh_system_tokens_task" is run hourly (by default), so the token probably won't last that long.
                $persistedtoken->set('expires', time() + WEEKSECS);
            }
            $persistedtoken->set('scope', $token->scope);
            $persistedtoken->save();
        } else {
            if ($persistedtoken) {
                $persistedtoken->delete();
            }
        }
    }
1233971
public function setCookieToken($token)
    {
        $this->cookieToken = $token; // Remember this for this request.
        $encrypted = Encryption::encrypt($token, $this->config->getSecretKey()); // Encrypt token.

        // Set cookie on client.
        setcookie($this->config->getCookieName(),
            $encrypted,
            time() + $this->config->getTokenTtl(),
            '/',
            '',
            $this->config->getCookieSslOnly(),
            $this->config->getCookieHttpOnly()); // Store in cookie.
    }
619674
public function setToken($token)
    {
        $token = trim($token);

        $this->isChanged('token', $token);

        $this->token = $token;

        return $this;
    }
1308114
protected function clearToken($token)
    {
        $token = $this->tokenize($token);
        $this->checkToken($token);
        $this->tokens[$token] = array();
    }
464005
public function reset($token=null, $data=null)
    {
        $form_name = $this->getDefaultFormName();
        $token || $token = isset($_POST[$form_name]) ? $_POST[$form_name] : (isset($_GET[$form_name]) ? $_GET[$form_name] : null);
        
        parent::reset($token, $data);
    }
424358
protected function assertErrorToken(Token $token)
    {
        if (!$token->isError()) {
            return $this;
        }
        switch ($token->getType()) {
            case Token::TYPE_ERROR_INVALID_ESCAPE:
                throw new SyntaxException(
                    "Invalid escape sequence at position #{$this->getNextPosition()}",
                    $this->getNextPosition()
                );

            default:
                throw new UnknownSyntaxException(
                    "Unknown type of error token: {$token->getType()} at position #{$this->getNextPosition()}",
                    $this->getNextPosition()
                );
        }
    }