Download a set of documents

@param Token       $token

@return Response
771419
public function downloadDocuments(Token $token)
    {
        if (false === $list = @unserialize($token->getData())) {
            $this->app->abort(500, 'Invalid datas');
        }
        if (!is_array($list)) {
            $this->app->abort(500, 'Invalid datas');
        }

        foreach (['export_name', 'files'] as $key) {
            if (!isset($list[$key])) {
                $this->app->abort(500, 'Invalid datas');
            }
        }

        $exportName = $list['export_name'];

        if ($list['count'] === 1) {
            $file = end($list['files']);
            $subdef = end($file['subdefs']);
            $exportName = sprintf('%s%s.%s', $file['export_name'], $subdef['ajout'], $subdef['exportExt']);
            $exportFile = \p4string::addEndSlash($subdef['path']) . $subdef['file'];
            $mime = $subdef['mime'];
            $list['complete'] = true;
        } else {
            $exportFile = $this->app['tmp.download.path'].'/'.$token->getValue() . '.zip';
            $mime = 'application/zip';
        }

        if (!$this->getFilesystem()->exists($exportFile)) {
            $this->app->abort(404, 'Download file not found');
        }

        $this->getDispatcher()->addListener(KernelEvents::RESPONSE, function (FilterResponseEvent $event) use ($list) {
            \set_export::log_download(
                $this->app,
                $list,
                $event->getRequest()->get('type'),
                !!$event->getRequest()->get('anonymous', false),
                (isset($list['email']) ? $list['email'] : '')
            );
        });

        return $this->deliverFile($exportFile, $exportName, DeliverDataInterface::DISPOSITION_ATTACHMENT, $mime);
    }
980511
public function getByActionToken(string $token)
	{
		return $this->setAuthorizer($this->getModel()->where('action_token', '=', $token)->first());
	}
750676
public function expireByToken($token)
    {
        $token = $this->findByToken($token);

        if (! is_null($token)) {
            return $token->expire();
        }
    }
104266
public function revokeToken($token)
    {
        $revoked = false;
        $store = $this->getStore();
        $pool = $store->getTokens();
        if(!is_null($pool)){
            foreach($pool as $key => $savedToken){
                if($savedToken['token'] == $token){
                    unset($pool[$key]);
                    $revoked = true;
                    break;
                }
            }
        }
        $store->setTokens($pool);

        return $revoked;
    }
553479
public static function fetch_file($token) {
        global $DB;
        $remoteclient = get_mnet_remote_client();
        try {
            if (!$transferid = $DB->get_field('portfolio_mahara_queue', 'transferid', array('token' => $token))) {
                throw new mnet_server_exception(8009, 'mnet_notoken', 'portfolio_mahara');
            }
            $exporter = portfolio_exporter::rewaken_object($transferid);
        } catch (portfolio_exception $e) {
            throw new mnet_server_exception(8010, 'mnet_noid', 'portfolio_mahara');
        }
        if ($exporter->get('instance')->get_config('mnethostid') != $remoteclient->id) {
            throw new mnet_server_exception(8011, 'mnet_wronghost', 'portfolio_mahara');
        }
        global $CFG;
        try {
            $i = $exporter->get('instance');
            $f = $i->get('file');
            if (empty($f) || !($f instanceof stored_file)) {
                throw new mnet_server_exception(8012, 'mnet_nofile', 'portfolio_mahara');
            }
            try {
                $c = $f->get_content();
            } catch (file_exception $e) {
                throw new mnet_server_exception(8013, 'mnet_nofilecontents', 'portfolio_mahara', $e->getMessage());
            }
            $contents = base64_encode($c);
        } catch (Exception $e) {
            throw new mnet_server_exception(8013, 'mnet_nofile', 'portfolio_mahara');
        }
        $exporter->log_transfer();
        $exporter->process_stage_cleanup(true);
        return $contents;
    }
1339712
public function withToken(Token $token)
    {
        $this->grant = 'provided_token';
        $this->token = new AccessToken([
            'access_token' => $token->jwt(),
            'expires' => $token->expires()->timestamp,
        ]);

        return $this;
    }
845831
public function processRequestToken($token) {
        // Setup the params
        $params = [
            'client_id'     => $this->clientID,
            'client_secret' => $this->secret,
            'code'          => $token,
            'grant_type'    => 'authorization_code',
            'redirect_uri'  => $this->redirectURI
        ];

        // Parse the cURL result
        return CURL::post($this->url, $params);
    }
1371286
public static function extractToken($token) {
    $extract = self::$config['jwt_extract']($token);
    if (!$extract) {
      return false;
    }
    $guid = $extract['guid'];

    $user = Nymph::getEntity(
        ['class' => '\Tilmeld\Entities\User'],
        ['&',
          'guid' => $guid
        ]
    );
    if (!$user || !$user->guid || !$user->enabled) {
      return false;
    }

    return $user;
  }
968531
private function retrieveByToken(string $token)
    {
        $token = $this->validateToken($token);
        if (!$token) {
            return NULL;
        }
        $user = new User();
        if ($token->hasClaim('sub')) {
            $user->id = $token->getClaim('sub');
        }
        if ($token->hasClaim('name')) {
            $user->name = $token->getClaim('name');
        }
        if ($token->hasClaim('email')) {
            $user->email = $token->getClaim('email');
        }
        if ($token->hasClaim('roles')) {
            $user->roles = explode(' ', $token->getClaim('roles'));
        }
        if ($token->hasClaim('registries')) {
            $user->registries = explode(' ', $token->getClaim('registries'));
        }
        if ($token->hasClaim('cpf')) {
            $user->cpf = $token->getClaim('cpf');
        }
        if ($token->hasClaim('avatar')) {
            $user->avatar = $token->getClaim('avatar');
        }

        return $user;
    }
1130921
private function getEndpointUrlFromToken(Token $token)
    {
        $catalog = $token->getServiceCatalog($this->tenant->getServiceType(), $this->tenant->getServiceName());

        // use the first endpoint that has was requested
        $endpointType = $this->tenant->getServiceEndpoint() . 'url';
        foreach ($catalog as $endpoint) {
            $endpoint = array_change_key_case($endpoint, CASE_LOWER);
            if (array_key_exists($endpointType, $endpoint)) {
                return $endpoint[$endpointType];
            }
        }

        throw new TokenException('No endpoint with a ' . $this->tenant->getServiceEndpoint() . ' url found');
    }
383656
protected function _get($token = null)
    {
        $token = $this->_token($token);
        $entity = $this->_verify($token);

        if ($this->_save($entity)) {
            return $this->_success();
        }

        $this->_error();
    }
662482
protected function requireToken($token)
    {
        if ($token) {
            return $this->setToken($token);
        } elseif ($this->token) {
            return $this;
        } else {
            throw new JWTException('A token is required', 400);
        }
    }
179240
public function offsetGet($token)
    {
        if (isset($this->idf[$token])) {
            return $this->idf[$token];
        } else {
            return $this->logD;
        }
    }
168713
public function create($token = null)
    {
        if ($token) {
            $this->model->setToken($token);
        }

        return $this->request->create($this->model);
    }
624217
public function refresh(Token $token)
    {
        $payload = $this->setRefreshFlow()->decode($token);

        if ($this->blacklistEnabled) {
            // invalidate old token
            $this->blacklist->add($payload);
        }

        // return the new token
        return $this->encode(
            $this->payloadFactory->make([
                'sub' => $payload['sub'],
                'iat' => $payload['iat'],
            ])
        );
    }
668199
public function retrieveByToken($identifier, $token)
    {
        $model = $this->createModel();

        return $model->newQuery()
            ->where($model->getAuthIdentifierName(), $identifier)
            ->where($model->getRememberTokenName(), $token)
            ->first();
    }
509303
public function deleteToken($token)
    {
        return $this->queryBuilder->from($this->getTokenTable())
            ->where('token', $token)
            ->delete();
    }