1. OAuth同意画面の作成
- GCPコンソールから「APIとサービス」 > 「OAuth同意画面」を開く
- 「内部」 or 「外部」の選択 => 今回はテスト目的のため「内部」を選択
- アプリ名、ユーザサポートメール、デベロッパーの連絡先情報を埋める
- スコープを選択 => 今回はBigQuery APIを選択 (.../auth/bigquery)
2. OAuthクライアントIDの作成
- GCPコンソールから「APIとサービス」 > 「認証情報」を開く
- 「認証情報を作成」 > 「OAuthクライアントID」を選択
- アプリケーションの種類から「ウェブアプリケーション」を選択
- 承認済みの JavaScript 生成元 : https://example.com
- 承認済みのリダイレクト URI : https://example.com/oauth2redirect
3. アクセストークンの取得
認可エンドポイント
https://accounts.google.com/o/oauth2/v2/auth
クエリパラメータ
- client_id=<CLIENT_ID>
- scope=https://www.googleapis.com/auth/bigquery
- redirect_uri=https://example.com/oauth2redirect
- response_type=token # インプリシットグラントフローの場合はtoken
% CLIENT_ID=<CLIENT_ID>
% REDIRECT_URI=$(echo "https://example.com/oauth2redirect" | nkf -WwMQ | sed 's/=$//g' | tr = % | tr -d '\n')
% SCOPE=$(echo "https://www.googleapis.com/auth/bigquery" | nkf -WwMQ | sed 's/=$//g' | tr = % | tr -d '\n')
% echo "https://accounts.google.com/o/oauth2/v2/auth?redirect_uri=$REDIRECT_URI&response_type=token&client_id=$CLIENT_ID&scope=$SCOPE"
出力されたURLをブラウザで開いて認証及び認可するとリダイレクトURIのハッシュパラメータにアクセストークンが含まれている。
https://example.com/oauth2redirect#access_token=<access_token>&token_type=Bearer&expires_in=3599&scope=https://www.googleapis.com/auth/bigquery
4. アクセストークンの取り消し
curl 'https://accounts.google.com/o/oauth2/revoke?token=<access_token>'