Generates the auth token parts, stores them database and returns them

@throws TokenException

@return array
351319
public function generate(): string
    {
        $this->removeExpiredTokens();

        if (empty($this->id)) {
            Throw new TokenException('Cannot create AuthToken for empty id.');
        }

        // Create selector
        $selector = bin2hex($this->getSelector());

        // Create token
        $token = hash('sha256', $this->getToken());

        // Store selector and tokenb in DB
        $this->db->qb([
            'table' => 'core_auth_tokens',
            'method' => 'INSERT',
            'primary' => 'id_auth_token',
            'data' => [
                'selector' => $selector,
                'token' => $token,
                'id' => $this->id,
                'expires' => $this->expires_datetime
            ]
        ], true);

        // Set autologin token cookie only when token is stored successfully in db!!!
        if (empty($this->db->lastInsertId())) {

            $msg = 'AuthToken could not be stored in database.';

            if (isset($this->logger)) {
                $this->logger->warning($msg, __METHOD__);
            }

            Throw new TokenException($msg);

        }

        return $selector . ':' . $token;
    }
594496
public function getTokenName()
    {
        $session = \PHPSession::singleton();

        if ($session->hasAttribute(TokenStore::TOKEN_NAME)) {
            $name = $session->getAttribute(TokenStore::TOKEN_NAME);
        } else {
            $name = 'tao_' . substr(md5(microtime()), rand(0, 25), 7);
            $session->setAttribute(TokenStore::TOKEN_NAME, $name);
        }

        return $name;
    }
1040582
public function dumpTokens() {
		$result = "";
		foreach ($this->tokens as $token) {
			$result .= $token->toString() . PHP_EOL;
		}
		return $result;
	}
57378
public function getTokens(): array
    {
        $response = $this
            ->httpClient
            ->get(
                sprintf(
                    '/%s/tokens',
                    $this->getAppUUID()->getId()
                ),
                'get',
                [],
                [],
                Http::getApisearchHeaders($this)
            );

        self::throwTransportableExceptionIfNeeded($response);

        return array_map(function (array $token) {
            return Token::createFromArray($token);
        }, $response['body']);
    }
940969
public function token()
    {
        if(!$this->session->has('token')) {
            $this->session->create('token', Str::random(40));
        }

        return $this->session->get('token');
    }
793251
public function tokens()
    {
        return $this->hasMany(Token::class, 'user_id')
            ->join('oauth_access_token_providers', function ($join) {
                $join->on(
                    'oauth_access_tokens.id', '=', 'oauth_access_token_id'
                )->where('oauth_access_token_providers.provider', '=', AuthConfigHelper::getUserProvider($this));
            })->orderBy('created_at', 'desc')
            ->select('oauth_access_tokens.*')
            ->get();
    }
464873
public function generateToken()
    {
        do {
            $token = sha1(microtime());
        } while ($this->newQuery()->where(['token' => $token])->count() > 0);

        return $token;
    }
592851
public function getTokenString()
    {
        $cacheId = $this->getCacheId();

        if ($this->cache && $data = $this->cache->fetch($cacheId)) {
            return $data['access_token'];
        }

        $response = $this->getTokenResponse();

        if ($this->cache) {
            $this->cache->save($cacheId, $response, $response['expires_in']);
        }

        return $response['access_token'];
    }
285651
public static function getToken()
    {
        $token = self::getSessionToken();
        if (is_null($token)) {
            $nonce = self::generateNonce();
            self::setSessionToken($nonce);

        // Handle old tokens (< 2.6.0)
        } elseif (is_array($token)) {
            $nonce = key($token);
            self::setSessionToken($nonce);

        // New style tokens
        } else {
            $nonce = $token;
        }

        return $nonce;
    }
1234619
private static function create_login_token() {
        global $SESSION;

        $state = [
            'token' => random_string(32),
            'created' => time() // Server time - not user time.
        ];

        if (!isset($SESSION->logintoken)) {
            $SESSION->logintoken = [];
        }

        // Overwrite any previous values.
        $SESSION->logintoken[self::$logintokenkey] = $state;

        return $state;
    }
74964
public function getToken()
    {
        if (!$this->token) {
            $session = new Session('Auth');
            if (!$session->token) {
                $session->token = uniqid();
            }
            $this->token = $session->token;
        }
        return $this->token;
    }
782547
protected function getTokens()
    {
        if ($this->tokens === null) {
            $this->tokens = $this->parsePattern($this->pattern);
        }

        return $this->tokens;
    }
264093
public function generate()
    {
        $pickChars = str_repeat(static::DICTIONARY, static::LENGTH);
        for (; ;) {
            $value = substr(str_shuffle($pickChars), 0, static::LENGTH);
            if (preg_match(static::TOKEN_GENERATION_REGEX, $value)) {
                $this->insertQuery->execute([$value]);
                if ($this->insertQuery->rowCount() === 1) {
                    break;
                }
            }
        }

        return $value;
    }
880464
public function getTokens()
    {
        $tokens = [];

        foreach ($this as $device) {
            $tokens[] = $device->getToken();
        }

        return array_unique(array_filter($tokens));
    }
1005935
public function generateToken()
    {
        // Generate token from unique input
        $generator = new RandomNumberGenerator();
        $time      = microtime(true);
        $salt      = $generator->generate();

        return sha1($time.$salt);
    }
685738
public function getAndStoreToken()
    {
        $token = $this->generateToken(6);
        
        $this->setAttribute('secure_token', sha1($token));
        $this->setAttribute('secure_token_timestamp', time());
        $this->update(false);

        return $token;
    }
1159964
public function getTokenData()
    {
        if(!$this->has('token')) {
            throw new MissingTokenException(sprintf('No token available in \''.Config::get('forrest.storage.type').'\' storage'));
        }

        $token = $this->get('token');

        return Crypt::decrypt($token);
    }