1
3

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.

【Auth0】テナント設定をExportする

Posted at

はじめに

Auth0のテナント設定はExtensionの「Auth0 Deploy CLI」を使うとExportとImportをすることができます。
今回は「Auth0 Deploy CLI」を使ってExportをやってみました。

Extensionのインストール

Auth0の管理画面のExtensionsメニュー内の「Auth0 Deploy CLI」を選択してインストールします。

スクリーンショット 2020-08-27 10.11.51.png

インストール後に拡張機能を開くと基本的な使い方が記載されたページが開きます。

スクリーンショット 2020-08-27 10.30.24.png

CLIツールのインストールと設定ファイルの作成

以下のコマンドでCLIツールをインストールします。

npm i -g auth0-deploy-cli

Auth0の管理画面にアクセスし、Extensionのインストール時に作成されたauth0-deploy-cli-extensionのアプリケーション設定を開きます。

スクリーンショット 2020-08-29 23.46.17.png

auth0-deploy-cli-extensionの設定画面に記載されているDomain, Client ID, Client Secretをもとに以下のようなjsonファイルを作成します。ファイル名は任意ですが今回はconfig.jsonというファイル名で作成しました。

config.json
{
  "AUTH0_DOMAIN": "{テナントドメイン}",
  "AUTH0_CLIENT_ID": "{クライアントID}",
  "AUTH0_CLIENT_SECRET": "{クライアントシークレット}",
}

このconfig.jsonファイルの保存場所をCLIツールの引数に指定して設定内容を読み込ませます。

auth0-deploy-cliのヘルプ情報

auth0-deploy-cliのヘルプ情報を出力してみます。

コマンド
a0deploy --help 
出力
Auth0 Deploy CLI

コマンド:
  a0deploy import  Deploy Configuration  [エイリアス: deploy]
  a0deploy export  Export Auth0 Tenant Configuration  [エイリアス: dump]

オプション:
  --help           ヘルプを表示  [真偽]
  --version        バージョンを表示  [真偽]
  --debug, -d      Dump extra debug information.  [真偽] [デフォルト: false]
  --proxy_url, -p  A url for proxying requests, only set this if you are behind a proxy.  [文字列]

例:
  a0deploy export -c config.json -f yaml -o path/to/export       Dump Auth0 config to folder in YAML format
  a0deploy export -c config.json -f directory -o path/to/export  Dump Auth0 config to folder in directory format
  a0deploy import -c config.json -i tenant.yaml                  Deploy Auth0 via YAML
  a0deploy import -c config.json -i path/to/files                Deploy Auth0 via Path
  a0deploy dump -c config.json -f yaml -o path/to/export         Dump Auth0 config to folder in YAML format
  a0deploy dump -c config.json -f directory -o path/to/export    Dump Auth0 config to folder in directory format
  a0deploy deploy -c config.json -i tenant.yaml                  Deploy Auth0 via YAML
  a0deploy deploy -c config.json -i path/to/files                Deploy Auth0 via Path

See README (https://github.com/auth0/auth0-deploy-cli) for more in-depth information on configuration and setup.

YAML形式でExportする

ヘルプ情報の通り以下のコマンドを使用するとテナント設定をYAML形式でExportできます。

a0deploy export -c config.json -f yaml -o path/to/export
  • -cのあとに、事前に作成したconfig.jsonファイルの保存場所を指定します。
  • -oのあとに、Exportしたファイルの保存先ディレクトリを指定します。

上記コマンドを実行すると以下のような構成でテナント設定がファイル出力されます。

|--path
|  |--to
|  |  |--export
|  |  |  |--connections
|  |  |  |  |--email.html
|  |  |  |--emailTemplates
|  |  |  |  |--verify_email.html
|  |  |  |--pages
|  |  |  |  |--login.html
|  |  |  |  |--password_reset.html
|  |  |  |--rules
|  |  |  |  |--auth0-account-link-extension.js
|  |  |  |--tenant.yaml

大部分のテナント設定はtenat.yamlに記載されています。
その他のUniversal Loginなどのテンプレート設定はhtml形式で、Rulesの内容はjsファイルで出力されます。

Directory形式でExportする

YMAL形式意外にもDirectoryという形式でExportすることができます。
Directory形式だと設定ファイルはjsonになり、テナント内の各設定がディレクトリ別に出力されます。

a0deploy export -c config.json -f directory -o path/to/export

config.jsonやExportファイルの保存先の設定はYAML形式のときと同じです。

|--path
|  |--to
|  |  |--export
|  |  |  |--clients
|  |  |  |  |--Auth0 Management API (Test Application).json
|  |  |  |  |--My App.json
|  |  |  |  |--auth0-account-link.json
|  |  |  |  |--auth0-deploy-cli-extension.json
|  |  |  |--connections
|  |  |  |  |--email.html
|  |  |  |  |--email.json
|  |  |  |  |--google-oauth2.json
|  |  |  |--database-connections
|  |  |  |  |--Username-Password-Authentication
|  |  |  |  |  |--database.json
|  |  |  |--emails
|  |  |  |  |--provider.json
|  |  |  |  |--verify_email.html
|  |  |  |  |--verify_email.json
|  |  |  |--grants
|  |  |  |  |--Auth0 Management API (Test Application).json
|  |  |  |  |--auth0-account-link.json
|  |  |  |--guardian
|  |  |  |  |--factors
|  |  |  |  |  |--duo.json
|  |  |  |  |  |--email.json
|  |  |  |  |  |--otp.json
|  |  |  |  |  |--push-notification.json
|  |  |  |  |  |--sms.json
|  |  |  |  |--phoneFactorMessageTypes.json
|  |  |  |  |--phoneFactorSelectedProvider.json
|  |  |  |  |--policies.json
|  |  |  |  |--providers
|  |  |  |  |--templates
|  |  |  |--pages
|  |  |  |  |--login.html
|  |  |  |  |--login.json
|  |  |  |  |--password_reset.html
|  |  |  |  |--password_reset.json
|  |  |  |--resource-servers
|  |  |  |--roles
|  |  |  |--rules
|  |  |  |  |--auth0-account-link-extension.js
|  |  |  |  |--auth0-account-link-extension.json
|  |  |  |--tenant.json

テンプレート設定やRulesの出力形式はYAML形式の時と同じです。(htmlとjs)

おわりに

Exportしたテナント設定のファイルはテキストベースなので設定変更時の差分管理がやりやすくなります。
テナント設定ファイルはGit等のバージョン管理ツールに登録しておくことをおすすめします。

1
3
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
1
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?