This is an example repo of how to receive an event from Azure Event Grid in the Node runtime, handling AAD / MS Graph auth.
For some reason, there's no SDK for doing this, so I had to roll it semi-manually.
Azure has different ways to deliver events, but we're specifically using the Event Grid.
An Event Grid can send events to many things, but we're sending events to an HTTP endpoint, as it's more versatile than anything else.
An Event Grid can send events in 2 formats to an HTTP endpoint, and we're using the open standard CloudEvents, as it's preferred and portable.
We're using an open source tool called SirTunnel for ssh tunneling
- In Azure, create a virtual machine (whatever the cheapest one is), and make sure to expose ports 22, 80, and 443
- Click on the IP address of your VM and set a DNS name label (your domain name is now back on the homepage of the VM)
- Add your public key under VM -> Reset Password. Make sure to select Use existing public key, and paste your public key
- SSH into your VM, clone SirTunnel, add
sirtunnel.pyto the PATH, and runrun_server.sh
$ ssh <ip of vm>
> git clone https://github.com/anderspitman/SirTunnel
> ln -s ./SirTunnel/sirtunnel.py ./.local/bin/sirtunnel.py
> cd SirTunnel
> ./run_server.sh- In another terminal on your local machine, create the tunnel on whatever port you want, using the domain name of your VM
$ ssh -tR 9001:localhost:<port> <ip> sirtunnel.py <domain name> 9001- In Azure, create an Application Registration under an Enterprise Application
- In Azure, create an Event Grid Topic (just follow the Create a custom topic instructions, ignore the rest of the page, and choose a better name)
- Clone this repo, easy
- Copy
example.envto.env
git clone https://github.com/andrewschmidgit/aeg-subscriber-example.git
cp example.env .env- Set
CLIENT_IDandTENANT_IDfrom the App Registration you created in Azure Setup step 1 - Set
PORTto whatever you used back in Configure SSH Tunneling step 5 - Run
npm i, thennpm run devto run the app
npm i
npm run devUpon creation of the subscription, Event Grid will send a validation request to our app, so every other step should be completed before this.
- In Azure, on the Event Grid Topic you created earlier, create a new Event Subscription
- Give it a name
- For Event Schema select
Cloud Event Schema v1.0 - For Endpoint Type select
Web Hook - For Endpoint, paste in the domain of your VM, prepended by
https://, and with/eventat the end
https://<name>.<region>.cloudapp.azure.com/event
- Under Additional Features, check the
Use AAD authenticationbox, and paste in yourTENANT_IDandCLIENT_IDinto AAD Tenant ID and AAD Application ID or URI respectively - Click Create
In the app's console, you should see the contents of the JWT printed out for you