auth0/auth0-extension-boilerplate-hooks

Name: auth0-extension-boilerplate-hooks

Owner: Auth0

Description: null

Created: 2016-06-06 15:02:15.0

Updated: 2018-04-24 15:29:56.0

Pushed: 2016-09-30 01:07:20.0

Homepage: null

Size: 17

Language: JavaScript

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Working with hooks

Auth0 extensions supports hooks where you can add logic for creating artifacts required by your extension like rules, resource servers, etc.

Enabling hooks

For using hooks you will have to do two things.

h0": {
reateClient": true,
copes": "create:rules read:rules delete:rules",
nInstallPath": "/.extensions/on-install",
nUninstallPath": "/.extensions/on-uninstall"

use('/.extensions/on-install', ...);

use('/.extensions/on-uninstall', ...);

Note: if you don't add the entries to the webtask.json Auth0 extensions will not execute the hooks.

OnInstall Hook

Auth0 extensions will call the hook and if everything is OK it will process to install the extension.

Sample

In this example, we are creating a rule that will be used by the extension.

s.post('/on-install', function (req, res) {
q.auth0.rules.create({
name: 'extension-rule',
script: "function (user, context, callback) {\n  callback(null, user, context);\n}",
order: 2,
enabled: true,
stage: "login_success"

hen(function () {
res.sendStatus(204);

atch(function () {
res.sendStatus(500);
;

OnUninstall Hook

Auth0 extensions will call the hook and if everything is OK it will proceed to delete the extension.

Sample

In this example, we are deleting the rule created for the extension.

s.delete('/on-uninstall', function (req, res) {
q.auth0
.rules.getAll()
.then(function (rules) {
  var rule = _.find(rules, {name: 'extension-rule'});

  if (rule) {
    req.auth0
      .rules.delete({ id: rule.id })
      .then(function () {
        res.sendStatus(204);
      })
      .catch(function () {
        res.sendStatus(500);
      });
  }
})
.catch(function () {
  res.sendStatus(500);
});

Deploying as Auth0 Custom Extension
  1. Go to Auth0 Extensions
  2. Click on + Create Extension
  3. Fill in the textbox with https://github.com/auth0/auth0-extension-boilerplate-hooks
  4. Click on continue
  5. Finally, click on install
What is Auth0?

Auth0 helps you to:

Create a free Auth0 Account
  1. Go to Auth0 and click Sign Up.
  2. Use Google, GitHub or Microsoft Account to login.
Issue Reporting

If you have found a bug or if you have a feature request, please report them at this repository issues section. Please do not report security vulnerabilities on the public GitHub issue tracker. The Responsible Disclosure Program details the procedure for disclosing security issues.

Author

Auth0

License

This project is licensed under the MIT license. See the LICENSE file for more info.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.