php - 从 Wordpress wp_remote_post 调用 Laravel Passport 时,身份验证失败,但与 Postman 一起使用
问题描述
我正在重新询问和更新这个问题,并在评论偏离轨道时删除我的旧问题。
第一次使用Laravel Passport
,我花了几个小时试图弄清楚这一点。我正在从Wordpress
站点调用 api 端点。两者都是昨天全新安装的最新版本Passport
。Laravel 5.7.19
我的 API 使用Postman
, 和Passport
身份验证工作得很好。
我这样调用Laravel Passport
API Wordpress
:
$args = array(
'method' => 'POST',
'timeout' => '45',
'redirection' => '5',
'httpversion' => '1.0',
'blocking' => true,
'headers' => array(
'Accept' => 'application/json',
'X-Requested-With' => 'XMLHttpRequest',
'Authorization' => 'Bearer dd4b28b53ea...',
),
'body' => array(
'email' => $email,
'channel_url' => $channel_url,
'api_key' => $api_key,
),
'cookies' => array()
);
// PING API
$response = wp_remote_post( $login, $args );
如果我的路线在这样的auth:api
组内:
Route::group([
'middleware' => 'auth:api'
], function() {
Route::post('my/route', 'Api\AuthController@userChannel');
});
通话失败401
。wp_remote_post()
使用Postman
+Bearer token
它可以工作。
采取组外的路线auth:api
适用于Wordpress
并且Postman
我可以记录/查看令牌:
[2019-02-11 05:23:32] local.INFo: Bearer dd4b28b53ea...
我已经尝试按照许多帖子中的建议更改.htaccess
文件和文件,php artisan optimize:clear
但没有成功。Passport::withoutCookieSerialization();
AppServiceProvider
的例外Laravel
是:
The resource owner or authorization server denied the request. {"exception":"[object] (League\\OAuth2\\Server\\Exception\\OAuthServerException(code: 9): The resource owner or authorization server denied the request. at /home/vagrant/src/my-app/vendor/league/oauth2-server/src/Exception/OAuthServerException.php:215, InvalidArgumentException(code: 0): The JWT string must have two dots at /home/vagrant/src/my-app/vendor/lcobucci/jwt/src/Parser.php:95)
解决方案
正如 Travis 提到的,我上面的代码没有任何问题。我的控制器出现逻辑问题。上面的代码可以正常工作。
推荐阅读
- javascript - 签名板:缩放后无法正确检测鼠标坐标
- python - 使 MongoDB 适应 mongoengine 文档
- python - 在 Python 中将视频转换为帧 - 1 FPS
- node.js - 有没有更方便的方法将普通的 js 对象映射到 grcp 响应类?
- javascript - 如何在一个链接中执行两个事件:事件 onClick 到外部页面(_blank)和内部页面(_self)?
- javascript - 如何使用 jQuery live 获取选中和未选中的值?
- javascript - JavaScript RegEx:将具有动态长度的字符串格式化为块格式
- python - 从 URL 不变的网站中抓取数据
- r - 为什么要引用函数名
- c++ - 如果在多个共享库中调用并且启用了 libstdc++ 静态链接,C++ 流会变坏