Laravel Passport-无法创建密钥文件

发布于 2025-02-13 05:45:34 字数 396 浏览 0 评论 0原文

我在Laravel 8.0中有一个项目。该项目居住在服务器上。现在,我正在尝试使用Docker在本地环境上进行设置。

我几乎做到了,但是我在拉拉维尔/护照上有一个问题。 当我尝试运行任何工匠命令(甚至是“ PHP Artisan Passport:Keys”)时,我总是会有以下错误。

在cryptkey.php行69中: 无法从文件中读取键 file:///var/www/html/storage/oauth-private.key

所以这是正确的,因为尚未创建键。但是我无法生成新的。

即使我尝试创建它,也看起来像Laravel/Passport使用每个命令检查此键。

当命令发射时,我该如何跳过此检查。还是如何解决此问题?

谢谢。

I have a project in Laravel 8.0. This project is living on server. Now I'm trying setup it on my local environment using docker.

I almost done it but I have one issue with laravel/passport.
When I try run any artisan command (even "php artisan passport:keys") always I have following error.

In CryptKey.php line 69:
Unable to read key from file
file:///var/www/html/storage/oauth-private.key

So it's correct because keys are not created yet. But I'm not able generate new one.

It looks like laravel/passport checking this keys with every command even when I try to create it.

How can I skip this checking when command fired. Or how to fix this issue?

Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

故事灯 2025-02-20 05:45:38

我发现了这个问题。

authserviceProvider 中,在 boot()方法中,以下说明:

$server = $this->app->make(AuthorizationServer::class);
$server->enableGrantType(new PersonalAccessGrant(), new DateInterval("P{$tokenLifetime}D"));

因此,此方法不仅始终根据要求,而且在命令调用中也被触发。

要解决问题,我们需要在 $ this-> app-> make(呼叫之前添加检查。

if (app()->runningInConsole()) {
   return;
};

I found the problem.

In class AuthServiceProvider in boot() method where following instructions:

$server = $this->app->make(AuthorizationServer::class);
$server->enableGrantType(new PersonalAccessGrant(), new DateInterval("P{$tokenLifetime}D"));

So this method is always fired not only on request but on command call too.

To solve issue we need just add checking before $this->app->make( call.

if (app()->runningInConsole()) {
   return;
};
暮倦 2025-02-20 05:45:38

该命令应在服务器上运行,如果不是创建,则有一些权限问题

最佳示例 https://www.laravelcode.com/post/laravel-8-api-authentication-using-passport-from-the-scratch

此命令应在服务器上运行

This command should run on server if not create then there is the server some permission issue

Best Example https://www.laravelcode.com/post/laravel-8-api-authentication-using-passport-from-the-scratch

This command should run on server

错々过的事 2025-02-20 05:45:38

我认为关键本身不是生成的。因此,使用以下命令首先生成密钥。

php artisan key:generate

然后运行,

php artisan passport:keys

如果这不起作用,则必须是许可问题。提供足够的阅读权限存储文件夹。在终端中尝试以下命令,

sudo chmod 755 -R storage

I think the key itself is not generated. So use the below command to generate key first.

php artisan key:generate

And then run,

php artisan passport:keys

If this din't work, Then It must be the permission issue. Provide enough read permission to storage folder. Try the below command in the terminal,

sudo chmod 755 -R storage
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文