M2Mでアクセストークンを取得する(password) – 【Auth0】

M2Mでアクセストークンを取得する(password) – 【Auth0】

前提

  • Auth0アカウント作成済
  • Regular Web Appsタイプのアプリケーション作成済
  • Domainはdev-xxxx1xxxx111xxxx.jp.auth0.com

設定

passwordでトークン取得できるように「Applications」ー「Settings」画面の一番下にあるPasswordにチェックを入れて「Save Changes」をクリックします。

次に「Default Directory」の設定を行います。「Settings」をクリックします。

「General」タブの「Default Directory」に「Username-Password-Authentication」を指定します。

これで設定完了です。

M2Mでアクセストークン取得(password)

curlコマンドで実行します。

$ curl --request POST \
  --url 'https://dev-xxxx1xxxx111xxxx.jp.auth0.com/oauth/token' \
  --header 'content-type: application/x-www-form-urlencoded' \
  --data grant_type=password \
  --data client_id=mu9UwdImFvafUpX5c81xFoqiCXVlsHnN \
  --data client_secret=1K5jBMQbJhMII6RhILfJSKKdzUdiNTJ_KWzW7tE1gBGjHYwUDfczJjQ8yd0WC38d \
  --data audience=https://dev-xxxx1xxxx111xxxx.jp.auth0.com/api/v2/ \
  --data username=takahashi@example.com \
  --data password=abcd1234!

レスポンスが返ってきます。

{
    "access_token": "xxx...",
    "scope": "read:current_user update:current_user_metadata ...",
    "expires_in": 86400,
    "token_type": "Bearer"
}

M2MのリソースオーナーパスワードだとActionsが動作しない

M2MではActionsがありますが、Client Credential Flowの場合のみ動作します。

Resouce Owner Password FlowではActionsは動作しません。

参考サイト

Call Your API Using Resource Owner Password Flow
Learn how to call your own API from highly-trusted applications using the Resource Owner Password Flow.

コメント

株式会社CONFRAGE ITソリューション事業部をもっと見る

今すぐ購読し、続きを読んで、すべてのアーカイブにアクセスしましょう。

続きを読む

タイトルとURLをコピーしました