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 Actionsを用いたカスタムロジック組み込み方法メモ

Posted at

Actionsとは

  • ログインやユーザー登録前後など特定のユースケース(Flow)に独自定義したロジックを組み込むAuth0の機能
    • 例:ログイン時にユーザーのメールアドレス検証状態を確認する、など

設定方法

カスタムロジックを定義する

  1. ダッシュボード画面 -> Actions -> Flowsを選択する。

  2. 処理を加えるFlowを選択する。

  3. 処理を加えるフローを選択する。※今回は「Login

  4. Add Action -> Custom -> 「+」を選択する。

  5. Build Customを選択する。

  6. Create Actionウィンドウが開かれるため、Name(カスタムロジック名)を入力する。

    • Trigger : Login / Post Login※変更なし
    • Runtime : Node 16変更なし
  7. カスタムロジックを記述する。

    ※ログインユーザーがメールアドレス未検証の場合にブロックする例

    exports.onExecutePostLogin = async (event,api) => {
        // メールアドレス未検証の場合はブロックする
        if (!event.user.email_verified){
            api.access.deny('Access Denied (Not Email Verified)')
        }
    }
    

    ※実装に必要なnode依存関係を追加したい場合はAdd Dependencyを選択し、対象のライブラリとそのバージョンを入力する。

    ※機微情報をコードに直接記述したくない場合はDefine Secretを選択し、KeyとValueを入力する。event.secrets.{Key名}のように参照する。

  8. Save Draft -> Deployを選択する。

Flow内にカスタムロジックを配置する

  1. Loginフローに戻り、Customを選択する。
  2. 定義したカスタムロジックをフローの差し込みたい箇所にドラッグ&ドロップする。
  3. Applyを押下する。

参考情報

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?