ROMANCE DAWN for the new world

Microsoft Azure を中心とした技術情報を書いています。

Postman で Azure Active Directory 認証された API のアクセストークンを取得する

Postman を使って、Azure Active Directory 認証された API のアクセストークンを取得する方法のメモです。

Azure Active Directory にアプリケーションを登録する

Azure Portal で Postman 用の Azure AD アプリケーションを登録します。

必須項目 設定値
Redirect URIs https://www.getpostman.com/oauth2/callback
Client secrets 自動生成(後から確認できないのでメモしておく)
API permissions Postman からアクセスしたい API

API Permission は、add a permission をクリックして選択できます。忘れずに、Grant admin consent for 既定のディレクトリも設定しておきます。
右側に表示される API Permission Name は、Postman 側の設定で必要なのでメモしておきます。

f:id:TonyTonyKun:20200912162207p:plain

アプリケーションを登録できたら、Postman 側の設定で必要な情報をメモします。
まずは、Application (client) ID です。

f:id:TonyTonyKun:20200912155813p:plain

次に、Endpoints をクリックして表示される2つのエンドポイントです。

  • OAuth 2.0 authorization endpoint (v2)
  • OAuth 2.0 token endpoint (v2)

f:id:TonyTonyKun:20200912160008p:plain

Postman でアクセストークンを取得する

Postman では、Authorization タブから OAuth 2.0 を選択して、Get New Access Token をクリックします。

f:id:TonyTonyKun:20200912160750p:plain

上記の画面で、それぞれの項目を設定して、Request Token ボタンを押します。

項目 設定値
Token Names 任意の名前
Auth URL OAuth 2.0 authorization endpoint (v2)
Access Token URL OAuth 2.0 token endpoint (v2)
Client ID Application (client) ID
Client Secret Client Secrets
Scope API Permission Name
Grant Type Authorization Code

取得したアクセストークンを Authorization ヘッダーにセットすれば、Azure Active Directory 認証された API にアクセスできます。

f:id:TonyTonyKun:20200912161537p:plain