【发布时间】:2019-05-29 14:54:58
【问题描述】:
我正在尝试使用 JWT Bearer 执行 OAuth2 的步骤 here,我已包含 installation instructions 中所述的相应文件。
但是,当我运行以下 PHP 代码时:
$private_key = file_get_contents("/www/var/includes/keyfile.pem");
$client_id = 'example_client_id';
$user_id = 'example_user_id';
$grant_type = 'urn:ietf:params:oauth:grant-type:jwt-bearer';
$jwt = generateJWT($private_key, $client_id, $user_id, 'https://api.example.com');
...我收到以下错误:
openssl_sign(): supplied key param cannot be coerced into a private key
Uncaught exception 'Exception' with message 'Unable to sign data.'
我已经读到使用“file_get_contents”可能不是最好的方法,已经尝试了其他方法但没有运气。第一个链接中的文档特别说要使用它,这似乎很奇怪?
【问题讨论】:
-
听起来你的
keyfile.pem文件有问题 -
从您链接的示例中,他们使用
generateJWT和 RSA 私钥(来自公钥/私钥对)。.pem文件通常是证书 -
好的,有道理!您知道将 .pem 文件与 JWT 一起使用的方法吗? .pem 是此 API 的要求。