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.

AzureADでDeviceCodeFlow

Last updated at Posted at 2020-10-05

概要

  • AzureADでDeviceCodeFlowを使った認証をします。
  • RedirectURIを用いない認証が可能です

アプリの登録

  • まず実験用のアプリを登録します
  • Azure Portalに入る
    https://portal.azure.com/
  • AzureActiveDirectoryを選ぶ
  • アプリの登録を選ぶ
  • 新規登録を選ぶ
  • 名前は適当、アカウントの種類は「マルチテナント+個人アカウント」
  • リダイレクトURIは省略(後で設定する)

アプリの設定

  • 認証を開く
  • プラットフォームを追加
  • 「モバイルアプリとデスクトップアプリ」を選ぶ
  • https://login.microsoftonline.com/common/oauth2/nativeclient 」にチェックを入れて「構成」を押す
  • 「既定のクライアントの種類」で「はい」を選ぶ
  • 最後に「保存」を押す
  • 概要ページに移動して「アプリケーション (クライアント) ID」をメモっておく

Tokenの取得

  • curlでTokenを取得します。
$ curl -X POST -d 'client_id=クライアントID&scope=user.read%20openid%20profile%20offline_access' https://login.microsoftonline.com/common/oauth2/v2.0/devicecode
  • レスポンスが表示されたら、verification_uri、user_code、device_codeをメモっておく
  • verification_uriをブラウザで開いて、user_codeを入力する
  • 入力しおわったら、トークンを取得する
curl -X POST -d 'client_id=クライアントID&grant_type=urn:ietf:params:oauth:grant-type:device_code&device_code=デバイスコード' https://login.microsoftonline.com/common/oauth2/v2.0/token
  • これでaccess_token, id_token, refresh_tokenが取得できているはずです

自分のプロファイルの取得

  • GraphAPIで自分のプロファイルを読んでみます
$ curl -H "Authorization: Bearer アクセストークン" https://graph.microsoft.com/v1.0/me

参考URL

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?