How to Authenticate to Graph API from Azure Function App Using App Registration?

0
2
Asked By CreativeCactus92 On

I'm in the process of turning my PowerShell script into an Azure Function App, but I'm hitting a wall on how to authenticate with the Graph API using an App Registration. My current setup utilizes InteractiveBrowserCredential, allowing the Graph API operations to be performed on behalf of the signed-in user.

I've been trying to sign in using this code snippet:

`Connect-MgGraph -NoWelcome -ClientId $clientId -TenantId $tenantId -Scopes @(`

`"Permission1",`

`"Permission2",`

`...

)`

Is there a way to authenticate the Function App on behalf of the user from my calling script? If so, what's the best method to sign into my Function App to carry out the required actions?

2 Answers

Answered By TechWhiz42 On

It sounds like you already have a good start! If you're converting your PowerShell script into a Function App, make sure you set up a Key Vault to store your app's credentials securely. You'll want to give your Function App the necessary access to read those secrets as well. Don't forget to implement System Assigned Managed Identity for your Function App—this often simplifies API connections. Also, your app registration must have the right API permissions configured to align with the operations you're handling.

Answered By AzureSage77 On

Instead of managing secrets, I recommend leveraging the System Assigned Managed Identity of your Function App. This way, you can avoid dealing with the hassle of secret expiration and rotations. It should help streamline your Graph API permissions significantly. However, do note that System Managed Identity typically only supports delegated permissions. It sounds like your function aims to support PIM role activations, which indeed requires those delegated permissions to work correctly.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.