Airship\Engine\Security\Authentication::rotateToken PHP Method

rotateToken() public method

Replace the existing long-term authentication cookie
public rotateToken ( string $token, integer $userId ) : mixed
$token string
$userId integer
return mixed
    public function rotateToken(string $token, int $userId = 0)
    {
        try {
            $decoded = Base64::decode($token);
        } catch (\RangeException $ex) {
            return false;
        }
        if ($decoded === false) {
            return false;
        } elseif (Binary::safeStrlen($decoded) !== self::LONG_TERM_AUTH_BYTES) {
            return false;
        }
        $sel = Binary::safeSubstr($decoded, 0, self::SELECTOR_BYTES);
        \Sodium\memzero($decoded);
        // Delete the old token
        $this->db->delete($this->tableConfig['table']['longterm'], [$this->tableConfig['fields']['longterm']['selector'] => Base64::encode($sel)]);
        // Let's get a new token
        return $this->createAuthToken($userId);
    }