首页 > 解决方案 > 我们如何通过以下 curl 请求检索用户 ID 和 iam 令牌?

问题描述

作为联合用户,它必须使用 API 密钥或一次性密码进行身份验证。我试图执行以下 curl 请求:-

例子 :-

输入 :-

curl -s -u 'bx:bx' -k -X POST --header 'Content-Type: application/x-www-form-urlencoded' --header 'Accept: application/json' -d "grant_type=password&response_type=cloud_iam,ims_portal&username=${1}&password=${2}&ims_account=${3}" https://iam.ng.bluemix.net/oidc/token

输出 :-

"errorMessage":"You cannot authenticate with user name and password, as you are a federated user","errorDetails":"Your user id '<<><><>>' is federated and must use an API key or one-time passcode to authenticate"

但是我们如何验证用户来生成 iam_token 和 iam_user_id 呢?

参考:- https://softlayer.github.io/rest/IBMidtoSLKey/

标签: ibm-cloudibm-cloud-infrastructure

解决方案


您从 SoftLayer 指南中引用的代码片段具有设置 SoftLayer 用户名和 API 密钥的结果:

echo "SL_USERNAME: $SL_USERNAME"
echo "SL_API_KEY: $SL_API_KEY"

这是一种迂回的方式来查找在您的用户配置文件中看到的作为 API 用户名和身份验证密钥列出的相同信息。如果您没有看到 API 用户名和身份验证密钥,您可以在用户列表中您的姓名旁边的操作菜单上创建一个。

然后您可以执行基础设施 API,我希望这是最终目标。

export IAAS_USERNAME=<API Username>
export IAAS_KEY=<Authentication Key>
curl -u $IAAS_USERNAME:$IAAS_KEY https://api.softlayer.com/rest/v3/SoftLayer_Account/getAllBillingItems

目前尚不清楚是否有必要围绕 IAM 代币进行讨论。如果上述建议不充分,请提供有关您要达到的目标的更多指导。


推荐阅读