Php 从Wordpress wp_remote_post调用Laravel Passport时,身份验证失败,但与邮递员一起工作
我正在重新询问和更新这个问题,并在评论偏离轨道时删除我的旧问题 第一次使用Laravel Passport,我花了几个小时试图弄明白这一点。我正在从Php 从Wordpress wp_remote_post调用Laravel Passport时,身份验证失败,但与邮递员一起工作,php,wordpress,laravel,laravel-passport,Php,Wordpress,Laravel,Laravel Passport,我正在重新询问和更新这个问题,并在评论偏离轨道时删除我的旧问题 第一次使用Laravel Passport,我花了几个小时试图弄明白这一点。我正在从Wordpress站点调用api端点。Passport和Laravel 5.7.19都是昨天新安装的最新版本 我的API使用Postman和Passport身份验证工作正常 我从Wordpress调用Laravel PassportAPI,如下所示: $args = array( 'method' => 'POST', 'tim
Wordpress
站点调用api端点。Passport
和Laravel 5.7.19
都是昨天新安装的最新版本
我的API使用Postman
和Passport
身份验证工作正常
我从Wordpress
调用Laravel Passport
API,如下所示:
$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 );
Route::group([
'middleware' => 'auth:api'
], function() {
Route::post('my/route', 'Api\AuthController@userChannel');
});
如果我的路线在auth:api
组中,如下所示:
$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 );
Route::group([
'middleware' => 'auth:api'
], function() {
Route::post('my/route', 'Api\AuthController@userChannel');
});
在调用wp\u remote\u post()
时,401
失败。使用邮递员
+承载令牌
它可以工作
在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提到的,我上面的代码没有问题。我的控制器有逻辑问题。上述代码正常工作。是否可能使用刷新令牌而不是访问令牌?如果这是你令牌的真正开始,它看起来不太正确(jwt不是十六进制字符串)Travis,我两小时前发现的。我把我的Laravel控制器的代码搞糟了,它正在截断令牌。谢谢你的帮助!