Handles generating tokens for clients.

@return $this The current object.
167715
public function token()
    {
        // Handle the token request
        $response = $this->tokenServer->handleTokenRequest(\OAuth2\Request::createFromGlobals());

        // Get the data as json and convert it to an array,
        // - so we can set our own response type.
        $data = $response->getResponseBody('json');
        $data = json_decode($data, true);

        // Set the response, status code and output content setting final output to true
        $this->response = $data;
        $this->statusCode = $response->getStatusCode();
        $this->output(true);
        return $this;
    }
832041
public static function generateToken() {
        if (self::$token == NULL) {
            if (session()->has('token')) {
                session()->delete('token');
            }
            self::$token = base64_encode(openssl_random_pseudo_bytes(32));
            session()->set('token', self::$token);
        }

        return self::$token;
    }
1040151
private function tokens(): void
    {
        foreach ($this->attributes as $attribute => $value) {
            switch ($attribute) {
                case Options::ATTRIBUTE_BOLD:
                    $this->tokens[] = Options::MARKDOWN_TOKEN_BOLD;
                    break;

                case Options::ATTRIBUTE_ITALIC:
                    $this->tokens[] = Options::MARKDOWN_TOKEN_ITALIC;
                    break;

                default:
                    break;
            }
        }
    }
931478
protected function setTokenSettings()
    {
        // Set token lifetime
        $this->tokenLifetime = config('nodes.api.auth.userToken.lifetime', null);

        // Set token table
        $this->tokenTable = $tokenTable = config('nodes.api.auth.userToken.table', 'user_tokens');

        // Set token columns used in condition
        $columns = config('nodes.api.auth.userToken.columns', [
            'user_id' => 'user_id',
            'token' => 'token',
            'expire' => 'expire',
        ]);

        // Prepend token table name to token columns
        foreach ($columns as $key => $field) {
            $this->tokenColumns[$key] = $tokenTable.'.'.$field;
        }

        return $this;
    }
301133
public function createToken()
    {
        $time = microtime(true);
        $token = $this->generate();

        $store = $this->getStore();

        $pool = $this->invalidate($store->getTokens());

        $pool[] = [
            'ts' => $time,
            'token' => $token
        ];

        $store->setTokens($pool);

        return $token;
    }
876962
public function tokenAction()
    {
        $request = $this->getRequest();
        if (! $request instanceof HttpRequest) {
            // not an HTTP request; nothing left to do
            return;
        }

        if ($request->isOptions()) {
            // OPTIONS request.
            // This is most likely a CORS attempt; as such, pass the response on.
            return $this->getResponse();
        }

        $oauth2request = $this->getOAuth2Request();
        
        $response = $this->server->handleTokenRequest($oauth2request);
        if ($response->isClientError()) {
            $parameters = $response->getParameters();
            $errorUri   = isset($parameters['error_uri']) ? $parameters['error_uri'] : null;
            return new ApiProblemResponse(
                new ApiProblem(
                    $response->getStatusCode(),
                    $parameters['error_description'],
                    $errorUri,
                    $parameters['error']
                )
            );
        }
        return $this->setHttpResponse($response);
    }
135393
public function save() {

        if(!$this->hasToken()) {
            if (static::hasSingleToken()) {
                $this->setToken(static::getSingleToken());
            } else {
                $this->generateToken();
            }
        }

        if (!$this->hasConstructor()) {
            $this->setConstructor(static::class);
        }

        Session::push($this->getToken(), json_encode(['constructor' => $this->getConstructor()]));
        return $this;
    }
511889
protected function requireToken()
    {
        if (! $this->jwT->setRequest($this->getRequest())->getToken()) {
            throw new JwTException('Token could not be parsed from the request.');
        }

        return $this->jwT;
    }
6690
protected function createNewTokens()
    {
        $logger = $this->getLogger();
        $logger->debug('Starting request to create fresh access & refresh tokens');

        $body = [
            'client_id' => 'anonymous',
            'grant_type' => 'password',
            'response_type' => 'token',
            'scope' => 'openid',
            'username' => $this->credentials->getUsername(),
            'password' => $this->credentials->getPassword(),
        ];

        $response = $this->sendPostRequest($body);

        $logger->debug('Successfully retrieved new access & refresh tokens', $response);

        return [
            'accessToken' => new Token(
                $response['access_token'],
                $this->tokenExtractor->extract($response['access_token'])
            ),
            'refreshToken' => new Token(
                $response['refresh_token'],
                $this->tokenExtractor->extract($response['refresh_token'])
            ),
        ];
    }
1369447
public function appendTokens(Tokenizer $new_tokens)
    {
        $this->tokens = array_merge($this->tokens, $new_tokens->asArray());
        $this->rewind();

        return $this;
    }
86492
public function onGenerateAccessToken()
    {
        if (!User::isAccessTokenValid($this->_user->access_token)) {
            $this->_user->generateAccessToken();
            $this->_user->save(false);
        }
    }
666347
public function getToken()
    {
        if ($this->token === null) {
            try {
                $this->parseToken();
            } catch (JWTException $e) {
                $this->token = null;
            }
        }

        return $this->token;
    }
75706
protected function genToken()
    {
        // Generate a new random token (as random as possible)
        $rg = new RandomGenerator();
        $token = $rg->randomToken('md5');

        // Store a file in the session save path (safer than /tmp, as open_basedir might limit that)
        file_put_contents($this->pathForToken($token), $token);

        return $token;
    }
588999
protected function fillRepoToken()
    {
        if ($this->config->hasRepoToken()) {
            $this->env['COVERALLS_REPO_TOKEN'] = $this->config->getRepoToken();
        }

        // backup
        if (isset($this->env['COVERALLS_REPO_TOKEN'])) {
            $this->readEnv['COVERALLS_REPO_TOKEN'] = $this->env['COVERALLS_REPO_TOKEN'];
        }

        return $this;
    }
31208
public function generateToken()
    {
        if (isset($this->token)) return;

        $this->token = base_convert(md5(uniqid(rand(), true)), 16, 36);
        setcookie($this->getCookieName(), $this->token, time() + $this->cookie_lifetime, '/');
    }
766344
private function getAuthToken()
    {
        // Generate a new token if current is expired or empty
        if (!$this->token || new \DateTime() > $this->tokenExpireTime) {
            $this->requestToken();
        }

        return $this->token;
    }
355800
protected function prev_token(){
		$this->tok = prev( $this->input );
		$this->t = self::token_to_symbol( $this->tok );
		return $this->tok;
	}