我运行sudo composer require lcobucci/jwt来安装这些东西。
然后,我在我的文件上添加了use Lcobucci\JWT\Configuration;
然后,我开始使用示例代码
$config = new Configuration(); // This object helps to simplify the creation of the dependencies
// instead of using "?:" on constructors.
$token = $config->createBuilder()
->issuedBy('https://login.uat.telenet.be/openid') // Configures the issuer (iss claim)
->canOnlyBeUsedBy('site') // Configures the audience (aud claim)
->identifiedBy('888254e8-f1e8-4956-86fa-a6c0f61a6421', true) // Configures the id (jti claim), replicating as a header item
->issuedAt(time()) // Configures the time that the token was issue (iat claim)
->canOnlyBeUsedAfter(time() + 60) // Configures the time that the token can be used (nbf claim)
->expiresAt(time() + 3600) // Configures the expiration time of the token (exp claim)
->with('uid', 1) // Configures a new claim, called "uid"
->getToken(); // Retrieves the generated token
$token->getHeaders(); // Retrieves the token headers
$token->getClaims(); // Retrieves the token claims
echo $token->getHeader('jti'); // will print "4f1g23a12aa"
echo $token->getClaim('iss'); // will print "http://example.com"
echo $token->getClaim('uid'); // will print "1"
echo $token; // The string representation of the object is a JWT string (pretty easy, right?)我一直在犯这个错误
未找到类'Lcobucci\JWT\Configuration‘
我怎么才能防止这种情况?
这是我的整个composer.json文件
{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"type": "project",
"require": {
"php": ">=5.5.9",
"laravel/framework": "5.1.*",
"illuminate/html": "^5.0",
"laracasts/utilities": "~2.0",
"barryvdh/laravel-debugbar": "^2.0",
"sammyk/laravel-facebook-sdk": "~3.0",
"doctrine/dbal": "^2.5",
"lcobucci/jwt": "^3.2"
},
"require-dev": {
"fzaninotto/faker": "~1.4",
"mockery/mockery": "0.9.*",
"phpunit/phpunit": "~4.0",
"phpspec/phpspec": "~2.1",
"mcamara/laravel-localization": "1.0.*"
},
"autoload": {
"classmap": [
"database"
],
"psr-4": {
"App\\": "app/",
"Helpers\\": "app/Helpers/"
},
"files": ["app/Helper.php"]
},
"autoload-dev": {
"classmap": [
"tests/TestCase.php"
]
},
"scripts": {
"post-install-cmd": [
"php artisan clear-compiled",
"php artisan optimize"
],
"pre-update-cmd": [
],
"post-update-cmd": [
"php artisan clear-compiled",
"php artisan optimize"
],
"post-root-package-install": [
"php -r \"copy('.env.example', '.env');\""
],
"post-create-project-cmd": [
"php artisan key:generate"
]
},
"config": {
"preferred-install": "dist"
}
}发布于 2017-01-24 16:32:37
您已经安装了包的^3.2版本。如果查看此版本的代码和文档,就会发现没有Configuration对象;有一个Builder对象。
如果你只是去https://github.com/lcobucci/jwt,你将看到他们的主分支。根据他们的文件,他们目前正在编写下一个主要版本:
重要:这是我们下一个主要版本(v4)的文档,它将发生变化。如果您正在使用稳定版本,则应该转到分支3.2。
请确保查看正在使用的版本的文档:
https://github.com/lcobucci/jwt/tree/3.2
这是3.2的示例代码(您正在使用的版本):
use Lcobucci\JWT\Builder;
$token = (new Builder())->setIssuer('http://example.com') // Configures the issuer (iss claim)
->setAudience('http://example.org') // Configures the audience (aud claim)
->setId('4f1g23a12aa', true) // Configures the id (jti claim), replicating as a header item
->setIssuedAt(time()) // Configures the time that the token was issue (iat claim)
->setNotBefore(time() + 60) // Configures the time that the token can be used (nbf claim)
->setExpiration(time() + 3600) // Configures the expiration time of the token (nbf claim)
->set('uid', 1) // Configures a new claim, called "uid"
->getToken(); // Retrieves the generated token
$token->getHeaders(); // Retrieves the token headers
$token->getClaims(); // Retrieves the token claims
echo $token->getHeader('jti'); // will print "4f1g23a12aa"
echo $token->getClaim('iss'); // will print "http://example.com"
echo $token->getClaim('uid'); // will print "1"
echo $token; // The string representation of the object is a JWT string (pretty easy, right?)发布于 2017-01-24 14:34:52
尝试运行composer dumpauto命令
发布于 2020-03-13 14:04:50
首先,删除供应商文件夹并尝试使用命令重新安装composer
composer update 已经面对一个问题两个多小时了,尝试不同的方法,然后尝试这个,我的问题解决了。

https://stackoverflow.com/questions/41830759
复制相似问题