Using Microsoft Graph .NET Client Library in Azure Functions

I use this code sample as a demo in my conference session “Building serverless applications with Microsoft Graph and Azure Functions” which I presented at several conferences in 2018. Slides can be found on my SlideShare profile.

Azure Functions bindings for Microsoft Graph provide functionality for accessing Microsoft Graph from Azure Functions. One of bindings is auth token binding, which gets an Azure AD bearer token that is in turn used for authentication of subsequent calls to Microsoft Graph.

If we create function from “Microsoft Graph profile photo API” template, the function will retrieve profile photo for current user by making REST call which is authenticated by passing authentication token in the call header. Sufficient permissions will be configured when function is created.

When auth token extension is installed it will also install DLLs for .NET SDK for Microsoft Graph, because those DLLs are prerequisites for auth token extension. We can verify that by checking if SDK DLLs exist in BIN folder for Azure Function app:

Now we can modify code of the function created by template:

We need to reference both Microsoft.Graph and Microsoft.Graph.Core DLLs. These two lines should be added on top of the run.csx, above 'using' statements