Putting some more FUN into Azure Functions, Managed Identity & Microsoft Graph

Published Aug 09 2021 11:14 AM 2,701 Views

Usecase & purpose of this blog post

I want to show, how you can use a Managed Identity in Azure Functions to get an access token for Microsoft Graph API.

 

image-8.png

Prerequisites to benefit from this article:

To get the most out of this post, you should understand the following concepts – I included some links that should help you getting started.

Managed Identity – What is that and why would I want one?

Managed Identities are the state-of-the-art way to get Azure Active Directory access tokens, because you won’t need to handle credentials, which is of course a security benefit

>…where there are credentials, there are leaks ¯\_(ツ)_/¯

If you are unfamiliar with tokens, this article by Lee Ford will help. This is not a full tutorial on Managed Identities, for more information please start to read here. Also, Yannick Reekmans posted an entire series on Managed Identities, highly recommended to read this – helped me a lot to understand.

Azure Functions

If you’d like to deploy and execute code without needing to THINK about server infrastructure or VMs, you may like Azure Functions. Azure Functions can be written in a lot of languages and you can deploy and execute Azure Functions on any platform that can run .NET Core. Azure functions are scalable, as they use compute-on-demand: More resources are allocated automagically, when the demand of execution increases. If the demand decreases again, you don’t need to worry about the extra resources anymore as they drop off again. This way, you only pay what you need. For more info please start to read here: Azure Functions Overview | Microsoft Docs

I will use PowerShell for my Azure Functions, so that IT-Pros can benefit from this post as well. But please do choose your poison your favourite language, the concept stays the same. Use whatever you are familiar with or what makes you happy.

Microsoft Graph

Microsoft Graph is THE API to access Microsoft 365 resources, in our case we will want to read all Microsoft 365 groups – for more information see also the Microsoft Graph permissions reference – Microsoft Graph | Microsoft Docs.

Our challenge will be to access the Graph API with a Managed Identity. I will show how to do this entirely in Azure CLI & VS Code. Creating and assigning Managed Identities has been shown often before in the Azure portal, but a script would allow for automation, it is usually faster than working in a visual environment and you can use the tool of your choice. I highly recommend VS Code as editor (and I like the built-in terminal as well).

Create your Azure Functions locally

You still may create your first Azure Functions in the Azure Portal (I did as well), which demoes really nicely, but as we want to go for real world, I will show how to develop your Azure Functions in Visual Studio code. This has some great advantages:

  • you develop locally using the tools that you are already familiar with
  • you don’t need to adjust to ever changing UI in Azure portal
  • you can benefit from source control
  • you can collaborate with others

I covered how to do this also in a previous post, but for the sake of a start-to-end scenario, here we go again:

  • Install the Core Tools package with npm install -g azure-functions-core-tools@3 --unsafe-perm true
  • Install the Azure Functions extension for VS Code
  • Select New Project
  • Select a folder for your project
  • Select a language – I will use PowerShell
  • Select HTTP trigger as a template
  • Type in a better name like GetGraphToken
  • Select Authorization level Function
  • Select how you want to open your project – I prefer Add to workspace
  • You will now see your Local Project in the pane.

 

(yes, my pane is on the right hand side so that my code doesn’t “jump” all the time when I am expanding or collapsing the pane)

We will now write the code for our Azure Functions. Replace the default code of run.ps1 in VS Code by this:

 

using namespace System.Net

# Input bindings are passed in via param block
param($Request, $TriggerMetadata)

# Write to the Azure Functions log stream.
Write-Host "PowerShell HTTP trigger function processed a request."

# Interact with query parameters or the body of the request
.$Scope = $Request.Query.Scope
if (-not $Scope) {
$Scope = $Request.Body.Scope
}
#If parameter "Scope" has not been provided, we assume that graph.microsoft.com is the target resource
If (!$Scope) {
$Scope = "https://graph.microsoft.com/"
}

$tokenAuthUri = $env:IDENTITY_ENDPOINT + "?resource=$Scope&api-version=2019-08-01"
$response = Invoke-RestMethod -Method Get -Headers @{"X-IDENTITY-HEADER"="$env:IDENTITY_HEADER"} -Uri $tokenAuthUri -UseBasicParsing

$accessToken = $response.access_token

#Invoke REST call to Graph API
$uri = 'https://graph.microsoft.com/v1.0/groups'
$authHeader = @{
'Content-Type'='application/json'
'Authorization'='Bearer ' + $accessToken
}

$result = (Invoke-RestMethod -Uri $uri -Headers $authHeader -Method Get -ResponseHeadersVariable RES).value

If ($result) {
$body = $result
$StatusCode = '200'
}
Else {
$body = $RES
$StatusCode = '400'}

# Associate values to output bindings by calling 'Push-OutputBinding'
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
StatusCode = $StatusCode
Body = $body
})

 

Take a moment to understand what the code does:

Watch out – the Graph API will this way return up to 100 groups – Please adjust with query parameters as needed like https://graph.microsoft.com/v1.0/groups?$top=42 or use paging, which is described here: Paging Microsoft Graph data in your app – Microsoft Graph | Microsoft Docs

 

Resources in Azure

We will now create the Functions App in Azure – You can either install the CLI or use Cloud shell (available on shell.azure.com – no installation is needed then and it works in any browser!)

Variables & names

For testing purposes, I pseudo-randomized a number to not always need to come up with new names:

 

#Get a random number between 100 and 300 to more easily be able to distinguish between several trials
$rand = Get-Random -Minimum 100 -Maximum 300

We will now set some variables, this reduces risk of typos and makes our code better readable – also we can reuse it better – this is a courtesy to future-self

#Set values
$resourceGroup = "DemoPlay$rand"
$location = "westeurope"
$storage = "luisedemostorage$rand"
$functionapp = "LuiseDemo-functionapp$rand"

Resource group

Let’s create a resource-group that will later hold our Azure Functions App

 

#create group
az group create -n $resourceGroup -l $location

Storage Account

As our Functions App will need a storage account, we will create this as well:

#create storage account
az storage account create `
-n $storage `
-l $location `
-g $resourceGroup `
--sku Standard_LRS

 

Functions App

Now create the Azure Functions app which later holds our functions (remember we created that earlier locally, but will later deploy it to Azure)

 

#create function
az functionapp create `
-n $functionapp `
--storage-account $storage `
--consumption-plan-location $location `
--runtime powershell `
-g $resourceGroup `
--functions-version 3

It will take a few moments for everything to be set, once this step is completed, you will be prompted with a message, that you also can benefit from Application Insights.

Managed Identity

We want things to be super secure – this is why we want to enable a system assigned Managed Identity for our new Functions:

az functionapp identity assign -n $functionapp -g $resourceGroup

 Our Managed Identity shall have the right permission scope to access Graph API for Group.Read.All, and to eventually be able to make the required REST call, we will need

  • the Graph API service Provider
  • permission scope, expressed as App role
    Let’s do this:
#Get Graph Api service provider (that's later needed for --api) 
az ad sp list --query "[?appDisplayName=='Microsoft Graph'].{Name:appDisplayName, Id:appId}" --output table --all

#Save that service provider 
$graphId = az ad sp list --query "[?appDisplayName=='Microsoft Graph'].appId | [0]" --all 

# Get permission scope for "Group.Read.All"
$appRoleId = az ad sp show --id $graphId --query "appRoles[?value=='Group.Read.All'].id | [0]" 

Time to make the REST call to assign the permissions as shown above to the Managed Identity:

#Set values
$webAppName="LuiseDemo-functionapp$rand"
$principalId=$(az resource list -n $webAppName --query [*].identity.principalId --out tsv)
$graphResourceId=$(az ad sp list --display-name "Microsoft Graph" --query [0].objectId --out tsv)
$appRoleId=$(az ad sp list --display-name "Microsoft Graph" --query "[0].appRoles[?value=='Group.Read.All' && contains(allowedMemberTypes, 'Application')].id" --out tsv)
$body="{'principalId':'$principalId','resourceId':'$graphResourceId','appRoleId':'$appRoleId'}"

#the actual REST call 
az rest --method post --uri https://graph.microsoft.com/v1.0/servicePrincipals/$principalId/appRoleAssignments --body $body --headers Content-Type=application/json

 

If you like to, you may now have a look at our Managed Identity permissions in the Azure portal – for everyone who loves to be assured in a UI that things have worked:

 

image-10-2048x664.png

  • Open portal.azure.com
  • Select Azure Active Directory
  • Select Enterprise applications
  • Select Managed Identity from the Applications dropdown
  • Note the app level permission Read all groups for Microsoft Graph

Deploy to Azure

 

Let’s now deploy our Function to our Functions App. Go back to Visual Studio Code:

  • Select the Azure extension
  • Select deploy to Functions App – its that little cloud icon
  • Select the Functions App you already created in Azure
  • Confirm the Pop up window by selecting Deploy
  • Check progress results in the output window

Time to test!
Please note, that due to our Managed Identity, we can’t test locally. You can trigger your Functions with Postman or similar or run a test in the Azure portal

 

  • Open portal.azure.com
  • Select Resource groups
  • Select the resource group you worked in
  • Select the Azure Functions App you worked in
  • Select Functions
  • Select Code + Test
  • Select Test/Run
  • Select Run

 

You should see a status code 200 – and a list of all your Microsoft 365 groups. YAY!

 

groups (1).png

Conclusion and FusionDev scenario

As developers, we could build a robust, scalable and secure solution, developed with familiar tools like VS Code, PowerShell or Azure CLI. But what if we want to make this available to makers/citizen developers? What if we want to make sure, that this could be used in Power Apps and Power Automate? One way to achieve this, is creating a Power Platform custom connector. This way, makers can use the connector which calls our Azure Functions in a canvas app and display for example the groups in a gallery or table.

Please note, that there are of course more fancy use cases, I will focus in this blog post on the code – If you have a good story, please reach out.

Sample script is available at Script Samples | PnP Samples

 

 

More Resources to learn


Get started with Microsoft 365 development by signing up for a free Developer tenant
Join the Microsoft 365 PnP Community – join our calls and benefit from guidance, tools, sample
 
Originally published at Putting some more FUN into Azure Functions, Managed Identity & Microsoft Graph – M365 Princess

3 Comments
New Contributor

Great article. Thanks for sharing
Believe it or not but after checking this one I also moved the side menu on the right side (no jumping code, how could I noticed that before :) )

Hey @AdamWoj - thank you for your feedback! Do you have a scenario where you would use my approach? 
Also: side menu on the right FTW! You can also do this with the new `.` feature on GitHub. - On any GitHub repo - press the Dot on your keyboard and get VisualStudio Code IN YOUR BROWSER  :)  

New Contributor

@Luise Freese  currently no, not for production use at least ;) but who knows what will be the future requirements, so I try to keep up to date with any 'tips and tricks' :P.

%3CLINGO-SUB%20id%3D%22lingo-sub-2628949%22%20slang%3D%22en-US%22%3ERe%3A%20Putting%20some%20more%20FUN%20into%20Azure%20Functions%2C%20Managed%20Identity%20%26amp%3B%20Microsoft%20Graph%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2628949%22%20slang%3D%22en-US%22%3E%3CP%3EGreat%20article.%20Thanks%20for%20sharing%3CBR%20%2F%3EBelieve%20it%20or%20not%20but%20after%20checking%20this%20one%20I%20also%20moved%20the%20side%20menu%20on%20the%20right%20side%20(no%20jumping%20code%2C%20how%20could%20I%20noticed%20that%20before%20%3A)%3C%2Fimg%3E%26nbsp%3B)%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2628047%22%20slang%3D%22en-US%22%3EPutting%20some%20more%20FUN%20into%20Azure%20Functions%2C%20Managed%20Identity%20%26amp%3B%20Microsoft%20Graph%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2628047%22%20slang%3D%22en-US%22%3E%3CDIV%20class%3D%22the_title%22%3E%0A%3CH1%20id%3D%22toc-hId-1413225703%22%20id%3D%22toc-hId-1413225703%22%20id%3D%22toc-hId-1413225703%22%20id%3D%22toc-hId-1413225703%22%20id%3D%22toc-hId-1413225703%22%20id%3D%22toc-hId-1413225703%22%3EPutting%20some%20more%20FUN%20into%20Azure%20Functions%2C%20Managed%20Identity%20%26amp%3B%20Microsoft%20Graph%3C%2FH1%3E%0A%3C%2FDIV%3E%0A%3CDIV%20class%3D%22cm-post-meta%22%3E%26nbsp%3B%3C%2FDIV%3E%0A%3CDIV%20class%3D%22the_content%22%3E%0A%3CH2%20id%3D%22toc-hId-2103787177%22%20id%3D%22toc-hId-2103787177%22%20id%3D%22toc-hId-2103787177%22%20id%3D%22toc-hId-2103787177%22%20id%3D%22toc-hId-2103787177%22%20id%3D%22toc-hId-2103787177%22%3EUsecase%20%26amp%3B%20purpose%20of%20this%20blog%20post%3C%2FH2%3E%0A%3CP%3EI%20want%20to%20show%2C%20how%20you%20can%20use%20a%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Factive-directory%2Fmanaged-identities-azure-resources%2Foverview%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3EManaged%20Identity%3C%2FA%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Ein%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fazure-functions%2Ffunctions-overview%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3EAzure%20Functions%3C%2FA%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eto%20get%20an%20access%20token%20for%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fgraph%2Foverview%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3EMicrosoft%20Graph%20API%3C%2FA%3E.%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId-296332714%22%20id%3D%22toc-hId-296332714%22%20id%3D%22toc-hId-296332714%22%20id%3D%22toc-hId-296332714%22%20id%3D%22toc-hId-296332714%22%20id%3D%22toc-hId-296332714%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22solution-overview.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F301795i54772C85D9395BDA%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22solution-overview.png%22%20alt%3D%22solution-overview.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FH2%3E%0A%3CH2%20id%3D%22toc-hId--1511121749%22%20id%3D%22toc-hId--1511121749%22%20id%3D%22toc-hId--1511121749%22%20id%3D%22toc-hId--1511121749%22%20id%3D%22toc-hId--1511121749%22%20id%3D%22toc-hId--1511121749%22%3EPrerequisites%20to%20benefit%20from%20this%20article%3A%3C%2FH2%3E%0A%3CP%3ETo%20get%20the%20most%20out%20of%20this%20post%2C%20you%20should%20understand%20the%20following%20concepts%20%E2%80%93%20I%20included%20some%20links%20that%20should%20help%20you%20getting%20started.%3C%2FP%3E%0A%3CH3%20id%3D%22toc-hId--820560275%22%20id%3D%22toc-hId--820560275%22%20id%3D%22toc-hId--820560275%22%20id%3D%22toc-hId--820560275%22%20id%3D%22toc-hId--820560275%22%20id%3D%22toc-hId--820560275%22%3EManaged%20Identity%20%E2%80%93%20What%20is%20that%20and%20why%20would%20I%20want%20one%3F%3C%2FH3%3E%0A%3CP%3EManaged%20Identities%20are%20the%20state-of-the-art%20way%20to%20get%20Azure%20Active%20Directory%20access%20tokens%2C%20because%20you%20won%E2%80%99t%20need%20to%20handle%20credentials%2C%20which%20is%20of%20course%20a%20security%20benefit%3C%2FP%3E%0A%3CBLOCKQUOTE%20class%3D%22wp-block-quote%22%3E%0A%3CP%3E%E2%80%A6where%20are%20credentials%2C%20there%20are%20leaks%20%C2%AF%5C_(%E3%83%84)_%2F%C2%AF%3C%2FP%3E%0A%3C%2FBLOCKQUOTE%3E%0A%3CP%3EIf%20you%20are%20unfamiliar%20with%20tokens%2C%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fmicrosoft-365-pnp-blog%2Fintroduction-to-tokens%2Fba-p%2F2267853%22%20target%3D%22_blank%22%3Ethis%20article%3C%2FA%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eby%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Ftwitter.com%2Flee_ford%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3ELee%20Ford%3C%2FA%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Ewill%20help.%20This%20is%20not%20a%20full%20tutorial%20on%20Managed%20Identities%2C%20for%20more%20information%20please%20start%20to%20read%20here.%20Also%2C%3CA%20href%3D%22https%3A%2F%2Ftwitter.com%2FYannickReekmans%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3EYannick%20Reekmans%3C%2FA%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eposted%20an%20entire%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fblog.yannickreekmans.be%2Fsecretless-applications-managed-identities%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3Eseries%20on%20Managed%20Identities%3C%2FA%3E%2C%20highly%20recommended%20to%20read%20this%20%E2%80%93%20helped%20me%20a%20lot%20to%20understand.%3C%2FP%3E%0A%3CH3%20id%3D%22toc-hId-1666952558%22%20id%3D%22toc-hId-1666952558%22%20id%3D%22toc-hId-1666952558%22%20id%3D%22toc-hId-1666952558%22%20id%3D%22toc-hId-1666952558%22%20id%3D%22toc-hId-1666952558%22%3EAzure%20Functions%3C%2FH3%3E%0A%3CP%3EIf%20you%E2%80%99d%20like%20to%20deploy%20and%20execute%20code%20without%20needing%20to%20THINK%20about%20server%20infrastructure%20or%20VMs%2C%20you%20may%20like%20Azure%20Functions.%20Azure%20Functions%20can%20be%20written%20in%20a%20lot%20of%20languages%20and%20you%20can%20deploy%20and%20execute%20Azure%20Functions%20on%20any%20platform%20that%20can%20run%20.NET%20Core.%20Azure%20functions%20are%20scalable%2C%20as%20they%20use%20compute-on-demand%3A%20More%20resources%20are%20allocated%20automagically%2C%20when%20the%20demand%20of%20execution%20increases.%20If%20the%20demand%20decreases%20again%2C%26nbsp%3Byou%20don%E2%80%99t%20need%20to%20worry%20about%20the%20extra%20resources%20anymore%20as%20they%20drop%20off%20again.%20This%20way%2C%20you%20only%20pay%20what%20you%20need.%20For%20more%20info%20please%20start%20to%20read%20here%3A%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fazure-functions%2Ffunctions-overview%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3EAzure%20Functions%20Overview%20%7C%20Microsoft%20Docs%3C%2FA%3E%3C%2FP%3E%0A%3CP%3EI%20will%20use%20PowerShell%20for%20my%20Azure%20Functions%2C%20so%20that%20IT-Pros%20can%20benefit%20from%20this%20post%20as%20well.%20But%20please%20do%20choose%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CS%3Eyour%20poison%3C%2FS%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eyour%20favorite%20language%2C%20the%20concept%20stays%20the%20same.%20Use%20whatever%20you%20are%20familiar%20with%20or%20what%20makes%20you%20happy.%3C%2FP%3E%0A%3CH3%20id%3D%22toc-hId--140501905%22%20id%3D%22toc-hId--140501905%22%20id%3D%22toc-hId--140501905%22%20id%3D%22toc-hId--140501905%22%20id%3D%22toc-hId--140501905%22%20id%3D%22toc-hId--140501905%22%3EMicrosoft%20Graph%3C%2FH3%3E%0A%3CP%3EMicrosoft%20Graph%20is%20THE%20API%20to%20access%20Microsoft%20365%20resources%2C%20in%20our%20case%20we%20will%20want%20to%20read%20all%20Microsoft%20365%20groups%20%E2%80%93%20for%20more%20information%20see%20also%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fgraph%2Fpermissions-reference%23group-permissions%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3EMicrosoft%20Graph%20permissions%20reference%20%E2%80%93%20Microsoft%20Graph%20%7C%20Microsoft%20Docs.%26nbsp%3B%3C%2FA%3E%3C%2FP%3E%0A%3CP%3EOur%20challenge%20will%20be%20to%20access%20the%20Graph%20API%20with%20a%20Managed%20Identity.%20I%20will%20show%20how%20to%20do%20this%20entirely%20in%20Azure%20CLI%20%26amp%3B%20VS%20Code.%20Creating%20and%20assigning%20Managed%20Identities%20has%20been%20shown%20often%20before%20in%20the%20Azure%20portal%2C%20but%20a%20script%20would%20allow%20for%20automation%2C%20it%20is%20usually%20faster%20than%20working%20in%20a%20visual%20environment%20and%20you%20can%20use%20the%20tool%20of%20your%20choice.%20I%20highly%20recommend%20VS%20Code%20as%20editor%20(and%20I%20like%20the%20built-in%20terminal%20as%20well).%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId--151005009%22%20id%3D%22toc-hId--151005009%22%20id%3D%22toc-hId--151005009%22%20id%3D%22toc-hId--151005009%22%20id%3D%22toc-hId--151005009%22%20id%3D%22toc-hId--151005009%22%3ECreate%20your%20Azure%20Functions%20locally%3C%2FH2%3E%0A%3CP%3EYou%20still%20may%20create%20your%20first%20Azure%20Functions%20in%20the%20Azure%20Portal%20(I%20did%20as%20well)%2C%20which%20demoes%20really%20nicely%2C%20but%20as%20we%20want%20to%20go%20for%20real%20world%2C%20I%20will%20show%20how%20to%20develop%20your%20Azure%20Functions%20in%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fcode.visualstudio.com%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3EVisual%20Studio%20code%3C%2FA%3E.%20This%20has%20some%20great%20advantages%3A%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3Eyou%20develop%20locally%20using%20the%20tools%20that%20you%20are%20already%20familiar%20with%3C%2FLI%3E%0A%3CLI%3Eyou%20don%E2%80%99t%20need%20to%20adjust%20to%20ever%20changing%20UI%20in%20Azure%20portal%3C%2FLI%3E%0A%3CLI%3Eyou%20can%20benefit%20from%20source%20control%3C%2FLI%3E%0A%3CLI%3Eyou%20can%20collaborate%20with%20others%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3EI%20covered%20how%20to%20do%20this%20also%20in%20a%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fm365princess.com%2Fputting-the-fun-into-azure-functions-the-friendly-sms-reminder%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3Eprevious%20post%3C%2FA%3E%2C%20but%20for%20the%20sake%20of%20a%20start-to-end%20scenario%2C%20here%20we%20go%20again%3A%3C%2FP%3E%0A%3COL%3E%0A%3CLI%3EInstall%20the%20Core%20Tools%20package%20with%26nbsp%3B%3CCODE%3Enpm%20install%20-g%20azure-functions-core-tools%403%20--unsafe-perm%20true%3C%2FCODE%3E%3C%2FLI%3E%0A%3CLI%3EInstall%20the%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fmarketplace.visualstudio.com%2Fitems%3FitemName%3Dms-azuretools.vscode-azurefunctions%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3EAzure%20Functions%20extension%20for%20VS%20Code%3C%2FA%3E%3C%2FLI%3E%0A%3CLI%3ESelect%26nbsp%3B%3CSTRONG%3ENew%20Project%3C%2FSTRONG%3E%3C%2FLI%3E%0A%3CLI%3ESelect%20a%20folder%20for%20your%20project%3C%2FLI%3E%0A%3CLI%3ESelect%20a%20language%20%E2%80%93%20I%20will%20use%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EPowerShell%3C%2FSTRONG%3E%3C%2FLI%3E%0A%3CLI%3E%26nbsp%3BSelect%26nbsp%3B%3CSTRONG%3EHTTP%20trigger%3C%2FSTRONG%3E%26nbsp%3Bas%20a%20template%3C%2FLI%3E%0A%3CLI%3EType%20in%20a%20better%20name%20like%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EGetGraphToken%3C%2FCODE%3E%3C%2FLI%3E%0A%3CLI%3ESelect%20Authorization%20level%26nbsp%3B%3CSTRONG%3EFunction%3C%2FSTRONG%3E%3C%2FLI%3E%0A%3CLI%3ESelect%20how%20you%20want%20to%20open%20your%20project%20%E2%80%93%20I%20prefer%26nbsp%3B%3CSTRONG%3EAdd%20to%20workspace%3C%2FSTRONG%3E%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%3EYou%20will%20now%20see%20your%26nbsp%3B%3CSTRONG%3ELocal%20Project%3C%2FSTRONG%3E%26nbsp%3Bin%20the%20pane.%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22VSCodeAF.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F301796iA194A658D6157D1B%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22VSCodeAF.png%22%20alt%3D%22VSCodeAF.png%22%20%2F%3E%3C%2FSPAN%3E%3CBR%20%2F%3E(yes%2C%20my%20pane%20is%20on%20the%20right%20hand%20side%20so%20that%20my%20code%20doesn%E2%80%99t%20%E2%80%9Cjump%E2%80%9D%20all%20the%20time%20when%20I%20am%20expanding%20or%20collapsing%20the%20pane)%3C%2FP%3E%0A%3CDIV%20class%3D%22wp-block-group%22%3E%0A%3CDIV%20class%3D%22wp-block-group__inner-container%22%3E%0A%3CDIV%20class%3D%22wp-block-group%22%3E%0A%3CDIV%20class%3D%22wp-block-group__inner-container%22%3E%0A%3CP%3EWe%20will%20now%20write%20the%20code%20for%20our%20Azure%20Functions.%20Replace%20the%20default%20code%20of%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3Erun.ps1%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Ein%20VS%20Code%20by%20this%3A%3C%2FP%3E%0A%3CPRE%20class%3D%22wp-block-code%22%3E%3CCODE%3Eusing%20namespace%20System.Net%0A%0A%23%20Input%20bindings%20are%20passed%20in%20via%20param%20block%0Aparam(%24Request%2C%20%24TriggerMetadata)%0A%0A%23%20Write%20to%20the%20Azure%20Functions%20log%20stream.%0AWrite-Host%20%22PowerShell%20HTTP%20trigger%20function%20processed%20a%20request.%22%0A%0A%23%20Interact%20with%20query%20parameters%20or%20the%20body%20of%20the%20request%0A.%24Scope%20%3D%20%24Request.Query.Scope%0Aif%20(-not%20%24Scope)%20%7B%0A%20%20%20%20%24Scope%20%3D%20%24Request.Body.Scope%0A%7D%0A%23If%20parameter%20%22Scope%22%20has%20not%20been%20provided%2C%20we%20assume%20that%20graph.microsoft.com%20is%20the%20target%20resource%0AIf%20(!%24Scope)%20%7B%0A%20%20%20%20%24Scope%20%3D%20%22https%3A%2F%2Fgraph.microsoft.com%2F%22%0A%7D%0A%0A%24tokenAuthUri%20%3D%20%24env%3AIDENTITY_ENDPOINT%20%2B%20%22%3Fresource%3D%24Scope%26amp%3Bapi-version%3D2019-08-01%22%0A%24response%20%3D%20Invoke-RestMethod%20-Method%20Get%20-Headers%20%40%7B%22X-IDENTITY-HEADER%22%3D%22%24env%3AIDENTITY_HEADER%22%7D%20-Uri%20%24tokenAuthUri%20-UseBasicParsing%0A%0A%24accessToken%20%3D%20%24response.access_token%0A%0A%23Invoke%20REST%20call%20to%20Graph%20API%0A%24uri%20%3D%20'https%3A%2F%2Fgraph.microsoft.com%2Fv1.0%2Fgroups'%0A%24authHeader%20%3D%20%40%7B%20%20%20%20%0A'Content-Type'%3D'application%2Fjson'%0A'Authorization'%3D'Bearer%20'%20%2B%20%20%24accessToken%0A%7D%0A%0A%24result%20%3D%20(Invoke-RestMethod%20-Uri%20%24uri%20-Headers%20%24authHeader%20-Method%20Get%20-ResponseHeadersVariable%20RES).value%0A%0AIf%20(%24result)%20%7B%0A%20%20%20%20%24body%20%3D%20%24result%0A%20%20%20%20%24StatusCode%20%3D%20'200'%0A%7D%0AElse%20%7B%0A%20%20%20%20%24body%20%3D%20%24RES%0A%20%20%20%20%24StatusCode%20%3D%20'400'%7D%0A%0A%23%20Associate%20values%20to%20output%20bindings%20by%20calling%20'Push-OutputBinding'%0APush-OutputBinding%20-Name%20Response%20-Value%20(%5BHttpResponseContext%5D%40%7B%0A%20%20%20%20StatusCode%20%3D%20%24StatusCode%0A%20%20%20%20Body%20%3D%20%24body%0A%7D)%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3ETake%20a%20moment%20to%20understand%20what%20the%20code%20does%3A%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3Elog%20that%20a%20request%20was%20received%3C%2FLI%3E%0A%3CLI%3Edefine%20the%20scope%20(if%20not%20stated%2C%20it%E2%80%99s%20Microsoft%20Graph)%3C%2FLI%3E%0A%3CLI%3Eobtain%20the%20token%20from%20the%20environment%20variables%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EIDENTITY_ENDPOINT%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eand%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EIDENTITY_HEADER%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Ewhich%20come%20from%20the%20Managed%20Identity%20(thanks%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Ftwitter.com%2FYannickReekmans%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3EYannick%20Reekmans%3C%2FA%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Efor%20this%20hint)%20%E2%80%93%20learn%20more%20here%3A%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fapp-service%2Foverview-managed-identity%3Ftabs%3Dpowershell%26amp%3BWT.mc_id%3DM365-MVP-5003400%23obtain-tokens-for-azure-resources%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3EManaged%20identities%20%E2%80%93%20Azure%20App%20Service%20%7C%20Microsoft%20Docs%3C%2FA%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%E2%80%93%20you%20can%20also%20see%20your%20environment%20variables%20here%2C%20the%20mentioned%20ones%20will%20show%20after%20you%20assigned%20the%20system%20assigned%20Managed%20Identity%3A%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3Ehttps%3A%2F%2F%3CYOUR-FUNCTIONAPPNAME-HERE%3E.scm.azurewebsites.net%2FENV.cshtml%23envVariables)%3C%2FYOUR-FUNCTIONAPPNAME-HERE%3E%3C%2FCODE%3E%3C%2FLI%3E%0A%3CLI%3Epass%20that%20token%20in%20the%20header%20of%20the%20REST%20call%20towards%20the%20group%20endpoint%20of%20Microsoft%20Graph%3C%2FLI%3E%0A%3CLI%3Eget%20the%20status%20code%20(hopefully%20200)%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3EWatch%20out%20%E2%80%93%20the%20Graph%20API%20will%20this%20way%20return%20up%20to%20100%20groups%20%E2%80%93%20Please%20adjust%20with%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fgraph%2Fquery-parameters%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Equery%20parameters%3C%2FA%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eas%20needed%20like%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3E%3CA%20href%3D%22https%3A%2F%2Fgraph.microsoft.com%2Fv1.0%2Fgroups%3F%24top%3D42%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehttps%3A%2F%2Fgraph.microsoft.com%2Fv1.0%2Fgroups%3F%24top%3D42%3C%2FA%3E%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eor%20use%20paging%2C%20which%20is%20described%20here%3A%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fgraph%2Fpaging%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3EPaging%20Microsoft%20Graph%20data%20in%20your%20app%20%E2%80%93%20Microsoft%20Graph%20%7C%20Microsoft%20Docs%3C%2FA%3E%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId--1958459472%22%20id%3D%22toc-hId--1958459472%22%20id%3D%22toc-hId--1958459472%22%20id%3D%22toc-hId--1958459472%22%20id%3D%22toc-hId--1958459472%22%20id%3D%22toc-hId--1958459472%22%3EResources%20in%20Azure%3C%2FH2%3E%0A%3C%2FDIV%3E%0A%3C%2FDIV%3E%0A%3CP%3EWe%20will%20now%20create%20the%20Functions%20App%20in%20Azure%20%E2%80%93%20You%20can%20either%20install%20the%20CLI%20or%20use%20Cloud%20shell%20(available%20on%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fshell.azure.com%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3Eshell.azure.com%3C%2FA%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%E2%80%93%20no%20installation%20is%20needed%20then%20and%20it%20works%20in%20any%20browser!)%3C%2FP%3E%0A%3CH3%20id%3D%22toc-hId--1267897998%22%20id%3D%22toc-hId--1267897998%22%20id%3D%22toc-hId--1267897998%22%20id%3D%22toc-hId--1267897998%22%20id%3D%22toc-hId--1267897998%22%20id%3D%22toc-hId--1267897998%22%3EVariables%20%26amp%3B%20names%3C%2FH3%3E%0A%3CP%3EFor%20testing%20purposes%2C%20I%20pseudo-randomized%20a%20number%20to%20not%20always%20need%20to%20come%20up%20with%20new%20names%3A%3C%2FP%3E%0A%3CPRE%20class%3D%22wp-block-code%22%3E%3CCODE%3E%23Get%20a%20random%20number%20between%20100%20and%20300%20to%20more%20easily%20be%20able%20to%20distinguish%20between%20several%20trials%0A%24rand%20%3D%20Get-Random%20-Minimum%20100%20-Maximum%20300%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3EWe%20will%20now%20set%20some%20variables%2C%26nbsp%3Bthis%20reduces%20risk%20of%20typos%20and%20makes%20our%20code%20better%20readable%20%E2%80%93%20also%20we%20can%20reuse%20it%20better%20%E2%80%93%20this%20is%20a%20courtesy%20to%20future-self%3C%2FP%3E%0A%3CPRE%20class%3D%22wp-block-code%22%3E%3CCODE%3E%23Set%20values%0A%24resourceGroup%20%3D%20%22DemoPlay%24rand%22%0A%24location%20%3D%20%22westeurope%22%0A%24storage%20%3D%20%22luisedemostorage%24rand%22%0A%24functionapp%20%3D%20%22LuiseDemo-functionapp%24rand%22%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CH3%20id%3D%22toc-hId-524451356%22%20id%3D%22toc-hId-524451356%22%20id%3D%22toc-hId-524451356%22%20id%3D%22toc-hId-524451356%22%20id%3D%22toc-hId-524451356%22%20id%3D%22toc-hId-524451356%22%3EResource%20group%3C%2FH3%3E%0A%3CP%3ELet%E2%80%99s%20create%20a%20resource-group%20that%20will%20later%20hold%20our%20Azure%20Functions%20App%3C%2FP%3E%0A%3CPRE%20class%3D%22wp-block-code%22%3E%3CCODE%3E%23create%20group%0Aaz%20group%20create%20-n%20%24resourceGroup%20-l%20%24location%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CH3%20id%3D%22toc-hId--1283003107%22%20id%3D%22toc-hId--1283003107%22%20id%3D%22toc-hId--1283003107%22%20id%3D%22toc-hId--1283003107%22%20id%3D%22toc-hId--1283003107%22%20id%3D%22toc-hId--1283003107%22%3EStorage%20Account%3C%2FH3%3E%0A%3CP%3EAs%20our%20Functions%20App%20will%20need%20a%20storage%20account%2C%20we%20will%20create%20this%20as%20well%3A%3C%2FP%3E%0A%3CPRE%20class%3D%22wp-block-code%22%3E%3CCODE%3E%23create%20storage%20account%0Aaz%20storage%20account%20create%20%60%0A%20%20-n%20%24storage%20%60%0A%20%20-l%20%24location%20%60%0A%20%20-g%20%24resourceGroup%20%60%0A%20%20--sku%20Standard_LRS%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CH3%20id%3D%22toc-hId-1204509726%22%20id%3D%22toc-hId-1204509726%22%20id%3D%22toc-hId-1204509726%22%20id%3D%22toc-hId-1204509726%22%20id%3D%22toc-hId-1204509726%22%20id%3D%22toc-hId-1204509726%22%3EFunctions%20App%3C%2FH3%3E%0A%3CP%3ENow%20create%20the%20Azure%20Functions%20app%20which%20later%20holds%20our%20functions%20(remember%20we%20created%20that%20earlier%20locally%2C%20but%20will%20later%20deploy%20it%20to%20Azure)%3C%2FP%3E%0A%3CPRE%20class%3D%22wp-block-code%22%3E%3CCODE%3E%23create%20function%0Aaz%20functionapp%20create%20%60%0A%20%20-n%20%24functionapp%20%60%0A%20%20--storage-account%20%24storage%20%60%0A%20%20--consumption-plan-location%20%24location%20%60%0A%20%20--runtime%20powershell%20%60%0A%20%20-g%20%24resourceGroup%20%60%0A%20%20--functions-version%203%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3EIt%20will%20take%20a%20few%20moments%20for%20everything%20to%20be%20set%2C%20once%20this%20step%20is%20completed%2C%20you%20will%20be%20prompted%20with%20a%20message%2C%20that%20you%20also%20can%20benefit%20from%20Application%20Insights.%3C%2FP%3E%0A%3CH3%20id%3D%22toc-hId--602944737%22%20id%3D%22toc-hId--602944737%22%20id%3D%22toc-hId--602944737%22%20id%3D%22toc-hId--602944737%22%20id%3D%22toc-hId--602944737%22%20id%3D%22toc-hId--602944737%22%3EManaged%20Identity%3C%2FH3%3E%0A%3CP%3EWe%20want%20things%20to%20be%20super%20secure%20%E2%80%93%20this%20is%20why%20we%20want%20to%20enable%20a%20system%20assigned%20Managed%20Identity%20for%20our%20new%20Functions%3A%3C%2FP%3E%0A%3CPRE%20class%3D%22wp-block-code%22%3E%3CCODE%3Eaz%20functionapp%20identity%20assign%20-n%20%24functionapp%20-g%20%24resourceGroup%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3EOur%20Managed%20Identity%20shall%20have%20the%20right%20permission%20scope%20to%20access%20Graph%20API%20for%20Group.Read.All%2C%20and%20to%20eventually%20be%20able%20to%20make%20the%20required%20REST%20call%2C%20we%20will%20need%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3Ethe%20Graph%20API%20service%20Provider%3C%2FLI%3E%0A%3CLI%3Epermission%20scope%2C%20expressed%20as%20App%20role%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3ELet%E2%80%99s%20do%20this%3A%3C%2FP%3E%0A%3CPRE%20class%3D%22wp-block-code%22%3E%3CCODE%3E%23Get%20Graph%20Api%20service%20provider%20(that's%20later%20needed%20for%20--api)%20%0Aaz%20ad%20sp%20list%20--query%20%22%5B%3FappDisplayName%3D%3D'Microsoft%20Graph'%5D.%7BName%3AappDisplayName%2C%20Id%3AappId%7D%22%20--output%20table%20--all%0A%0A%23Save%20that%20service%20provider%20%0A%24graphId%20%3D%20az%20ad%20sp%20list%20--query%20%22%5B%3FappDisplayName%3D%3D'Microsoft%20Graph'%5D.appId%20%7C%20%5B0%5D%22%20--all%20%0A%0A%23%20Get%20permission%20scope%20for%20%22Group.Read.All%22%0A%24appRoleId%20%3D%20az%20ad%20sp%20show%20--id%20%24graphId%20--query%20%22appRoles%5B%3Fvalue%3D%3D'Group.Read.All'%5D.id%20%7C%20%5B0%5D%22%20%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3ETime%20to%20make%20the%20REST%20call%20to%20assign%20the%20permissions%20as%20shown%20above%20to%20the%20Managed%20Identity%3A%3C%2FP%3E%0A%3CPRE%20class%3D%22wp-block-code%22%3E%3CCODE%3E%23Set%20values%0A%24webAppName%3D%22LuiseDemo-functionapp%24rand%22%0A%24principalId%3D%24(az%20resource%20list%20-n%20%24webAppName%20--query%20%5B*%5D.identity.principalId%20--out%20tsv)%0A%24graphResourceId%3D%24(az%20ad%20sp%20list%20--display-name%20%22Microsoft%20Graph%22%20--query%20%5B0%5D.objectId%20--out%20tsv)%0A%24appRoleId%3D%24(az%20ad%20sp%20list%20--display-name%20%22Microsoft%20Graph%22%20--query%20%22%5B0%5D.appRoles%5B%3Fvalue%3D%3D'Group.Read.All'%20%26amp%3B%26amp%3B%20contains(allowedMemberTypes%2C%20'Application')%5D.id%22%20--out%20tsv)%0A%24body%3D%22%7B'principalId'%3A'%24principalId'%2C'resourceId'%3A'%24graphResourceId'%2C'appRoleId'%3A'%24appRoleId'%7D%22%0A%0A%23the%20actual%20REST%20call%20%0Aaz%20rest%20--method%20post%20--uri%20https%3A%2F%2Fgraph.microsoft.com%2Fv1.0%2FservicePrincipals%2F%24principalId%2FappRoleAssignments%20--body%20%24body%20--headers%20Content-Type%3Dapplication%2Fjson%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3EIf%20you%20like%20to%2C%20you%20may%20now%20have%20a%20look%20at%20our%20Managed%20Identity%20permissions%20in%20the%20Azure%20portal%20%E2%80%93%20for%20everyone%20who%20loves%20to%20be%20assured%20in%20a%20UI%20that%20things%20have%20worked%3A%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3EOpen%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fportal.azure.com%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3Eportal.azure.com%3C%2FA%3E%3C%2FLI%3E%0A%3CLI%3ESelect%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EAzure%20Active%20Directory%3C%2FSTRONG%3E%3C%2FLI%3E%0A%3CLI%3ESelect%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EEnterprise%20applications%3C%2FSTRONG%3E%3C%2FLI%3E%0A%3CLI%3ESelect%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EManaged%20Identity%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Efrom%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EApplications%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Edropdown%3C%2FLI%3E%0A%3CLI%3ENote%20the%20app%20level%20permission%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3ERead%20all%20groups%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Efor%20Microsoft%20Graph%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CH2%20id%3D%22toc-hId-1755485377%22%20id%3D%22toc-hId-1755485377%22%20id%3D%22toc-hId-1755485377%22%20id%3D%22toc-hId-1755485377%22%20id%3D%22toc-hId-1755485377%22%20id%3D%22toc-hId-1755485377%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22permissions.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F301797i74F3548CB97DBF1D%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22permissions.png%22%20alt%3D%22permissions.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FH2%3E%0A%3CH2%20id%3D%22toc-hId--51969086%22%20id%3D%22toc-hId--51969086%22%20id%3D%22toc-hId--51969086%22%20id%3D%22toc-hId--51969086%22%20id%3D%22toc-hId--51969086%22%20id%3D%22toc-hId--51969086%22%3EDeploy%20to%20Azure%3C%2FH2%3E%0A%3CDIV%20class%3D%22wp-block-group%22%3E%0A%3CDIV%20class%3D%22wp-block-group__inner-container%22%3E%0A%3CDIV%20class%3D%22wp-block-group%22%3E%0A%3CDIV%20class%3D%22wp-block-group__inner-container%22%3E%0A%3CP%3ELet%E2%80%99s%20now%20deploy%20our%20Function%20to%20our%20Functions%20App.%20Go%20back%20to%20Visual%20Studio%20Code%3A%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3ESelect%20the%20Azur%20eextension%3C%2FLI%3E%0A%3CLI%3ESelect%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3Edeploy%20to%20Functions%20App%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%E2%80%93%20its%20that%20little%20cloud%20icon%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22deploy.png%22%20style%3D%22width%3A%20805px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F301798i563C0F02DD7224A0%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22deploy.png%22%20alt%3D%22deploy.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3ESelect%20the%20Functions%20App%20you%20already%20created%20in%20Azure%3C%2FLI%3E%0A%3CLI%3EConfirm%20the%20Pop%20up%20window%20by%20selecting%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EDeploy%3C%2FSTRONG%3E%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22confirm.png%22%20style%3D%22width%3A%20830px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F301799iA279926185762F9E%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22confirm.png%22%20alt%3D%22confirm.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3ECheck%20progress%20results%20in%20the%20output%20window%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22deploying.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F301800iE477140982A2F186%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22deploying.png%22%20alt%3D%22deploying.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22out.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F301801i1E70FCBF164722F7%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22out.png%22%20alt%3D%22out.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3C%2FDIV%3E%0A%3C%2FDIV%3E%0A%3C%2FDIV%3E%0A%3C%2FDIV%3E%0A%3C%2FDIV%3E%0A%3C%2FDIV%3E%0A%3CH2%20id%3D%22toc-hId--1859423549%22%20id%3D%22toc-hId--1859423549%22%20id%3D%22toc-hId--1859423549%22%20id%3D%22toc-hId--1859423549%22%20id%3D%22toc-hId--1859423549%22%20id%3D%22toc-hId--1859423549%22%3ETime%20to%20test!%3C%2FH2%3E%0A%3CP%3EPlease%20note%2C%20that%20due%20to%20our%20Managed%20Identity%2C%20we%20can%E2%80%99t%20test%20locally.%20You%20can%20trigger%20your%20Functions%20with%20Postman%20or%20similar%20or%20run%20a%20test%20in%20the%20Azure%20portal%3A%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3EOpen%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22http%3A%2F%2Fportal.azure.com%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3Eportal.azure.com%3C%2FA%3E%3C%2FLI%3E%0A%3CLI%3ESelect%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EResource%20groups%3C%2FSTRONG%3E%3C%2FLI%3E%0A%3CLI%3ESelect%20the%20resource%20group%20you%20worked%20in%3C%2FLI%3E%0A%3CLI%3ESelect%20the%20Azure%20Functions%20App%20you%20worked%20in%3C%2FLI%3E%0A%3CLI%3ESelect%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EFunctions%3C%2FSTRONG%3E%3C%2FLI%3E%0A%3CLI%3ESelect%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3ECode%20%2B%20Test%3C%2FSTRONG%3E%3C%2FLI%3E%0A%3CLI%3ESelect%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3ETest%2FRun%3C%2FSTRONG%3E%3C%2FLI%3E%0A%3CLI%3ESelect%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3ERun%3C%2FSTRONG%3E%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3EYou%20should%20see%20a%20status%20code%20200%20%E2%80%93%20and%20a%20list%20of%20all%20your%20Microsoft%20365%20groups.%20YAY!%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId-628089284%22%20id%3D%22toc-hId-628089284%22%20id%3D%22toc-hId-628089284%22%20id%3D%22toc-hId-628089284%22%20id%3D%22toc-hId-628089284%22%20id%3D%22toc-hId-628089284%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22response.png%22%20style%3D%22width%3A%20906px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F301803i252AC7296CC8326D%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22response.png%22%20alt%3D%22response.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FH2%3E%0A%3CH2%20id%3D%22toc-hId--1179365179%22%20id%3D%22toc-hId--1179365179%22%20id%3D%22toc-hId--1179365179%22%20id%3D%22toc-hId--1179365179%22%20id%3D%22toc-hId--1179365179%22%20id%3D%22toc-hId--1179365179%22%3EConclusion%20and%20FusionDev%20scenario%3C%2FH2%3E%0A%3CP%3EAs%20developers%2C%20we%20could%20build%20a%20robust%2C%20scalable%20and%20secure%20solution%2C%20developed%20with%20familiar%20tools%20like%20VS%20Code%2C%20PowerShell%20or%20Azure%20CLI.%20But%20what%20if%20we%20want%20to%20make%20this%20available%20to%20makers%2Fcitizen%20developers%3F%20What%20if%20we%20want%20to%20make%20sure%2C%20that%20this%20could%20be%20used%20in%20Power%20Apps%20and%20Power%20Automate%3F%20One%20way%20to%20achieve%20this%2C%20is%20creating%20a%20Power%20Platform%20custom%20connector.%20This%20way%2C%20makers%20can%20use%20the%20connector%20which%20calls%20our%20Azure%20Functions%20in%20a%20canvas%20app%20and%20display%20for%20example%20the%20groups%20in%20a%20gallery%20or%20table.%3CBR%20%2F%3E%3CBR%20%2F%3EPlease%20note%2C%20that%20there%20are%20of%20course%20more%20fancy%20use%20cases%2C%20I%20will%20focus%20in%20this%20blog%20post%20on%20the%20code%20%E2%80%93%20If%20you%20have%20a%20good%20story%2C%20please%20reach%20out.%26nbsp%3B%3CBR%20%2F%3E%3CBR%20%2F%3ESample%20script%20is%20available%20at%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fpnp.github.io%2Fscript-samples%2Findex.html%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3EScript%20Samples%20%7C%20PnP%20Samples%3C%2FA%3E%3C%2FP%3E%0A%3CDIV%20id%3D%22tinyMceEditorLuiseFreese_9%22%20class%3D%22mceNonEditable%20lia-copypaste-placeholder%22%3E%26nbsp%3B%3C%2FDIV%3E%0A%3CH2%20id%3D%22toc-hId-1308147654%22%20id%3D%22toc-hId-1308147654%22%20id%3D%22toc-hId-1308147654%22%20id%3D%22toc-hId-1308147654%22%20id%3D%22toc-hId-1308147654%22%20id%3D%22toc-hId-1308147654%22%3EMore%20Resources%20to%20learn%3C%2FH2%3E%0A%3CP%3EGet%20started%20with%20Microsoft%20365%20development%20by%20signing%20up%20for%20a%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fdeveloper.microsoft.com%2Fen-us%2Fmicrosoft-365%2Fdev-program%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Efree%20Developer%20tenant%3C%2FA%3E%3C%2FP%3E%0A%3CP%3EJoin%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Faka.ms%2Fm365PnP%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3EMicrosoft%20365%20PnP%20Community%3C%2FA%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%E2%80%93%20join%20our%20calls%20and%20benefit%20from%20guidance%2C%20tools%2C%20sample%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EOriginally%20published%20at%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fm365princess.com%2Fputting-some-fun-into-azure-functions-managed-identity-and-microsoft-graph%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3EPutting%20some%20more%20FUN%20into%20Azure%20Functions%2C%20Managed%20Identity%20%26amp%3B%20Microsoft%20Graph%20%E2%80%93%20M365%20Princess%3C%2FA%3E%3C%2FP%3E%0A%3C%2FDIV%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-2628047%22%20slang%3D%22en-US%22%3E%3CP%3E%26nbsp%3BLearn%20how%20to%20used%20Managed%20Identity%20in%20Azure%20Functions%20to%20call%20Microsoft%20Graph%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22mateusz-waclawek-t2b2svMf8ek-unsplash.jpg%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F301804iB245D51166D5DA22%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22mateusz-waclawek-t2b2svMf8ek-unsplash.jpg%22%20alt%3D%22mateusz-waclawek-t2b2svMf8ek-unsplash.jpg%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2628047%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EHow%20to%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2641168%22%20slang%3D%22en-US%22%3ERe%3A%20Putting%20some%20more%20FUN%20into%20Azure%20Functions%2C%20Managed%20Identity%20%26amp%3B%20Microsoft%20Graph%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2641168%22%20slang%3D%22en-US%22%3E%3CP%3EHey%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F972728%22%20target%3D%22_blank%22%3E%40AdamWoj%3C%2FA%3E%26nbsp%3B-%20thank%20you%20for%20your%20feedback!%20Do%20you%20have%20a%20scenario%20where%20you%20would%20use%20my%20approach%3F%26nbsp%3B%3CBR%20%2F%3EAlso%3A%20side%20menu%20on%20the%20right%20FTW!%20You%20can%20also%20do%20this%20with%20the%20new%20%60.%60%20feature%20on%20GitHub.%20-%20On%20any%20GitHub%20repo%20-%20press%20the%20Dot%20on%20your%20keyboard%20and%20get%20VisualStudio%20Code%20IN%20YOUR%20BROWSER%26nbsp%3B%20%3A)%3C%2Fimg%3E%26nbsp%3B%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2642664%22%20slang%3D%22en-US%22%3ERe%3A%20Putting%20some%20more%20FUN%20into%20Azure%20Functions%2C%20Managed%20Identity%20%26amp%3B%20Microsoft%20Graph%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2642664%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F89985%22%20target%3D%22_blank%22%3E%40Luise%20Freese%3C%2FA%3E%26nbsp%3B%20currently%20no%2C%20not%20for%20production%20use%20at%20least%20%3B)%3C%2Fimg%3E%20but%20who%20knows%20what%20will%20be%20the%20future%20requirements%2C%20so%20I%20try%20to%20keep%20up%20to%20date%20with%20any%20'tips%20and%20tricks'%20%3AP.%3C%2FP%3E%3C%2FLINGO-BODY%3E
Co-Authors
Version history
Last update:
‎Aug 21 2021 12:17 AM
Updated by: