Laravel Passport JWT 身份验证失败
Posted
技术标签:
【中文标题】Laravel Passport JWT 身份验证失败【英文标题】:Laravel Passport JWT authentication failing 【发布时间】:2020-08-17 13:37:24 【问题描述】:当我尝试通过护照创建 JWT(在 Ubuntu/apache2 上运行)时,我开始在生产中遇到此错误。据我所知,服务器上没有任何变化,没有安装,没有部署,它只是停止工作。
php 7.3
OpenSSL 1.0.1f
Laravel 5.8
production.ERROR: There was an error while creating the signature: error:04066044:rsa routines:rsa_ossl_private_encrypt:internal error "exception":"[object] (InvalidArgumentException(code: 0): There was an error while creating the signature: error:04066044:rsa routines:rsa_ossl_private_encrypt:internal error at /api/vendor/lcobucci/jwt/src/Signer/OpenSSL.php:27)
[stacktrace]
#0 /api/vendor/lcobucci/jwt/src/Signer/BaseSigner.php(36): Lcobucci\\JWT\\Signer\\OpenSSL->createHash('eyJ0eXAiOiJKV1Q...', Object(Lcobucci\\JWT\\Signer\\Key))
#1 /api/vendor/lcobucci/jwt/src/Builder.php(470): Lcobucci\\JWT\\Signer\\BaseSigner->sign('eyJ0eXAiOiJKV1Q...', Object(Lcobucci\\JWT\\Signer\\Key))
#2 /api/vendor/lcobucci/jwt/src/Builder.php(450): Lcobucci\\JWT\\Builder->createSignature(Array, Object(Lcobucci\\JWT\\Signer\\Rsa\\Sha256), Object(Lcobucci\\JWT\\Signer\\Key))
#3 /api/vendor/league/oauth2-server/src/Entities/Traits/AccessTokenTrait.php(41): Lcobucci\\JWT\\Builder->getToken()
#4 /api/vendor/league/oauth2-server/src/ResponseTypes/BearerTokenResponse.php(28): Laravel\\Passport\\Bridge\\AccessToken->convertToJWT(Object(League\\OAuth2\\Server\\CryptKey))
#5 /api/vendor/league/oauth2-server/src/AuthorizationServer.php(202): League\\OAuth2\\Server\\ResponseTypes\\BearerTokenResponse->generateHttpResponse(Object(Zend\\Diactoros\\Response))
#6 /api/vendor/laravel/passport/src/Http/Controllers/AccessTokenController.php(63): League\\OAuth2\\Server\\AuthorizationServer->respondToAccessTokenRequest(Object(Zend\\Diactoros\\ServerRequest), Object(Zend\\Diactoros\\Response))
#7 /api/vendor/laravel/passport/src/Http/Controllers/HandlesOAuthErrors.php(28): Laravel\\Passport\\Http\\Controllers\\AccessTokenController->Laravel\\Passport\\Http\\Controllers\\closure()
#8 /api/vendor/laravel/passport/src/Http/Controllers/AccessTokenController.php(65): Laravel\\Passport\\Http\\Controllers\\AccessTokenController->withErrorHandling(Object(Closure))
#9 /api/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php(48): Laravel\\Passport\\Http\\Controllers\\AccessTokenController->issueToken(Object(Zend\\Diactoros\\ServerRequest))
#10 /api/vendor/laravel/framework/src/Illuminate/Routing/Route.php(219): Illuminate\\Routing\\ControllerDispatcher->dispatch(Object(Illuminate\\Routing\\Route), Object(Laravel\\Passport\\Http\\Controllers\\AccessTokenController), 'issueToken')
#11 /api/vendor/laravel/framework/src/Illuminate/Routing/Route.php(176): Illuminate\\Routing\\Route->runController()
#12 /api/vendor/laravel/framework/src/Illuminate/Routing/Router.php(680): Illuminate\\Routing\\Route->run()
#13 /api/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(30): Illuminate\\Routing\\Router->Illuminate\\Routing\\closure(Object(Illuminate\\Http\\Request))
#14 /api/vendor/laravel/framework/src/Illuminate/Routing/Middleware/ThrottleRequests.php(58): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\closure(Object(Illuminate\\Http\\Request))
#15 /api/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(163): Illuminate\\Routing\\Middleware\\ThrottleRequests->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#16 /api/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\closure(Object(Illuminate\\Http\\Request))
#17 /api/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(104): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\closure(Object(Illuminate\\Http\\Request))
#18 /api/vendor/laravel/framework/src/Illuminate/Routing/Router.php(682): Illuminate\\Pipeline\\Pipeline->then(Object(Closure))
#19 /api/vendor/laravel/framework/src/Illuminate/Routing/Router.php(657): Illuminate\\Routing\\Router->runRouteWithinStack(Object(Illuminate\\Routing\\Route), Object(Illuminate\\Http\\Request))
#20 /api/vendor/laravel/framework/src/Illuminate/Routing/Router.php(623): Illuminate\\Routing\\Router->runRoute(Object(Illuminate\\Http\\Request), Object(Illuminate\\Routing\\Route))
#21 /api/vendor/laravel/framework/src/Illuminate/Routing/Router.php(612): Illuminate\\Routing\\Router->dispatchToRoute(Object(Illuminate\\Http\\Request))
#22 /api/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(176): Illuminate\\Routing\\Router->dispatch(Object(Illuminate\\Http\\Request))
#23 /api/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(30): Illuminate\\Foundation\\Http\\Kernel->Illuminate\\Foundation\\Http\\closure(Object(Illuminate\\Http\\Request))
我也刚刚注意到这个错误的另一个版本。没有任何改变,所以我不知道为什么会出现这个错误。
注意这一点:rsa routines:RSA_setup_blinding:BN lib
production.ERROR: There was an error while creating the signature: error:04088003:rsa routines:RSA_setup_blinding:BN lib "exception":"[object] (InvalidArgumentException(code: 0): There was an error while creating the signature: error:04088003:rsa routines:RSA_setup_blinding:BN lib at /api/vendor/lcobucci/jwt/src/Signer/OpenSSL.php:27)
[stacktrace]
#0 /api/vendor/lcobucci/jwt/src/Signer/BaseSigner.php(36): Lcobucci\\JWT\\Signer\\OpenSSL->createHash('eyJ0eXAiOiJKV1Q...', Object(Lcobucci\\JWT\\Signer\\Key))
#1 /api/vendor/lcobucci/jwt/src/Builder.php(470): Lcobucci\\JWT\\Signer\\BaseSigner->sign('eyJ0eXAiOiJKV1Q...', Object(Lcobucci\\JWT\\Signer\\Key))
#2 /api/vendor/lcobucci/jwt/src/Builder.php(450): Lcobucci\\JWT\\Builder->createSignature(Array, Object(Lcobucci\\JWT\\Signer\\Rsa\\Sha256), Object(Lcobucci\\JWT\\Signer\\Key))
#3 /api/vendor/league/oauth2-server/src/Entities/Traits/AccessTokenTrait.php(41): Lcobucci\\JWT\\Builder->getToken()
#4 /api/vendor/league/oauth2-server/src/ResponseTypes/BearerTokenResponse.php(28): Laravel\\Passport\\Bridge\\AccessToken->convertToJWT(Object(League\\OAuth2\\Server\\CryptKey))
#5 /api/vendor/league/oauth2-server/src/AuthorizationServer.php(202): League\\OAuth2\\Server\\ResponseTypes\\BearerTokenResponse->generateHttpResponse(Object(Zend\\Diactoros\\Response))
#6 /api/vendor/laravel/passport/src/Http/Controllers/AccessTokenController.php(63): League\\OAuth2\\Server\\AuthorizationServer->respondToAccessTokenRequest(Object(Zend\\Diactoros\\ServerRequest), Object(Zend\\Diactoros\\Response))
#7 /api/vendor/laravel/passport/src/Http/Controllers/HandlesOAuthErrors.php(28): Laravel\\Passport\\Http\\Controllers\\AccessTokenController->Laravel\\Passport\\Http\\Controllers\\closure()
#8 /api/vendor/laravel/passport/src/Http/Controllers/AccessTokenController.php(65): Laravel\\Passport\\Http\\Controllers\\AccessTokenController->withErrorHandling(Object(Closure))
#9 /api/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php(48): Laravel\\Passport\\Http\\Controllers\\AccessTokenController->issueToken(Object(Zend\\Diactoros\\ServerRequest))
#10 /api/vendor/laravel/framework/src/Illuminate/Routing/Route.php(219): Illuminate\\Routing\\ControllerDispatcher->dispatch(Object(Illuminate\\Routing\\Route), Object(Laravel\\Passport\\Http\\Controllers\\AccessTokenController), 'issueToken')
#11 /api/vendor/laravel/framework/src/Illuminate/Routing/Route.php(176): Illuminate\\Routing\\Route->runController()
#12 /api/vendor/laravel/framework/src/Illuminate/Routing/Router.php(680): Illuminate\\Routing\\Route->run()
#13 /api/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(30): Illuminate\\Routing\\Router->Illuminate\\Routing\\closure(Object(Illuminate\\Http\\Request))
#14 /api/vendor/laravel/framework/src/Illuminate/Routing/Middleware/ThrottleRequests.php(58): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\closure(Object(Illuminate\\Http\\Request))
#15 /api/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(163): Illuminate\\Routing\\Middleware\\ThrottleRequests->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#16 /api/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\closure(Object(Illuminate\\Http\\Request))
#17 /api/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(104): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\closure(Object(Illuminate\\Http\\Request))
#18 /api/vendor/laravel/framework/src/Illuminate/Routing/Router.php(682): Illuminate\\Pipeline\\Pipeline->then(Object(Closure))
#19 /api/vendor/laravel/framework/src/Illuminate/Routing/Router.php(657): Illuminate\\Routing\\Router->runRouteWithinStack(Object(Illuminate\\Routing\\Route), Object(Illuminate\\Http\\Request))
#20 /api/vendor/laravel/framework/src/Illuminate/Routing/Router.php(623): Illuminate\\Routing\\Router->runRoute(Object(Illuminate\\Http\\Request), Object(Illuminate\\Routing\\Route))
#21 /api/vendor/laravel/framework/src/Illuminate/Routing/Router.php(612): Illuminate\\Routing\\Router->dispatchToRoute(Object(Illuminate\\Http\\Request))
#22 /api/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(176): Illuminate\\Routing\\Router->dispatch(Object(Illuminate\\Http\\Request))
#23 /api/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(30): Illuminate\\Foundation\\Http\\Kernel->Illuminate\\Foundation\\Http\\closure(Object(Illuminate\\Http\\Request))
#24 /api/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(21): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\closure(Object(Illuminate\\Http\\Request))
【问题讨论】:
您安装了哪个版本的护照? 【参考方案1】:我今天也有同样的问题。花了很多时间并没有找到解决方案。 这个算法对我有帮助
-
sudo certbot
选择需要的域,然后输入“2”两次以更新 ssl 证书
然后从存储文件夹中删除密钥,同时从数据库表 oauth_clients 中删除
php 工匠护照:安装
检查存储文件夹中密钥的权限
sudo service apache2 重启
之后 laravel 护照开始登录用户。对我来说,证书似乎有些问题,因为没有证书更新的同一串命令无法修复身份验证工作。
【讨论】:
以上是关于Laravel Passport JWT 身份验证失败的主要内容,如果未能解决你的问题,请参考以下文章
Laravel 5.6 - 用于自助API的Passport JWT httponly cookie SPA身份验证?
使用 passport-jwt 进行 JWT 身份验证不考虑到期日期