Search code examples
azureazure-web-app-servicemicrosoft-graph-apiazure-functionsfunction-binding

Using a single Azure Function to access multiple users' resources on their behalf


TL;DR: I'm not sure how to go about accessing multiple users' in our organization's calendar resources (read only), and if it's possible to do so in a single Azure Function. Any guidance to what I can do would be much appreciated.

As the title says, I'm looking for a way to access multiple user's resources on their behalf using Azure Functions and the Microsoft Graph API. Currently I have a little bit of experience using the Auth Token binding, but so far I've only been able to use a single user-id as an input to fetch the token they'd consented access to. I'd like to be able to access multiple users' tokens in a single function, regardless of if I need to use the Auth Token binding or coding in some other method of obtaining and retrieving said tokens. Currently the only way that I can see making this work with the Auth Token binding would be to create an Azure Function for each of our users individually, which would require an administrator to create a new function for each new user. Is there another way I can do this so that I can limit the requirements to a single function? My hope is to be able to loop through each token (or user-id to fetch said token) and check their calendar events in said loop. I like this because it means that any new users that are added will not need a new function created solely for them, which means less administration overhead. It's important to note that this is designed to run for < 10 users at a time and < 50 appt's per day. We will be running the function once per day at a certain time.

If you're wondering, our use case is to be able to look at multiple users' calendars in our organization and then be able to send reminder SMS messages to numbers included in each appointment in each users' calendar.


Solution

  • I see two main directions you could try:

    • Create an additional Azure Function that extracts all relevant user IDs and pass each ID to the second Azure Function (if you wish to continue using Token From ID).
    • You might be able to use OAuth's Client Credentials flow, meaning a dedicated token for the Azure Function that can be used to access the required resources. This might allow you to both iterate over the list of relevant users and extract the required information for each user in the same function.

    Hope it helps!