Connect to Graph API with App Reg inside Azure Function

Bickel, Maxim 1 Reputation point
2022-11-30T13:57:23.04+00:00

Hi,

I am trying to connect to GraphAPI in order to get some users and put them into different Groups.
Is there any possibility to connect to the Graph API within an Azure Function using an App Reg (Cert oder Secret).

If it is possbile: how? And is it possible to run the Azure Function within Tenant A but connect to Tenant B (using Graph API).

Thanks for your help.

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
4,626 questions
Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
11,368 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Alistair Ross 7,106 Reputation points Microsoft Employee
    2022-11-30T14:53:55.94+00:00

    Hi @Bickel, Maxim

    Yes, it is possible. What you have to understand is that the function is just a code running on a computer, regardless of where it is. Therefore, all you need to do is provide the function the details of the App Registration and ensure that the function does not have any network limitations for connecting to the graph Api. (or any Api that you are wanting to connect to for that matter)

    Here is an example function https://learn.microsoft.com/en-us/samples/microsoftgraph/msgraph-sample-azurefunction-csharp/microsoft-graph-sample-azure-function.
    This sample demonstrates how to use the Microsoft Graph .NET SDK to access data in Office 365 from Azure Functions.

    Something to keep in mind is that the client secret isn't stored in the code, but referenced from a key vault within the functions application settings. Also make sure that the App Registration is created in Tenant B.

    I hope this helps provide you with the information you need. If it does, please make sure to mark the question as answered so it helps other people in future.

    Kind regards

    Alistair