解决 laravel passport 'Key file "%s" permissions are not correct, should be 600 or 660 instead of %s' 问题

in web技术 with 0 comment 访问: 2,582 次

问题描述

这是我之前遇到的问题,忘记记录了。

环境:

我在做我自己的项目的时候,决定全部使用API风格,token鉴权的机制,这样就可以只写一份后端,而不考虑页面。问题就出现在这,我是使用windows进行开发,当我安装完laravel/passport的时候,访问报错'Key file "%s" permissions are not correct, should be 600 or 660 instead of 666',这显然是一个权限的问题,但是比较尴尬的是我在用windows,应该没涉及到什么权限的问题才对啊,毕竟windows的····(不能说坏话,万一我有一天去微软上班了呢)。

问题所在

            $keyPathPerms = decoct(fileperms($keyPath) & 0777);
            if (in_array($keyPathPerms, ['600', '660'], true) === false) {
                // @codeCoverageIgnoreStart
                trigger_error(sprintf(
                    'Key file "%s" permissions are not correct, should be 600 or 660 instead of %s',
                    $keyPath,
                    $keyPathPerms
                ), E_USER_NOTICE);
                // @codeCoverageIgnoreEnd
            }

在windows下,这里keyPathPerms确实是666,于是触发了这个报错。

接着,我给laravel/passport提了一个issues, https://github.com/laravel/passport/issues/712 ,但是没人回复。

由于这些包都是各种互相引入,所以我只能找到源头,他内置其实是这个包:

https://github.com/thephpleague/oauth2-server

所以我提了一个PR给他们:

https://github.com/thephpleague/oauth2-server/pull/901 ,只是想寻求一些帮助,或者告诉我win下的正确操作,或者告诉我我的错误,因为我认为他们这是硬编码,他们一定都鄙视windosw,哈哈。

我在PR中抛去了windows,既然你选择了windows,那就别怪我了。

在第51行改为:

if (in_array($keyPathPerms, ['400', '440', '600', '660'], true) === false && strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN') {

ok,起码他为我工作了。

什么?不安全?不安全你还用windows。

2018-06-01最新更新:我提的PR被重新打开了,哈哈!!!

赞赏支持
Responses