API调用有问题。正如主题所述,我们不能使用凭据访问后端API。
我们客户的生产和暂存实例运行Shopware 6.2.3,我们为Shopware编写插件。因此,现在我们希望将客户的实例更新为6.4.x.x。我们还有一个新安装的dev实例(6.4.13.0),用于测试我们自己的SW 6.4插件。
现在我们面临一个我们无法解释的问题。我们把制作的副本从6.2.3更新到6.4.13.0,没有出现任何重大问题。但是我们的API调用总是失败,因为这个错误:
{"errors":[{"code":"6","status":"400","title":"The user credentials were incorrect.","detail":null}]}凭证是绝对正确的,我们可以使用它们登录到后端。
当我们使用Curl具有相同的有效负载时,也会发生相同的错误。在我们的6.4dev实例上(见上文),Curl命令和插件都能完美地工作,并且能够获得访问令牌。
这是我们用来测试的Curl命令:
curl --request POST --url https://our-domain.example/api/oauth/token --header 'Authorization: ' --header 'Content-Type: application/json' --data '{"grant_type": "password", "username": "xxxxx", "password": "xxxxxxxx", "client_id": "administration"}'这是我们的开发人员编写的代码;它在6.4dev实例上工作得很好:
private function _getToken($domain, $username, $pass)
{
if ($domain[strlen($domain)-1] !== "/")
{
$domain .= "/";
}
$endpoint = $domain . "api/oauth/token";
$config = [];
if (strpos($endpoint, "https") > -1) {
$config = ['verify' => false];
}
$client = new Client($config);
$json_encode = json_encode([
'username' => $username,
'password' => $pass,
'grant_type' => 'password',
"client_id" => "administration",
]);
$response = $client->request('POST', $endpoint, [
'body' => $json_encode,
"headers" => ["Content-Type" => "application/json"]
]);
return json_decode($response->getBody())->access_token;
}为了排除将Shopware更新为6.4存在问题,我们在未接触的生产实例和暂存实例以及voilà:相同的错误上测试了API调用,但差别很小。它抛出除400以外的一个错误401。
因此,很明显,6.2.3实例有问题。
知道我们能查到什么吗?Shopware核心或数据库中是否有阻止API身份验证的东西?
任何帮助都是非常感谢的!提前感谢!
发布于 2022-10-31 12:17:02
不过,我们发现了问题所在。Curl在验证(仍然有效) SSL证书时遇到了问题。因此,我们试图对其进行更新,但由于web服务器缺少IPv6地址,“‘sEncrypt”失败了。因此,我们将它添加到虚拟主机,更新证书,现在API调用给我们令牌。
https://stackoverflow.com/questions/74262678
复制相似问题