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 1 year has passed since last update.

Auth0 API認可制御の検証手順 メモ

Posted at
  • Auth0でのAPI認可制御について検証した際の手順をメモしておく。

Auth0各要素の関係性

auth0_api.png

検証準備

APIを定義する

  1. ダッシュボード画面 -> Applications -> APIsを選択する。
  2. 「Create API」を押下する。
  3. Name、Identifierを入力する。
    • Name:API名
    • Identifier:APIエンドポイント
      • 今回はhttp://localhost:3000/usersとする。
  4. Permissionsを選択する。
  5. API呼び出しに必要なPermission(スコープ)を設定する。
    • 今回はtestとする。

アプリケーション(クライアント)を定義する

  1. ダッシュボード画面 -> Applications -> Applications を選択する。
  2. 今回は「Single Page Application」を選択する。※任意
  3. Settingsの下記項目を設定する。
    • Allowed Callback URLs : http://localhost:3000
    • Allowed Logout URLs : http://localhost:3000
    • Allowed Web Origins : http://localhost:3000

動作検証

※認可コードグラントで取得したアクセストークンのペイロードを確認する。

  1. 認可エンドポイントへアクセスする。

    • https://{tenant_url}/authorize?client_id=....&redirect_uri=http://localhost:3000&scope=read:test&state=....&response_type=code&audience=http://localhost:3000/users

      audienceにAPI定義のidentifierを指定し、scopeにAPI定義のPermissionを設定する。

  2. ログインする。

  3. 同意画面で同意する。※スコープtestが表示される。

  4. 3後にhttp://localhost:3000へリダイレクトされた際に指定された認可コードを取得する。

  5. 認可コードを指定してアクセストークンを取得する。

    POST /oauth/token HTTP/1.1
    Host: {tenant_url}
    Content-Type: application/x-www-form-urlencoded
    Content-Length: 256
    
    code=...&redirect_uri=http%3A%2F%2Flocalhost%3A3000&scope=test&client_id=...&client_secret=...&grant_type=authorization_code
    
  6. アクセストークンをデコードする。

auth0_access_token_jwt.png

audにAPI定義のIdentifierscopeにAPI定義のpermissionが設定されていることを確認できる。※認可リクエスト時に指定したもの。

※呼び出されたAPI側はこちらの手順に従って、アクセストークンの検証を行う。

参考情報

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?