使用 grant_type=密码的 CURL API 令牌请求
CURL API token request with grant_type=password
我需要为我的应用程序生成一个 API 令牌。来自外部服务的文档显示了以下信息:
This request uses normal post webforms.
<password> must be md5 encoded.
Endpoint: api/token
Request: "grant_type: password
Password: <password>
Username: <USERNAME>
"
我所做的是在控制台中生成 md5 编码的密码:
> Digest::MD5.hexdigest("ZCW2OQo5yhfmTKutGjiCWQ==")
=> "53a89a22375a3665cfe4cb92ee17992b"
并将其放入 curl 命令中,如下所示:
curl -d "grant_type=password&password=53a89a22375a3665cfe4cb92ee17992b&username=my_user_name" -X POST https://enpoint/api/token
但是我得到的不是预期的响应而是错误:
{"error":"invalid_grant"}
您的密码似乎已经以某种方式编码 - 它是二进制字符串的 base64 编码。
尝试将您的实际密码而不是这个已经编码的版本作为 hexdigest
的参数。
我需要为我的应用程序生成一个 API 令牌。来自外部服务的文档显示了以下信息:
This request uses normal post webforms.
<password> must be md5 encoded.
Endpoint: api/token
Request: "grant_type: password
Password: <password>
Username: <USERNAME>
"
我所做的是在控制台中生成 md5 编码的密码:
> Digest::MD5.hexdigest("ZCW2OQo5yhfmTKutGjiCWQ==")
=> "53a89a22375a3665cfe4cb92ee17992b"
并将其放入 curl 命令中,如下所示:
curl -d "grant_type=password&password=53a89a22375a3665cfe4cb92ee17992b&username=my_user_name" -X POST https://enpoint/api/token
但是我得到的不是预期的响应而是错误:
{"error":"invalid_grant"}
您的密码似乎已经以某种方式编码 - 它是二进制字符串的 base64 编码。
尝试将您的实际密码而不是这个已经编码的版本作为 hexdigest
的参数。