note-assets | ||
.gitignore | ||
Meetings.csproj | ||
Program.cs | ||
README.md | ||
Settings.cs | ||
settings.json | ||
TeamsMeetingRequest.cs | ||
Utils.cs |
Creating Teams Meeting With Dotnet
In his sample project I am attempting to create a Teams meeting using the Microsoft Graph API with .NET.
The application should manage most of the process for you. What you need to do is fill out the pre-requisites, copy data to appsettings.json, and run the application. You might be required to create an application access policy in Teams PowerShell. This app will error out if that is needed.
Prerequisites
- dotnet 6.0 or later
- Microsoft Graph API access
- this requires an Azure AD application with the appropriate permissions to create Teams meetings.
- You can register an application in the Azure portal and grant it the
OnlineMeetings.ReadWrite
permission.
Registering an application
- Go to the Entra id applications view.
- Click on "New registration".
- Fill in the application name and redirect URI (if needed).
- Click "Register".
- Once registered, note the Application (client) ID and Directory (tenant) ID.
- Under "Certificates & secrets", create a new client secret and note it down. This will be used for authentication.
- Under "API permissions", add the
OnlineMeetings.ReadWrite
permission. You may need to grant admin consent for this permission.
At this point you should have three separate pieces of information:
- Application (client) ID: This is the unique identifier for your application.
- Directory (tenant) ID: This is the identifier for your Azure AD tenant.
- Client secret: This is the secret key used to authenticate your application.
Filling out the appsettings.json
Sample:
{
"TenantId": "",
"ClientId": "",
"ClientSecret": ""
}
Creating an application access policy
First step is to install some powershell modules. Mainly the MicrosoftTeams
module.
Install-Module -Name MicrosoftTeams -Force -AllowClobber
Then we need to connect to Teams PowerShell:
Connect-MicrosoftTeams
If you get an error like this:
Connect-MicrosoftTeams : The 'Connect-MicrosoftTeams' command was found in the module 'MicrosoftTeams', but the
module could not be loaded. For more information, run 'Import-Module MicrosoftTeams'.
At line:1 char:1
+ Connect-MicrosoftTeams
You need to set execution policy to allow running scripts:
Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass
Then you can run the Connect-MicrosoftTeams
command again.
The command will pop up a login window where you can enter your credentials. Use the admin credentials for the tenant.
Once connected, you can create the application access policy with the following command:
New-CsApplicationAccessPolicy -Identity "TeamsMeetingAccessPolicy" -AppIds "[CLIENT ID FROM APP REGISTRATION]" -Description "Allow this app to create meetings"
This command allows the application with the specified client ID to create Teams meetings.
But in order for the application to create meetings on behalf of a user, the app needs to be given authorization to do so.
Assigning the application access policy to a user
You can assign the application access policy to a user with the following command:
Grant-CsApplicationAccessPolicy -PolicyName "TeamsMeetingAccessPolicy" -Identity [USER PRINCIPAL NAME]
Runnin the app
Once you have filled out the appsettings.json
file and created the application access policy, you can run the application.
You can run the application using the following command:
dotnet run
On a successful run, you should see a message indicating that the Teams meeting was created successfully.
About licensing
When you create a new user via Entra ID, you are not necessarily automatically assigned a lisence. This is something that needs to be done separately. So if you login with your newly created user and teams tells you that you can't do that, check the lisences.