はじめに
Auth0のテナント設定はExtensionの「Auth0 Deploy CLI」を使うとExportとImportをすることができます。
今回は「Auth0 Deploy CLI」を使ってExportをやってみました。
Extensionのインストール
Auth0の管理画面のExtensions
メニュー内の「Auth0 Deploy CLI」を選択してインストールします。
インストール後に拡張機能を開くと基本的な使い方が記載されたページが開きます。
CLIツールのインストールと設定ファイルの作成
以下のコマンドでCLIツールをインストールします。
npm i -g auth0-deploy-cli
Auth0の管理画面にアクセスし、Extensionのインストール時に作成されたauth0-deploy-cli-extension
のアプリケーション設定を開きます。
auth0-deploy-cli-extension
の設定画面に記載されているDomain
, Client ID
, Client Secret
をもとに以下のような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等のバージョン管理ツールに登録しておくことをおすすめします。