This sample shows how to get new users in the Azure Active Directory and add them in Onboarding team on Microsoft Teams.
- Microsoft 365 Developer Program account
- Microsoft Azure Subscription
- Visual Studio Code
- Azure Functions Extension for Visual Studio Code
- Azure Storage Emulator
-
Create Azure Event Hubs and Key Vault to get Microsoft Graph Change Notifications delivered: Get change notifications delivered in different ways
-
Create
local.settings.json
file in your code and add the following code snippet by updating the Event Hub connection string:{ "IsEncrypted": false, "Values": { "AzureWebJobsStorage": "UseDevelopmentStorage=true", "FUNCTIONS_WORKER_RUNTIME": "node", "OnboardingEventHubs_Listen_EVENTHUB": "EventHub-Connection-String" }, "watchDirectories": [ "Shared" ] }
-
Register an app to Azure Active Directory to handle authentication for the deamon app: Optional: configure app-only authentication
In the App permissions tab, add
User.Read.All
andTeamMember.ReadWrite.All
permissions from Microsoft Graph Application Permissions. Grant admin consent for the permissions.Update
Shared/graph.js
file in the code with the required AAD app settings. -
Run the following commands in your CLI to install the dependencies:
npm install @azure/identity @microsoft/microsoft-graph-client isomorphic-fetch readline-sync
-
Open the terminal in Visual Studio Code and run your functions with the following command:
func host start
Make sure that Microsoft Azure Storage Emulator is running in the background.
-
Go to Azure Portal and select Azure Active Directory from the left pane and go to Users. Select + New user and Create new user. Fill in the details.
-
Once the OnboardingFunction triggered successfully, you should be able to see the newly added user as a member of the Onboarding team on Microsoft Teams.
- SubscriptionFunction: Subscribing to Microsoft Graph
users
change notifications, notifications will be delivered to Azure Event Hubs. - OnboardingFunction: Receiving change notifications from Azure Event Hubs and using the user id to add the user in the Onboarding team.
- Shared/graph.js: Shared code that handles Microsoft Graph API calls for
/subscriptions
and/teams/{team-id}/members
.