I want to let third-party organizations subscribe to my event grid events in a secure way. I am trying to do this using Azure AD as mentioned in the articles below.
https://learn.microsoft.com/en-us/azure/event-grid/security-authentication
https://learn.microsoft.com/en-us/azure/event-grid/secure-webhook-delivery
In the event subscription creation, I selected the WebHook endpoint type and entered the endpoint of the organization. For a proof of concept, I created an Azure Function (HttpTrigger) as a webhook endpoint out of my Azure AD.
Under the Additional Feature tab, I activated AAD Authentication. In this way, I managed to send a bearer token to the webhook endpoint.
My question is that how should the event subscriber validate the token which is coming from the event publisher?
When you want to make a request to an API that is secured with a bearer token authentication, you would first request a token from the API, make your request with that token and the API validates it. In this scenario, the token issuer and validator are the same.
In the event publisher/subscriber scenario, the subscriber is not the token issuer. That's what confuses me.
When the token is decrypted, it is kind of obvious where it comes from.
{
"aud": "00000000-0000-0000-0000-000000000000",
"iss": "https://sts.windows.net/00000000-0000-0000-0000-000000000000/",
"iat": 1612970997,
"nbf": 1612970997,
"exp": 1613057697,
"aio": "Lorem ipsum viverra",
"appid": "00000000-0000-0000-0000-000000000000",
"appidacr": "2",
"idp": "https://sts.windows.net/00000000-0000-0000-0000-000000000000/",
"oid": "00000000-0000-0000-0000-000000000000",
"rh": "Lorem ipsum viverra",
"roles": [
"role"
],
"sub": "00000000-0000-0000-0000-000000000000",
"tid": "00000000-0000-0000-0000-000000000000",
"uti": "Lorem ipsum viverra",
"ver": "1.0"
}
Should I just validate the token by having some constants about the event publisher or is there a more elegant way?
Update: In case anyone is interested in how I implemented it, I leave a demo project here.