Building Microsoft Teams Integration and Workflows
Building Microsoft Teams Integration and Workflows
FOR USE ONLY AS PART OF MICROSOFT VIRTUAL TRAINING DAYS PROGRAM. THESE MATERIALS ARE NOT AUTHORIZED
FOR DISTRIBUTION, REPRODUCTION OR OTHER USE BY NON-MICROSOFT PARTIES.
Microsoft 365 Virtual
Training Day:
Building Microsoft Teams
Integration and Workflows
Implement Microsoft identity –
Segment 1 of 2
Getting
started with • Overview of Microsoft identity platform
Microsoft • Token types in Microsoft Identity
Identity • Register an application
Overview of Microsoft identity platform
Why use an identity provider?
Resources Policies
Overview of Microsoft identity
Users:
Azure AD – Employees and Enterprise Resources
Azure AD B2B – Partners
Azure AD B2C – Customers/citizens
Resources:
Microsoft Graph is the gateway to your data in the Microsoft cloud
Policies:
Efficiently handle complex policies that control access to resources from different
networks and devices
External collaboration using B2B
Contoso Fabrikam
Azure Active Directory B2C
Any SAML
Social IDs provider
Microsoft Azure
Analytics
Active Directory
Your app
Gateway Microsoft
1 Graph
ID token
Security token that clients can use to verify identity of user
Claims in ID tokens can be used for the user experience, keys in DB’s & providing access to
client applications
External collaboration using B2B
Contoso Fabrikam
Azure Active Directory B2C
Any SAML
Social IDs provider
Microsoft Azure
Analytics
Active Directory
Your app
Gateway Microsoft
1 Graph
ID token
Security token that clients can use to verify identity of user
Claims in ID tokens can be used for the user experience, keys in DB’s & providing access to
client applications
Difference between user and application access tokens
… on behalf of a user
… directly from an application (for example: daemon or service applications
App-only tokens indicate the request is coming from an application and has no user backing it
Register an application
Register an application
Registration fields:
Application name
Supported account types
Redirect URI (optional)
Application object:
The application properties stored in the
manifest
Defines the required application
permissions
Microsoft identity platform supports both implicit flow and authorization code
flow, but authorization code flow is recommended.
Implicit flow uses iframes and cookies for silent single sign-on. Many modern browsers block third-
party cookies
The easiest way to use Microsoft identity for authentication and to obtain access tokens to
authorize requests to secured endpoints in SPAs is to use the Microsoft Authentication Library
(MSAL) for JavaScript.
• MSAL.js 2.0 (released July 2020) supports use of authorization code flow
Azure AD app registration
SPA must have an associated Azure AD app registration to support user sign-in &
obtain access token
Implement authentication
Demo
• Single-page applications
Web apps that sign in users and call APIs
Web apps that sign-in users & call APIs
Microsoft identity redirects users back to web app with claims about the user in an Identity token
Web app can also obtain an access token from Microsoft identity to act on the user’s behalf
OAuth 2.0 authorization code grant flow
Azure AD app registration
Web apps must have an associated Azure AD app registration to support
user sign-in & obtain access token
The sign-in process is handled by redirecting the user to the Azure AD sign-in page.
The sign-in process uses the values from the appsettings.json file and the configuration defined
in the previous setup to create the Azure AD URL to send the user to.
When a user signs-in to Azure AD and is redirected back to the web application, the web app uses
the MSAL.NET library to obtain an access token.
Daemon and non-interactive apps
Daemon & non-interactive apps
Some applications need to authenticate and obtain an access token to call secured endpoints without
any user interaction
• Console apps
• Services
• Web application that needs to access services but not in the context of the current user (Azure
KeyVault
Delegated permissions
• Used by apps with a signed-in user present
• Permissions provided to the app by the user so the app can act on the user’s behalf
• Doesn’t give permissions to the app
• User must have the permissions it grants to the app
Application permissions
• Used by apps that run without a signed-in user present
Effective permissions
• Permissions the app has when making requests to the target resource
• Intersection of delegated and application permissions
Effective permissions
Effective permissions are the permissions that your app will have when making requests to the
target resource.
Best practices for requesting permissions
Apps should gracefully handle scenarios where the user does not grant consent to the app when
permissions are requested
Permissions and consent framework
Demo
• Understanding permissions and the consent
framework in the Microsoft identity platform
Delegated permissions and consent
Delegated permissions
Delegated permissions are used by apps that have a signed-in user present
Either the user or an administrator consents to the permissions the app requests
Important to note – users do not grant apps permission; they grant the
app ability to act on their behalf
Some permissions can not be granted by a user and must be granted by an administrator:
• User grantable permissions: User.Read & User.ReadBasic.All
• Administrator grantable permissions: User.Read.All
User consent
When requesting permissions, if the /.default scope represents all static permissions defined in app
registration in the Azure AD admin center
Added to simplify the migration of apps from Microsoft identity v1.0 => v2.0 endpoint
The /.default scope must be used for apps that implement the OAuth 2.0 client credentials flow
Dynamic consent
Introduced in the Microsoft identity v2.0 endpoint
Permissions don’t need to be specified in the app registration in the Azure AD admin center (but this is
highly recommended)
Each time app requests an access token, specifies the permissions it needs on the scope property
If user hasn’t previously consented to the permission, they are prompted to accept them
Enables developers to ask users for only the permissions the app needs at that time, incrementally
asking for more permissions as needed
User consent
If the user has not previously granted the permission to the app or an administrator hasn't
consented on behalf of all user's in the organization, when a user signs-in to an app they're
prompted with the consent dialog.
Static consent
With static consent, the permissions are defined in the app's registration within the Azure AD
admin center.
Application permissions and consent
Application permissions
Some high-privilege permissions in the Microsoft ecosystem can be set to admin-restricted.
• Read all user's full profiles by using If an app requests an application permission
User.Read.All from a user, the user is notified they need an
• Write data to an organization's directory by admin to grant the permission
using Directory.ReadWrite.All
• Read all groups in an organization's directory
by using Group.Read.All
Admin consent
There's also a dedicated admin consent endpoint you can use if you would like to
proactively request that an administrator grants permission on behalf of the entire
tenant.
HTTP
GET
https://login.microsoftonline.com/{tenant}/v2.0/adm
inconsent?
client_id=6731de76-14a6-49ae-97bc-
6eba6914391e
&redirect_uri=http://localhost/myapp/permissions
&scope=https://graph.microsoft.com/calendars.rea
d%20https://graph.microsoft.com/mail.send
&state=12345
Recommendation: provide an admin experience in your app
If an app requires admin consent for to have application permissions high-privileged delegated
permissions, consider providing a special admin experience to trigger the admin consent
Secure custom web APIs to protect LOB systems from custom apps
Who will use your app? Microsoft
Graph
Mobile
Humans App
Partners (B2B)
Web Front End
Consumers (B2C)
API 2 API 3
Terminators (Applications/Services):
On behalf of a user
By themselves
Worker role
Access web APIs with applications (terminators)
In this module we're focusing on the last option in the figure above: terminators.
Create Microsoft identity-secured web APIs
Register & configure an Azure AD Create a new web API project Code the web API project, configured
application to support Microsoft identity
Register an Azure AD application
Console C#
public void ConfigureServices(IServiceCollection services)
{
dotnet new webapi -o ProductCatalog services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
-au singleorg
.AddMicrosoftIdentityWebApi(Configuration.GetSection("AzureAd"));
services.AddControllers();
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new OpenApiInfo { Title = "ProductCatalog",
Version = "v1" });
});
}
public List<Product> GetAllProducts()
{
HttpContext.VerifyUserHasAnyAcceptedScope(new string[] {
"Product.Read" });
return data.Products;
}
Call secured APIs from web applications
Create Microsoft identity-secured web apps
Web apps that call web APIs are confidential client applications.
The next step is to create the web application that will allow the user to sign in and then access
the secured web API.
Console
C#
• Domain: the domain of your Azure AD tenant public void ConfigureServices(IServiceCollection services)
{
where you registered the Azure AD services.AddAuthentication(OpenIdConnectDefaults.AuthenticationScheme)
.AddMicrosoftIdentityWebApp(Configuration.GetSection("AzureAd"))
application
.EnableTokenAcquisitionToCallDownstreamApi(Constants.ProductCatalogAPI.
• TenantId: the ID of your Azure AD tenant SCOPES)
.AddInMemoryTokenCaches();
where you registered the Azure AD
application services.AddControllersWithViews(options =>
{
var policy = new AuthorizationPolicyBuilder()
• ClientId: the ID of your Azure AD application .RequireAuthenticatedUser()
.Build();
• ClientSecret: the secret of your Azure AD options.Filters.Add(new AuthorizeFilter(policy));
});
application services.AddRazorPages()
.AddMicrosoftIdentityUI();
}
Add token acquisition
The next step is to create controllers to implement the pages on the site.
C# C#
[AuthorizeForScopes(Scopes = new[] { Constants.ProductCatalogAPI.CategoryReadScope
Requires administrator to grant consent for configured permissions before obtaining an access
token
Register a new Azure AD app and configure the app with an app secret.
Client credentials grant flow
Daemon apps implement the OAuth 2.0 client credentials grant flow to obtain an access token
from Microsoft identity.
Configure daemon apps to call secured APIs
The next step is to create the daemon app that will obtain an access token and then access the
secured web API.
Console
Your custom app can use this information and, in the cases where the app has the necessary permissions,
enable the user to edit their details from within the app.
Add or delete users
To add a user to your organization, first sign-in to the Azure AD admin center and select the Users
navigation option to open the All users blade.
Restricting apps to specific users
By default, Azure AD apps allow all users in Optionally disable this by enabling the Manually assign users to the app from the
an organization to sign-in to an app “User Assignment Required” property Azure AD admin center
Role-based access control (RBAC)
RBAC helps you manage resources, what areas of an app users have access to and what they
can do with those resources.
Groups can be configured to allow users to find and join groups on their
own
JSON
{
...
"optionalClaims": {
"idToken": [
{
"name": "groups",
"source": null,
"essential": false,
"additionalProperties": [ "emit_as_roles" ]
}
],
"accessToken": [],
"saml2Token": []
}
...
}
Code configuration
In ASP.NET, you can secure a controller so only authenticated users can access it by decorating it
the method with the [Authorize] attribute.
C#
@if (User.IsInRole("22222222-2222-2222-
C# 2222-222222222222"))
{
[Authorize(Roles("22222222-2222-2222-2222-
<li class="nav-item">
222222222222"))]
<a class="nav-link text-dark" asp-area=""
public class ProductsController : Controller
asp-controller="Products" asp-
{}
action="Index">Products</a>
</li>
}
Leverage application roles in custom apps
App roles in custom apps and APIs
RBAC enables administrators to grant permissions to roles vs individuals or
groups
JSON
"appRoles": [
{
"allowedMemberTypes": [ "User" ],
"description": "Administrator role for Product Catalog web application.",
"displayName": "ProductAdministrators",
"id": "98ce9517-557f-4ac5-b827-f18d948ee552",
"isEnabled": true,
"lang": null,
"origin": "Application",
"value": "ProductAdministrators"
},
{
"allowedMemberTypes": [ "User" ],
"description": "Viewer role for Product Catalog web application",
"displayName": "ProductViewers",
"id": "7465fed6-02cc-467c-87c2-fa6e0bf4f929",
"isEnabled": true,
"lang": null,
"origin": "Application",
"value": "ProductViewers"
}
]
Add users and groups to roles
After defining the app roles within the app's manifest, you can now add users to the role.
Code configuration
In ASP.NET, you can secure a controller so only authenticated users can access it by decorating it the method with the [Authorize] attribute.
C# C#
[Authorize(Roles = ("ProductAdministrators"))]
public ActionResult Create()
[Authorize(Roles=("ProductViewers,ProductAdministr {
[Authorize(Roles = ("ProductAdministrators"))]
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create([Bind("ProductName", "CategoryId")] ProductViewModel model)
{
if (ModelState.IsValid)
{
data.Products.Add(new Product()
{
Id = data.Products.Max(p => p.Id) + 1,
Name = model.ProductName,
Category = new Category { Id = model.CategoryId }
});
return RedirectToAction("Index");
}
return View(model);
}
Work with Microsoft Graph
Optimize • Microsoft Graph and query parameters
data usage • Expand related entities and search
with query content in Microsoft Graph
parameters • Reduce traffic with batched requests
Microsoft Graph and query parameters
Microsoft Graph: Gateway to your data in the Microsoft cloud
https://graph.microsoft.com
Office 365 Windows 10 Enterprise Mobility + Security
Users, Groups, Organizations Activities Azure AD
Outlook Device Relay Intune
SharePoint Identity Manager
Commands
OneDrive Advanced Threat Analytics
Teams Notifications
Advanced Threat Protection
Planner
Excel
OneNote
Native SDKs
Utilize framework & platform specific implementations
Abstracts the details of constructing & processing REST requests over HTTP
.NET, iOS, Android, PhP, Ruby, JavaScript, etc.
Optimize data usage with query parameters
Demo
• Use the Graph Explorer to search for content
Optimize data usage with query parameters
Demo
• Reduce traffic with batched requests
Optimize • Understand throttling in Microsoft Graph
network • Avoid throttling and implement throttling
traffic with strategies
Microsoft • Eliminate polling Microsoft Graph with
Graph the delta query
Understand throttling in Microsoft Graph
Understand throttling in Microsoft Graph
When an overwhelming number of requests are received by Microsoft Graph, requests are throttled
Photos are stored as binary data that developers can convert to different formats for various
scenarios
For example: base-64 for web
Accessing profile photos
To get a resource's profile photo, use the /photo/$value endpoint on the resource.
The same operation can be done using the Microsoft Graph .NET SDK:
C#
• accountEnabled (boolean) {
"accountEnabled": true,
• displayName (string) "displayName": "Melissa Darrow",
"mailNickname": "melissad",
• mailNickname (string)
"userPrincipalName":
• passwordProfile (PasswordProfile) "melissad@M365x068225.onmicrosoft.com",
"passwordProfile" : {
• userPrincipalName (string) "forceChangePasswordNextSignIn": true,
"password": "Password1!"
}
}
Manage
group • Working with groups in the organization
lifecycle with • Uses and their groups
Microsoft • Manage group lifecycle
Graph
Working with groups in the organization
Working with groups using Microsoft Graph
Groups are collections of users and other principals that share access to resources
Security groups
Used to control access to resources
Can contain Office 365 groups and other security groups
Users and their groups
Direct vs. transitive membership
Direct membership:
Groups the user has been explicitly added to
Transitive membership
Groups the user is a member of including those via a security group that was included in another security
group that has been added to group
Also includes groups the user has been added to through dynamic membership
Manage group lifecycle
Creating groups with Microsoft Graph
Create new groups by submitting HTTP POST to https://graph.microsoft.com/v1.0/groups & include new group
as a JSON object in the request body
C#
private static async Task<Microsoft.Graph.Group> CreateGroupAsync(GraphServiceClient
client)
Must include minimal properties: {
// create object to define members & owners as 'additionalData'
• displayName (string) var additionalData = new Dictionary<string, object>();
additionalData.Add("owners@odata.bind",
• mailEnabled (boolean) new string[] {
"https://graph.microsoft.com/v1.0/users/d280a087-e05b-4c23-b073-738cdb82b25e"
• mailNickname (string) }
);
• securityEnabled (boolean) additionalData.Add("members@odata.bind",
new string[] {
"https://graph.microsoft.com/v1.0/users/70c095fe-df9d-4250-867d-f298e237d681",
"https://graph.microsoft.com/v1.0/users/8c2da469-1eba-47a4-9322-ee0ddd24d99a"
}
Specify the new group as an Office 365 group: );
groupTypes: [“Unified”]
var group = new Microsoft.Graph.Group
{
AdditionalData = additionalData,
Description = "My first group created with the Microsoft Graph .NET SDK",
DisplayName = "My First Group",
GroupTypes = new List<String>() { "Unified" },
MailEnabled = true,
MailNickname = "myfirstgroup01",
SecurityEnabled = false
};
C#
HTTP
var groupIdToDelete = "{ID}";
DELETE await
https://graph.microsoft.com/v1.0/groups/{ID} client.Groups[groupIdToDelete].Request().Dele
teAsync();
Access files
• Access and download files from OneDrive
with
• Uploading files to OneDrive
Microsoft
• Work with file relationships and trends in
Graph
OneDrive
Access and download files from OneDrive
Why integrate with OneDrive file storage in the cloud?
Work with file content and metadata without downloading the binary
HTTP HTTP
Insights are relationships calculated using advanced analytics & machine learning
techniques
Get notifications on messages, events, contacts, users, groups, conversations, OneDrive files,
alerts, and more
Example notification scenarios
Create an app that will host a web API to listen for notifications.
Create a subscription to tell Microsoft Graph what entities you want to receive
notifications about and the address of your web API to post them to.
• Manage and renew subscriptions as needed
The change notifications that your app receives from Microsoft Graph can allow you
to track the changes of entities if you need to replicate data in your own system.
Microsoft Graph exposes multiple endpoints for developers to create and manage subscriptions:
• Create subscriptions
• HTTP POST https://graph.microsoft.com/v1.0/subscriptions
• Include the details of the subscription in the request body
• List subscriptions
• HTTP GET https://graph.microsoft.com/v1.0/subscriptions
• Retrieve a list of all active, non-expired, subscriptions
• Get one subscription
• HTTP GET https://graph.microsoft.com/v1.0/subscriptions/{GUID}
• Retrieve the details of a specific subscription using the subscription's ID
• Update subscription
• HTTP PATCH https://graph.microsoft.com/v1.0/subscriptions/{GUID}
• Update the expiration time of the subscription
• Delete subscription
• HTTP DELETE https://graph.microsoft.com/v1.0/subscriptions/{GUID}
• Delete an existing subscription
Use change notifications and track changes
Demo
with Microsoft Graph
• Microsoft Graph change notifications
Track changes with Microsoft Graph
Track Changes with the Microsoft Graph API
Add a full regular query at a long interval to be 100% certain no changes have been missed
Extend and Customize SharePoint
• Introduction to the SharePoint
Getting
Framework
started with
• Configure your Office 365 environment
SharePoint
• Configure your development
Framework
environment
Introduction to SharePoint Framework
SharePoint UX – Evolving cross versions
SharePoint Framework leverages an open source, Node.js based toolchain and embraces all web
frameworks + code editors
C#
IIS Express
MSBuild
Project Templates
Develop web
• Overview of SharePoint Framework web
parts with
parts
SharePoint
• Explore a SharePoint Framework project
Framework
Overview of SharePoint Framework web parts
Client-side web parts
They are still web Built for the modern, Runs directly inside a
parts! JavaScript-driven web SharePoint Page
Explore a SharePoint Framework project
Project Structure
.vscode: contains Visual Studio Code integration files
config: contains all config files
dist: contains output from all bundle processes
lib: created automatically on builds – contains pre-bundled built
files
node_modules: created automatically when installing all package
dependencies with a package manager
release: contains output from production bundle processes
src: this is the main folder of the project, it includes the web part,
styles, and a test file
temp: created automatically on builds - contains local dev
webserver files
Key Files – web part class
Defines the main entry point for the web part
Extends the BaseClientSideWebPart
All client-side web parts must extend the
BaseClientSideWebPart class in order to be defined as a
valid web part
Interface that defines the non-standard public properties on
the web part
Persisted when the web part is saved / published from edit
mode
Key Files – web part manifest
Defines the web part metadata
Key Files – SCSS file
Defines the web part styles
Key Files – config file
Contains information about your bundle(s), any external dependencies, localized resources
Specifies the AMD script libraries used in the web part
Client-side Web Part Build Flow
Develop web parts with the SharePoint
Demo
Framework
• Create a SharePoint Framework client-side web
part
Leverage
• Call anonymous third-party REST APIs
Microsoft
• Call Azure AD- secured third-party APIs
Graph and
• Call Microsoft Graph in SharePoint
third-party
Framework solutions
APIs
Consume third-party REST APIs
Consume REST APIs in SPFx - Overview
Common requirement in SPFx project is to display or interact with data external to the web part
Data in SharePoint lists & libraries
Data accessible via Microsoft Graph REST API
Data accessible in external 3rd Party APIs – anonymous & secured
SharePoint Framework provides APIs for all situations when you need to work with data sources
external to the web part
HttpClient: for calling 3rd party REST APIs
MSGraphClient: for calling the Microsoft Graph in the same tenant as the
SharePoint Online tenant
AADHttpClient: for 3rd party REST APIs secured with Azure Active Directory
Ref: https://docs.microsoft.com/sharepoint/dev/spfx/use-aadhttpclient
How It Works: Calling Azure AD Secured REST APIs from SPFx
Using the Azure AD HTTP Client
TypeScript
AadHttpClient
aadHttpClientFactory
.getClient(“https://your-endpoint-uri”)
aadClient: AadHttpClient
aadClient.get(endpoint, AadHttpClient.configurations.v1)
Add SharePoint Package to SharePoint App Catalog
Upload SharePoint packages to the app catalog
Have difference scoping options on exposing your custom tab as a web part and tab in your tenant
Tab executed in the context of the underlaying SharePoint site behind of the specific team
Create Microsoft
Teams tab images
& descriptions
Create manifest to
Microsoft Teams
app
Specify SharePoint Framework Web Part can be Microsoft Teams Tab
Web part manifest property:
supportedHosts
SharePoint Framework web parts as Teams Tabs – already have most of the information in the
SharePoint component’s manifest
Same Microsoft Teams context object available from the Microsoft Teams JavaScript SDK
NPM Package: @microsoft/teams-js
Use the presence of the Microsoft Teams context to determine if web part is running in SharePoint
or Microsoft Teams
Client-side web part settings in Microsoft Teams tabs
Custom Microsoft Teams Tab Configuration Options
SharePoint Framework web parts have public properties
Public properties can be made editable via the property pane
SharePoint page must be in edit mode to edit properties
User must have edit rights to the page to access the property pane
Property Pane Exposed in Microsoft Teams
Web Part property pane displayed when SPFx web part installed as a tab in a Microsoft Teams team
Accessible via the tab context menu Settings option
Extend Microsoft Teams – Segment 1 of 2
Overview of
• What are Microsoft Teams apps?
building apps
• How do you create an app for Microsoft Teams?
for Microsoft • When should you choose to build a custom Microsoft Teams app?
Teams
What are Microsoft Teams apps?
What is a Microsoft Teams app?
A Microsoft Teams app consists of three primary components:
The Microsoft Teams client (web, desktop, or mobile) provides the extensions points
and UI elements users will interact with
Web services hosted by developers provide the APIs and logic that power the app
Where can the Teams client be extended?
There are multiple places where the Microsoft Teams client can be extended to allow users to
interact with the app
Messaging Extensions - search commands are useful for allowing your users to search an external system and then share the results of that search within Teams. With cards and
card actions, you can richly format the results of that search, and allow users to do actions on the result without leaving the Microsoft Teams client.
Messaging Extensions - action commands are great for collecting information from your user in a single place, then sending that information to your web services. They excel in
scenarios where you need to create a record of some kind, or collect more than a few pieces of information as part of a single transaction.
Tabs - in groups and channels provide a shared canvas for multiple people to collaborate. You should add this to your app if you've got information or services that are applicable
to a group of people. Keep in mind that everyone is working from the same canvas, your page should be stateless and operate as a single-page app.
Tabs - in personal apps allow for a personal web-like experience. They're typically best for "hub" scenarios - "items assigned to me", or "things I've created". They can also be useful
for static content like help or about pages.
Conversational bots - in groups and channels help add additional information to a conversation that is useful for everyone (or at least most) involved. They can be used to
proactively add relevant information to the conversation, or respond to user requests ("hey bot, create a poll for where we should go to lunch"). Typically they shouldn't be used for
multi-turn conversations - use a task module to collect the information or move the conversation to a one-to-one chat instead, then insert the results back into the original
conversation.
Conversational bots - in personal apps can enable incredibly diverse workloads. Q&A bots, bots that start workflows in other systems, bots that tell jokes and bots that take notes
are just a few examples. Just remember to consider if a conversation-based interface is the best way to present your functionality.
Webhooks & Connectors are useful to allow users to subscribe a channel to notification messages from an external system.
Tools for developing apps for Microsoft Teams
Developers have multiple options for tools to support development of apps for
Microsoft Teams.
Tools for setting up and configuring your Teams app:
Yeoman Generator for Microsoft Teams
App Studio
Microsoft Teams Toolkit for Visual Studio Code or Visual Studio IDE
The web service takes advantage of the Bot Framework's messaging schema and secure
communication protocol, so you must register your web service as a bot in the Bot
Framework.
Receive queries
Respond to queries
Link unfurling messaging extensions
Developing link unfurling messaging extensions
Authentication is different
Web application style is based on the Teams client light / dark / high-contrast mode
Communication between Teams & the hosted page handled via Teams JavaScript client SDK
Overview of building a Microsoft Teams Tab
Not intended to be shared with others in a Added as part of a chat between two or
team more users
Displays a web page set in the manifest Scope = groupchat
Types of conversations:
In a channel: threaded conversations between multiple people
• Individual interactions need to be concise; limit multi-turn interactions
• Bots have access to conversations where they are directly @mentioned
• Great for notifications, polls/surveys, and interactions with a single request/response cycle
Types of conversations:
In a channel: threaded conversations between multiple people
• Individual interactions need to be concise; limit multi-turn interactions
• Bots have access to conversations where they are directly @mentioned
• Great for notifications, polls/surveys, and interactions with a single request/response cycle
Proactive messages are when the bot creates a new message in a channel.
Possible scenarios:
Welcome message for personal bot conversation
Poll responses
Notification of external events
1. App icon
2. App short name
3. Task module’s title
4. Close/cancel button
5. Entire area available to the web page
option
6. Entire area rendered if using the Adaptive
Card option
7. Adaptive Card button
Task modules in Microsoft Teams
Demo
• Collecting user input with task modules
Using adaptive cards and deep links in task modules
Overview of adaptive cards
A card is a user-interface (UI) container for short or related pieces of information.
JSON
{
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"type": "AdaptiveCard",
"version": "1.0",
"body": [
{
"type": "Container",
"items": [
{
"type": "TextBlock",
"text": "YouTube Video Selector",
"weight": "bolder",
"size": "extraLarge"
}]},
{
"type": "Container",
"items": [
{
"type": "TextBlock",
"text": "Enter the ID of a YouTube video to show in the task module player.",
"wrap": true
},
{
"type": "Input.Text",
"id": "youTubeVideoId",
"value": ""
}]}],
"actions": [
{
"type": "Action.Submit",
"title": "Update" }]}
Task modules and bots
Bots can invoke and process submissions from task modules
Microsoft’s Bot Framework & the Microsoft Teams SDK have added support for
Invoking task modules
Handling the Action.Submit event where a task module submits information back to the bot
Two types:
Outgoing webhooks allow users to send text messages from a channel to the
developer’s web services without having to use the Microsoft Bot Framework
Incoming webhooks work as a type of connector, allowing users to subscribe to
receive notifications and messages from a developer’s web services
Process channel messages with outgoing webhooks
An outgoing webhook allows your users
to send messages from a channel to
your web service.
Key features:
Scoped Configuration
Reactive Messaging
Standard HTTP messaging exchange
Teams API method support
Limitations
Add an outgoing webhook
Authenticate messages
Teams provides a unique URL to which you send a JSON payload with
the message that you want to POST, typically in a card format.
Key features:
Scoped configuration
Secure resource definitions
Actionable messaging support
Independent HTTPS messaging support
Markdown support
Add an incoming webhook
Register the incoming webhook
Microsoft Teams teams are founded on Microsoft 365 groups & SharePoint sites
"groupTypes":["Unified"],
Create a group using the Microsoft "mailEnabled":true, "securityEnabled":false,
https://graph.microsoft.com/v1.0/groups?$select=id,
resourceProvisioningOptions
https://graph.microsoft.com/v1.0/teams/{group-id}
https://graph.microsoft.com/v1.0/me/joinedTeams
Protected APIs in Microsoft Teams
Some Microsoft Teams APIs exposed by Microsoft Graph access sensitive data
Require additional validation beyond the just permissions defined & consented to in Azure AD
Need to know the teamsAppId of the app, and the entityId, contentUrl, removeUrl, and
websiteUrl to provide for that kind of app.
To create or configure a tab, submit an HTTP POST to the /tabs endpoint on a channel
with a payload that contains the settings to configure the tab
1 2 3
Custom Microsoft Custom Microsoft Notification activity
Teams app must be Teams app must be types must be
installed for the associated with an registered in the
recipient of the Azure AD app custom Microsoft
notification registration Teams app’s manifest
Requirement #2: Associate Microsoft Teams apps with Azure AD apps
The first requirement is to associate the Microsoft Teams app with the Azure AD
app registration created for the app.
JSON
{
"$schema": "https://developer.microsoft.com/en-us/json-schemas/teams/v1.8/MicrosoftTeams.schema.json",
"manifestVersion": "1.8",
...
"webApplicationInfo": {
"id": "8a2d385d-8504-43f8-a9b2-80caa44bfe22",
"resource": "api://app.contoso.com/8a2d385d-8504-43f8-a9b2-80caa44bfe22"
}
}
Requirement #3: Register the supported activity types
The third requirement is to register with Microsoft Teams the types of activities the app can send
notifications about.
JSON
{
"$schema": "https://developer.microsoft.com/en-us/json-schemas/teams/v1.8/MicrosoftTeams.schema.json",
"manifestVersion": "1.8",
...
"activities": {
"activityTypes": [
{
"type": "userMention",
"description": "Personal Mention Activity",
"templateText": "{actor} added the {tabName} tab to the {teamName}'s | {channelName} channel"
}
]
}
}
Sending activity feed notifications
Activity feed notifications are sent to users with the Microsoft Graph's
/teams/{groupId}/sendActivityNotification endpoint using an HTTP POST.
JSON
{
"topic": {
"source": "entityUrl",
"value": "https://graph.microsoft.com/v1.0/teams/{groupId}"
},
"activityType": "userMention",
"previewText": {
"content": "New tab created"
},
"recipient": {
"@odata.type": "microsoft.graph.aadUserNotificationRecipient",
"userId": "{recipient-objectID}"
},
"templateParameters": [
{ "name": "tabName", "value": "Word" },
{ "name": "teamName", "value": "Test Team" },
{ "name": "channelName", "value": "General" }
]
}
Authentication
• Understand authentication and single sign-on in
and single-
Microsoft Teams apps
sign on in
• Single sign-on (SSO) with Microsoft Teams tabs
Microsoft
• Single sign-on (SSO) with Microsoft Teams bots
Teams
Understand authentication and single sign-on in
Microsoft Teams apps
Microsoft Teams and Single Sign-on (SSO)
Microsoft Teams SSO support for tabs, task modules, and bots
permissions: this is a list of the API permissions your app needs the user to consent to, such
as User.Read or Mail.Read
obtain tokens with the OAuth2 implicit flow: Microsoft Teams must be able to obtain the
access tokens and ID tokens
access_as_user permission: this permission exposed by the app registration is used to grant
apps, such as Microsoft Teams, to act on the user's behalf:
preauthorize Microsoft Teams clients to act on the user's behalf: this setting removes
the requirement for users to explicitly consenting to allow Microsoft Teams to act on the
user's behalf
Unique characteristics of the Azure AD app for tabs
The next step is for your tab to obtain the initial ID token from Microsoft Teams.
TypeScript
microsoftTeams.authentication.getAuthToken({
successCallback: (result: string) => { this.ssoLoginSuccess(result) },
failureCallback: (error: string) => { this.ssoLoginFailure(error) }
});
Obtain an access token for Microsoft Graph
When you want to submit requests to Microsoft Graph from your tab, you need to obtain an
access token from Azure AD to include in your requests to Microsoft Graph.
First, you must associate the Azure AD app with the Microsoft Teams app.
JSON