0
0

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.

OIDC (OpenID Connect) のフロー

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

クエリパラメータ

ref. https://developers.google.com/identity/protocols/oauth2/openid-connect#authenticationuriparameters

  • client_id=<CLIENT_ID>
  • response_type=code # インプリシットフローの場合はtoken
  • scope="openid email" # OIDCの基本的なリクエストではopenidとemailが必要
  • redirect_uri=<REDIRECT_URI>
% CLIENT_ID=<CLIENT_ID>
% REDIRECT_URI=$(echo "urn:ietf:wg:oauth:2.0:oob" | nkf -WwMQ | sed 's/=$//g' | tr = % | tr -d '\n')
% SCOPE=$(echo "openid email" | nkf -WwMQ | sed 's/=$//g' | tr = % | tr -d '\n')
% echo "https://accounts.google.com/o/oauth2/v2/auth?response_type=code&client_id=$CLIENT_ID&scope=$SCOPE&redirect_uri=$REDIRECT_URI"

出力されたURLをブラウザで開くとOAuth同意画面にリダイレクトされ、同意すると認可コードが取得できる。

スクリーンショット 2021-08-15 1.09.04.png

4. アクセストークン、IDトークンの取得

トークンエンドポイント

https://oauth2.googleapis.com/token

クエリパラメータ

  • code=<認可コード>
  • client_id=<CLIENT_ID>
  • client_secret=<CLIENT_SECRET>
  • redirect_uri=<REDIRECT_URI>
  • grant_type=authorization_code
% CLIENT_SECRET=<CLIENT_SECRET>
% CODE=$(echo "4/1AX4XfWimLiJLj9Ru-bgcnG5zGhOcUtORu_uEEYSKRiHPTjpY6rW4Ua0Zdjw"|nkf -WwMQ|sed 's/=$//g'|tr = %|tr -d '\n')
% curl -XPOST 'https://oauth2.googleapis.com/token' -d "code=$CODE&redirect_uri=$REDIRECT_URI&client_id=$CLIENT_ID&client_secret=$CLIENT_SECRET&scope=&grant_type=authorization_code"

5. id_tokenのデコード

以下のサイトなどよりid_tokenをデコードして中身を確認できる。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?