Github Deployments

The GitHub Deployments extension allows you to deploy rules and database connection scripts from GitHub to Auth0. You can configure a GitHub repository, keep all your rules and database connection scripts there, and have them automatically deployed to Auth0 each time you push to your repository.

Configure the extension

To install and configure this extension, click on the GitHub Deployments box in the list of provided extensions on the Extensions page of the dashboard. The Install Extension window will open.

Install Github Deployments Extension

Set the following configuration variables:

  • GITHUB_REPOSITORY: The repository from which you want to deploy rules and database scripts. This can be either a public or private repository.
  • GITHUB_BRANCH: The branch that the extension will monitor for commits.
  • GITHUB_TOKEN: Your GitHub personal access token. Follow the instructions at Creating an access token to create a token with repo scope.
  • SLACK_INCOMING_WEBHOOK_URL: The Webhook URL for Slack, used in order to receive Slack notifications for successful and failed deployments (optional).

Once you have provided this information, click Install.

Navigate to the Extensions page and click on the Installed Extensions tab.

Click on the row for the GitHub Deployments extension. The first time you click on your installed extension, you will be asked to grant it to access your GitHub account.

Grant Github Access

Once you agree, you will be directed to the GitHub Integration configuration page.

Configure Extension

The Configuration page will display the settings you will need to create a webhook in your GitHub repository pointing to the extension.

Copy these values into the Add Webhook page for your GitHub repository:

Add Webhook

NOTE: You can find details on how to configure a webhook at Creating Webhooks on GitHub.

Deployment

Once you have setup the webhook in GitHub using the provided information, you are ready to start committing to your repository.

With each commit you push to your configured GitHub repository, if changes were made in the rules or database-connection folders, the webhook will call the extension to initiate a deployment.

The Deploy button on the Deployments tab of the extension allows you to manually deploy the rules and database connection scripts you already have in your GitHub repository. This is useful if you already have a repository filled with scripts that you want to deploy once you have setup the extension, or if you have accidentally deleted some scripts in Auth0 and need to redeploy the latest version of your repository.

WARNING: Deleting Rules and Scripts from GitHub

To maintain a consistent state, the extension will always do a full redeployment of the contents of these folders. Any rules or database connection scripts that exist in Auth0 but not in your GitHub repository will be deleted.

Deploy database connection scripts

In order to deploy database connection scripts, you must first create a directory under database-connections. The name of the directory must exactly match the name of your database connection in Auth0. Of course, you can create as many directories as you have database connections.

Under the created directory, create one file for every script you want to use. The allowed scripts are:

  • get_user.js
  • create.js
  • verify.js
  • login.js
  • change_password.js
  • delete.js

Only the login.js script is required in a custom database connection.

If you enabled the migration feature, you will also need to provide the get_user.js script.

You can find an example in this GitHub repository.

Deploy Hosted Pages

The supported hosted pages are:

  • error_page
  • guardian_multifactor
  • login
  • password_reset

To deploy a page, you must create an HTML file under the pages directory of your GitHub repository. For each HTML page you need to create a JSON file (with the same name) that will be used to mark the page as enabled or disabled. For example, in order to deploy an error_page, you would create two files:

your-github-repo/pages/error_page.html
your-github-repo/pages/error_page.json

To enable the page the error_page.json would contain the following:

{
  "enabled": true
}

Deploy rules

In order to deploy a rule, you must first create a JavaScript file under the rules directory of your GitHub repository. Each rule must be in its own .js file.

For example, if you create the file rules/set-country.js, then the extension will create a rule in Auth0 with the name set-country.

NOTE: If you plan to use Source Control integration for an existing account, first rename your rules in Auth0 to the same name of the files you will be deploying to this directory.

You can mark rules as manual. In that case, the source control extension will not delete or update them. To mark a rule navigate to the Rules Configuration tab of the GitHub Integration page. Toggle the Manual Rule switch for the rules you want to mark as manual. Click Update Manual Rules to save your changes.

Manual Rules

You can control the rule order, status (enabled/disabled) and stage (login_success, login_failure, user_registration) by creating a JSON file with the same name as your JavaScript file. For this example, you would create a file named rules/set-country.json.

set-country.js

function (user, context, callback) {
  if (context.request.geoip) {
    user.country = context.request.geoip.country_name;
  }
  callback(null, user, context);
}

set-country.json

{
  "enabled": false,
  "order": 15,
  "stage": "login_success"
}

You can find examples in this GitHub repository.

Set the order

Multiple rules of the same order are not allowed. To avoid conflicts, you can create a JSON file for each rule and assign a value for order. If you leave enough space between these values, re-ordering them without conflicts will be easier. For example, if you have three rules, instead of setting their order to 1, 2, 3, you can set them to 10, 20, 30. This way, to move the 30 rule before the 20, you can simply change its order to any value between 11 and 19.

Set the stage

After you deploy a rule, you cannot change its stage. You would have to create a new rule with a new name and updated stage, and then delete the original rule. For the user_registration and login_failure stages, only a single rule is allowed.

Track deployments

To track your deployments, navigate to the extensions page, click on the row for the GitHub Deployments extension, and select the Deployments tab. You will see a list of all deployments, both successful and failed.

Deployments Overview

If a deployment fails, you can examine the details of the deployment to determine why. Details are also available for successful deployments.

Deployment Log

Also, if you configured a Slack Incoming Webhook, you will be notified on Slack if a deployment has succeeded or failed.

Slack Integration