Skip to content

Instantly share code, notes, and snippets.

@coco98
Last active June 6, 2018 01:17
Show Gist options
  • Save coco98/302e98b2897b2648463d12ae73c520db to your computer and use it in GitHub Desktop.
Save coco98/302e98b2897b2648463d12ae73c520db to your computer and use it in GitHub Desktop.
Adding a preSignup hook

Requirements

  • You have an existing Hasura project, cluster
  • You have a microservice running where you can add a webhook
  • You have kubectl installed. Check by running: kubectl get pods -n hasura which should list all the hasura microservices

Step 1: Update the platform to v0.15.34+

Check your platform version:

$ hasura cluster status
Cluster name:       altar40                       
Cluster alias:      hasura
Kubectl context:    altar40
Platform version:   v0.15.31
Cluster state:      Synced

If the platform version is below v0.15.34 run the following command to update the platform:

kubectl set image -n hasura deployment/platform-sync shukra=hasuraci/shukra:v0.15.34

Step 2: Add a webhook in your microservice

Add a webhook to your microservice (you could even use any public endpoint):

var bodyParser = require('body-parser');

app.use(bodyParser.json());

app.post('/hook', (req, res) => {

  // req.body contains the entire signup/login request payload
  console.log(req.body);
  
  // return the roles you'd like to assign
  // return content-type: application/json roles array
  res.json({roles: ["somerole"]);
});

Step 3: Configure Hasura auth to call your hook

Add the following block to your conf/auth.yaml file:

authorizationHooks:
  preSignupHook: "http://api.default/hook"

This assumes that you have a microservice called api running in the default namespace running a POST webhook at /hook. You can replace this with any HTTP/HTTPS url.

Step 4: Deploy everything

git add conf/auth.yaml microservices/api
git commit -am 'adds hook'
git push hasura master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment