0
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.

「gcloud auth application-default print-access-token」でトークン取得するまで

Posted at

サービスアカウントでトークン取得するまでの覚書です。

環境

Windows10
Google Cloud SDKインストール済み
https://cloud.google.com/sdk/docs/install?hl=JA

Google Cloud Platformでサービスアカウントを発行、プロジェクトIDとサービスアカウントをメモしておきます。

サービスアカウントのキーを発行

Google Cloud SDKで以下のコマンドを実行します。
※この後の作業のためにロールをオーナーにしていますが、終わったら戻しておきます。

gcloud projects add-iam-policy-binding [プロジェクトID] --member="serviceAccount:[サービスアカウント]" --role="roles/owner"

変更したら、続けて以下コマンドを実行します。

gcloud iam service-accounts keys create [キーのファイル名].json --iam-account=[サービスアカウント]

成功するとローカルにJSONファイルが作成されます。
私の環境ではSDKのインストールディレクトリ内に作られていました。

環境変数を登録する

作成したJSONファイルを環境変数に登録します。

set GOOGLE_APPLICATION_CREDENTIALS=C:\Users\[ファイルまでのパス]\[キーのファイル名].json

トークン発行

gcloud auth application-default print-access-token

できた!
スクリーンショット 2021-09-09 16.36.27.png
何気に面倒なのであんまりやりたくないですね。

0
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
0
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?