使用 Laravel 进行 JWT 的作曲家出错

Posted

技术标签:

【中文标题】使用 Laravel 进行 JWT 的作曲家出错【英文标题】:Error with composer using Laravel for JWT 【发布时间】:2021-07-04 13:36:55 【问题描述】:

按照本指南:https://laravel-angular.io/docs/1/jwt-auth-install/ 我已经正确安装了tymon/jwt-auth:^1.0@dev。一切正常,但是当我运行:composer require irazasyed/jwt-auth-guard 时,会出现此错误。

composer require irazasyed/jwt-auth-guard
Using version ^1.0 for irazasyed/jwt-auth-guard
./composer.json has been updated
Running composer update irazasyed/jwt-auth-guard
Loading composer repositories with package information
Updating dependencies
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - irazasyed/jwt-auth-guard[dev-master, v1.0.0, ..., v1.0.4] require illuminate/support ~5.0 -> found illuminate/support[v5.0.0, ..., 5.8.x-dev] but these were not loaded, likely because it conflicts with another require.
    - irazasyed/jwt-auth-guard 1.0.x-dev is an alias of irazasyed/jwt-auth-guard dev-master and thus requires it to be installed too.
    - Root composer.json requires irazasyed/jwt-auth-guard ^1.0 -> satisfiable by irazasyed/jwt-auth-guard[v1.0.0, ..., 1.0.x-dev (alias of dev-master)].


Installation failed, reverting ./composer.json and ./composer.lock to their original content.

我的php版本是:7.4.16;

我的 Laravel 版本是:8.12;

我的作曲家版本是:2.0.9。

我不知道我能做什么。感谢大家的帮助!

更新:

这是运行composer require irazasyed/jwt-auth-guard --ignore-platform-reqs后的错误:

Using version ^1.0 for irazasyed/jwt-auth-guard
./composer.json has been updated
Running composer update irazasyed/jwt-auth-guard
Loading composer repositories with package information
Updating dependencies
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - irazasyed/jwt-auth-guard[dev-master, v1.0.0, ..., v1.0.4] require illuminate/support ~5.0 -> found illuminate/support[v5.0.0, ..., 5.8.x-dev] but these were not loaded, likely because it conflicts with another require.
    - irazasyed/jwt-auth-guard 1.0.x-dev is an alias of irazasyed/jwt-auth-guard dev-master and thus requires it to be installed too.
    - Root composer.json requires irazasyed/jwt-auth-guard ^1.0 -> satisfiable by irazasyed/jwt-auth-guard[v1.0.0, ..., 1.0.x-dev (alias of dev-master)].


Installation failed, reverting ./composer.json and ./composer.lock to their original content.

【问题讨论】:

我不会推荐这个包! - 该包没有任何测试 - 它只有两个文件并且使用 tymon/jwt-auth Laravel 已经支持 JWT - 它正在使用 tymon/jwt-auth。 Laravel 已经支持 jwt ---- 所以你不需要这个包你可以复制文件并添加你自己的测试。 laravel.com/docs/8.x/passport 也看看laravel.com/docs/8.x/sanctum 所以使用 Laravel Sanctum 我什至不需要 tymon/jwt-auth? 看看github.com/laravel/passport/blob/10.x/composer.json 它使用github.com/lcobucci/jwt 而不是tymon/jwt-auth 这里有更多关于你的 JS 如何使用 JWT laravel.com/docs/8.x/… 的信息 【参考方案1】:

lcobucci/jwt 是一个与框架无关的 PHP 库,允许您基于 RFC 7519 发布、解析和验证 JSON Web 令牌。

通过运行以下命令,您可以安装它。

composer require lcobucci/jwt

你可以在这里找到更多的文档

https://lcobucci-jwt.readthedocs.io/en/latest/

【讨论】:

请在您的答案中添加一些解释,以便其他人可以从中学习 @NicoHaase 肯定会这样做

以上是关于使用 Laravel 进行 JWT 的作曲家出错的主要内容,如果未能解决你的问题,请参考以下文章

Laravel 5.2 - 使用 composer 和 git bash 安装 laravel 时出错

尝试在 Laravel 中使用 JWT Auth 创建用户时出错 [关闭]

在 forge 上安装 Laravel 5.2 时出错

更新 Composer 时出错

Laravel作曲家安装错误[golonka / BBcodeParser] 404

通过 Composer 下载 Lumen 时出错