1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

IBM Cloud の IAM トークンの中身を確認する

Last updated at Posted at 2020-08-31

IAM トークンとは

IBM Cloud アクセストークンとも呼ばれます。
トークンを使うことで認証されたリソースアクセスを行うことができます。

CLI では ibmcloud iam oauth-tokens のコマンドで取得できます。

CLI を使用したアクセス・トークンの取得

IAM トークンは <ヘッダー>.<ペイロード>.<署名> の形式をとる JSON Web Token (JWT) です。

JSON Web Token (JWT) とは

こちらの外部記事が参考になります。

JWTとはJSON Web Tokenの略称であり、属性情報(Claim)をJSONデータ構造で表現したトークンの仕様です。
仕様はRFC7519(外部サイト)で定められています。
特徴として、署名、暗号化ができ、URL-safeであることなどが挙げられます。発音は"ジョット"です。

参考:JSON Web Token(JWT)の紹介とYahoo! JAPANにおけるJWTの活用 - Yahoo! JAPAN Tech Blog

JWT デコード

以下のようなコマンドで自身の IAM トークンの中身を確認できます。
自身が取得して変数に格納した値が正しい内容かの確認にも使えますね。


ibmcloud login -a cloud.ibm.com
export IAM_TOKEN=$(ibmcloud iam oauth-tokens | awk '{print $4}')
echo $IAM_TOKEN | cut -d. -f1 | base64 -D | jq -r \
&& echo $IAM_TOKEN | cut -d. -f2 | base64 -D | jq -r
result
{
  "kid": "xxxxxxxxxxxx",
  "alg": "RS256"
}
{
  "iam_id": "IBMid-xxxxxxXXXX",
  "id": "IBMid-xxxxxxXXXX",
  "realmid": "IBMid",
  "identifier": "xxxxxxXXXX",
  "given_name": "Taro",
  "family_name": "Hoge",
  "name": "Taro Hoge",
  "email": "xxx",
  "sub": "xxx",
  "account": {
    "valid": true,
    "bss": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
    "ims_user_id": "xxxxxx",
    "ims": "xxxxxxx"
  },
  "iat": 1598853406,
  "exp": 1598857006,
  "iss": "https://iam.cloud.ibm.com/identity",
  "grant_type": "urn:ibm:params:oauth:grant-type:passcode",
  "scope": "ibm openid",
  "client_id": "bx",
  "acr": 1,
  "amr": [
    "pwd"
  ]
}

また、jwt.io のサイトでもオンラインでデコードが可能です。
上記サイトではサーバー保存は行わないと明記されていますが、IAM トークンを使えばユーザーリソースにアクセスできてしまうので IAM トークンの取り扱いには注意しましょう。

参考

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?