我跑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?)
我一直收到此错误
Class' 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"
}
}
答案 0 :(得分:3)
尝试运行composer dumpauto
命令
答案 1 :(得分:1)
您已安装该软件包的版本^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?)
答案 2 :(得分:0)