This sample has example calls to many of the Teams Graph APIs, including:
- Get My Teams
- Get Channels
- Get Apps
- Create Channel
- Post Message
- Create Team and Group
- Add Team to Group
- Add Member to team
- Update Team settings
For more information on developing apps for Microsoft Teams, please review the Microsoft Teams developer documentation.**
As the current Microsoft Teams Graph APIs are only accessible by a tenant admin, to run the app, you'll need to sign in with an account with admin privileges. Note that in most companies, you might not have these rights, nor the ability to grant yourself these rights, therefore you might benefit from a developer account through our Office 365 Developer program.
You'll need to register an app through the following process:
-
Sign in to the Azure portal using either a work or school account or a personal Microsoft account.
-
If your account gives you access to more than one tenant, select your account in the top right corner, and set your portal session to the Azure AD tenant that you want.
-
Select New registration.
-
When the Register an application page appears, enter your application's registration information:
- Name - Enter a meaningful application name that will be displayed to users of the app.
- Supported account types - Select which accounts you would like your application to support.
- Redirect URI (optional) - Select Web and enter 'http://localhost:55065/' for the Redirect URI.
-
When finished, select Register.
-
Azure AD assigns a unique application (client) ID to your app, and you're taken to your application's Overview page. To add additional capabilities to your application, you can select other configuration options including branding, certificates and secrets, API permissions, and more.
Copy the Application Id. This is the unique identifier for your app.
-
Under Manage on the left-hand pane, click Certificates & secrets. Under Client secrets, click New client secret. Enter a description and an expiration, then click Add. This creates a secret string, or application password, which the application uses to prove it's identity.
Copy the value from the new secret.
-
Under Manage on the left-hand pane, click Authentication. Under Implicit grant, check Access tokens and ID tokens. During authentication, this enables the app to receive both sign-in info (the id_token) and artifacts (in this case, an authorization code) that the app can use to obtain an access token. Save your changes.
-
Under Manage on the left-hand pane, click API permissions and then Add a new permission. Select Microsoft Graph and then Delegated permissions. Add 'Group.ReadWrite.All' (Read and write all groups) and 'User.ReadWrite.All' (Read and write all users' full profile) permissions. Click Add a new permission again then Application permissions. Add 'Group.ReadWrite.All' (Read and write all groups) and 'User.ReadWrite.All' (Read and write all users' full profile) permissions.
See the individual project readmes for more information.
- Open the sample solution in Visual Studio.
- Get your appid & app secret from the previous section
- Create a file named Web.config.secrets (put it next to Web.config), and add in your appid and app secret:
<?xml version="1.0" encoding="utf-8"?>
<appSettings >
<add key="ida:AppId" value="xxxxx"/>
<add key="ida:AppSecret" value="xxxxx"/>
</appSettings>
- Update the 'Web Server' of your web application with the 'ida:RedirectUri' of your registered app
- In Solution Explorer, right-click the name of the Web application project for which you want to specify a Web server, and then click 'Properties'.
- In the 'Properties' window, click the 'Web' tab.
- Under 'Servers', update the 'Project Url' with the 'ida:RedirectUri' of your registered app.
- Click 'Create Virtual Directory'
- Save the file.
-
Build and run the sample.
-
Sign in with your account, and grant the requested permissions.
- Note you'll need to have appropriate elevated rights to run the app (Group.ReadWrite.All and User.ReadWrite.All)
-
Choose operation, such as 'Get My Teams', 'Get Channels', 'Create Channel' or 'Post Message'.
-
Response information is displayed at the bottom of the page.
We welcome your feedback! Here's how to send us yours.
This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.
Please read Contributing for details on the process for submitting pull requests to us.
This project is licensed under the MIT License - see the License file for details.
Copyright (c) 2018 Microsoft Corporation. All rights reserved.