Create Custom Extension

Hi

I’m trying to create a custom extension with the code published at github repo https://github.com/traveloka/auth0-authorization-exporter.

When I go to the Extensions page, click add extension button & put the url of the github repo, nothing happens when I clicked the continue button.

On checking the browser console, there is this error

raven.js:375 Uncaught TypeError:
e.replace is not a function
at r (https://cdn.auth0.com/extensions/webtask-gallery.standalone-2.1.min.js:502:175)
at Object.t.clean (https://cdn.auth0.com/extensions/webtask-gallery.standalone-2.1.min.js:502:1212)
at t.clean (https://cdn.auth0.com/extensions/webtask-gallery.standalone-2.1.min.js:502:1189)
at https://cdn.auth0.com/extensions/webtask-gallery.standalone-2.1.min.js:26:13404
at Array.map (native)
at t.value (https://cdn.auth0.com/extensions/webtask-gallery.standalone-2.1.min.js:26:13142)
at t.value (https://cdn.auth0.com/extensions/webtask-gallery.standalone-2.1.min.js:26:14260)
at Array. (https://cdn.auth0.com/extensions/webtask-gallery.standalone-2.1.min.js:26:16387)
at Array. (https://cdn.auth0.com/extensions/webtask-gallery.standalone-2.1.min.js:50:23899)
at u (https://cdn.auth0.com/extensions/webtask-gallery.standalone-2.1.min.js:50:22569)
at Object.fireWith [as resolveWith]
(https://cdn.auth0.com/extensions/webtask-gallery.standalone-2.1.min.js:50:23337)
at Array. (https://cdn.auth0.com/extensions/webtask-gallery.standalone-2.1.min.js:50:24025)
at u (https://cdn.auth0.com/extensions/webtask-gallery.standalone-2.1.min.js:50:22569)
at Object.fireWith [as resolveWith]
(https://cdn.auth0.com/extensions/webtask-gallery.standalone-2.1.min.js:50:23337)
at Object. (https://cdn.auth0.com/extensions/webtask-gallery.standalone-2.1.min.js:50:24670)
at u (https://cdn.auth0.com/extensions/webtask-gallery.standalone-2.1.min.js:50:22569)
at Object.fireWith [as resolveWith]
(https://cdn.auth0.com/extensions/webtask-gallery.standalone-2.1.min.js:50:23337)
at Object.o.(anonymous function) (https://cdn.auth0.com/extensions/webtask-gallery.standalone-2.1.min.js:50:24326)
at u (https://cdn.auth0.com/extensions/webtask-gallery.standalone-2.1.min.js:50:22569)
at Object.fireWith [as resolveWith]
(https://cdn.auth0.com/extensions/webtask-gallery.standalone-2.1.min.js:50:23337)
at r (https://cdn.auth0.com/extensions/webtask-gallery.standalone-2.1.min.js:51:26418)
at XMLHttpRequest. (https://cdn.auth0.com/extensions/webtask-gallery.standalone-2.1.min.js:52:232)
at XMLHttpRequest.d (https://cdn.ravenjs.com/3.5.1/raven.min.js:2:4273)

Have you added the git access token, the link looks dead and this might be a private repo.

The link is not dead. It’s because the ‘.’ at the end. It should have been

https://github.com/traveloka/auth0-authorization-exporter

Sorry my mistake. What do you mean by git access token?

hi @abhishek.hingnikar what do you mean git access token? If I look at the tutorial at https://auth0.com/docs/extensions/custom-extensions

None of them mentions the needs to create git access token.

My bad, I thought you were trying to sync a private repo. You can discard the comment, that repo should work, can you deploy it using the wt cli?

There is a typo in your webtask.json causing this error. The field at auth0-authorization-exporter/webtask.json at master · traveloka/auth0-authorization-exporter · GitHub should be “required”

hi @abhishek.hingnikar

Fixing the typo fixes the installation problem. But when it’s running, I get this error when I try to hit authorisation extension API user policy end point:

INFO wt: 
    170503/090512.431, [log,error] data: Request: POST /api/users/auth0|590817344dd40021eb8a76b0/policy/4IssBi2rK0rvWLHTwP3fOu2CIzp2C4an
    170503/090512.432, [log,error] data: Response: {
      "data": null,
      "isBoom": true,
      "isServer": false,
      "output": {
        "statusCode": 401,
        "payload": {
          "statusCode": 401,
          "error": "Unauthorized",
          "message": "Invalid token format",
          "attributes": {
            "error": "Invalid token format"
          }
        },
        "headers": {
          "WWW-Authenticate": "Token error=\"Invalid token format\""
        }
      }
    }

Why do I get invalid token format? The token I used is the token I get when I hit /oauth/token end point with audience set to ‘urn:auth0-authz-api’. This is the way I call the API

function getUserPolicy(domain, user_id, email, client_id, token) {
    return new Promise(function(resolve, reject) {
      var url = `${domain}/users/${user_id}/policy/${client_id}`;
      Request({
          method: 'POST',
          url: url,
          json: true,
          headers: {
              Authorization: `Bearer ${token}`,
              Accept: 'application/json'    
          },
          body: {
              connectionName: "Y"
          }
      }, (err, res, body) => {
          if (err) {
              console.log('Error getting user policy', err);
              reject(Error(err));
          } else {
              var userPermission = {};
              userPermission.client_id = client_id;
              userPermission.email = email;
              userPermission.permissions = body.permissions;
              resolve(userPermission);
          }
      });
    }); }

It works fine when I run it from the web task - tested it by running from the web task editor. But, I get the error when it’s run as an extension.