LoginSignup
1
1

More than 1 year has passed since last update.

[OAuth2] インプリシットグラントフロー

Last updated at Posted at 2021-08-14

1. OAuth同意画面の作成

  • GCPコンソールから「APIとサービス」 > 「OAuth同意画面」を開く
  • 「内部」 or 「外部」の選択 => 今回はテスト目的のため「内部」を選択
  • アプリ名、ユーザサポートメール、デベロッパーの連絡先情報を埋める
  • スコープを選択 => 今回はBigQuery APIを選択 (.../auth/bigquery)

2. OAuthクライアントIDの作成

  • GCPコンソールから「APIとサービス」 > 「認証情報」を開く
  • 「認証情報を作成」 > 「OAuthクライアントID」を選択
  • アプリケーションの種類から「ウェブアプリケーション」を選択

3. アクセストークンの取得

認可エンドポイント

https://accounts.google.com/o/oauth2/v2/auth

クエリパラメータ

% 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>'
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