Skip to content

Commit b240d94

Browse files
committed
Updated docs about Bot Powered ACEs
1 parent feff7e6 commit b240d94

7 files changed

+162
-144
lines changed

docs/spfx/viva/bot-powered/AuthN-and-AuthZ-in-Bot-Powered-ACEs-Entra.md

Lines changed: 71 additions & 40 deletions
Large diffs are not rendered by default.

docs/spfx/viva/bot-powered/AuthN-and-AuthZ-in-Bot-Powered-ACEs-Magic-Code.md

Lines changed: 73 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: Building Bot Powered Adaptive Card Extensions with Magic Code authentication
33
description: Learn how to secure Bot Powered Adaptive Card Extensions (ACEs) for Microsoft Viva Connections using any identity provider and a magic code.
4-
ms.date: 11/08/2024
4+
ms.date: 11/15/2024
55
ms.localizationpriority: high
66
---
77
# Building Bot Powered Adaptive Card Extensions with Magic Code authentication
@@ -36,20 +36,79 @@ The whole source code of the .NET sample is available in the following GitHub re
3636
First of all, you should create a Bot Powered ACE following the guidance provided in article ["Building your first Bot Powered Adaptive Card Extension,"](./Building-Your-First-Bot-Powered-ACE.md) stopping before the section ["Implement the actual Bot Powered ACE."](./Building-Your-First-Bot-Powered-ACE.md#implement-the-actual-bot-powered-ace)
3737
For the sake of simplicity, assume that the Bot Powered ACE project name is "WelcomeUserBotPoweredAce" and register the Azure Bot accordingly to the guidance.
3838

39-
### Configuring security for a Bot Powered ACE
39+
## Configuring security for the Bot Powered ACE
4040

4141
Before starting to develop the actual Bot Powered ACE, you need to enrich the configuration of the Azure Bot and of the Microsoft App behind the scenes of the Azure Bot.
42-
To access the Microsoft App backing the Azure Bot, open the "Configuration" panel of the Azure Bot and select the "Manage Password" link. In the Microsoft Entra ID application, select the Authentication panel and add the following URL as another "Redirect URI" for the application.
42+
To access the Microsoft App backing the Azure Bot, open the "Configuration" panel of the Azure Bot and select the "Manage Password" link.
43+
44+
Now, select the "Authentication" panel of the Microsoft App and under the "Platform configurations" section, select on "Add a platform" and select to add a *Web* platform. Then configure the following value for the "Redirect URIs" setting field.
4345

4446
```http
4547
https://token.botframework.com/.auth/web/redirect
4648
```
4749

48-
Select the "Save" button of the Authentication page when you're done configuring the extra URL. Then you need to configure an OAuth connection for the Azure Bot. To configure the OAuth connection, go back to the "Configuration" panel of the Azure Bot and select the "Add OAuth Connection Settings" button.
50+
You should also enable "Implicit grant and hybrid flows" by selecting the options to issue "Access tokens" and "ID tokens." Select the "Configure" button and your new Web platform is configured.
51+
52+
![The panel to configure a Web platform for the Microsoft App. You can configure the "Redirect URIs" for the web app and enable the "Implicit grant and hybrid flows" with support for "Access tokens" and "ID tokens".](./images/Azure-Portal-Create-Azure-Bot-05.png)
53+
54+
Now, select the "API permissions" panel and configure the app with the following delegated permissions:
55+
56+
* email
57+
* offline_access
58+
* openid
59+
* profile
60+
* User.Read
61+
62+
Select the "Grant admin consent for ..." button, in order to grant the permissions at tenant level.
63+
64+
![The panel to configure the "API permissions". There are few permissions already selected, including: email, offline_access, openid, profile, and User.Read. All of the permissions are granted at tenant level.](./images/Azure-Portal-Create-Azure-Bot-06.png)
65+
66+
Now, move to the "Expose an API" panel and configure a unique URI for your application selecting the "Add" link just beside the "Application ID URI" label. Here you need to configure a value for the "Application ID URI" that matches the following rule:
67+
68+
```http
69+
api://<your-ngrok-reverse-proxy-name>.ngrok.io/<App-Client-ID>
70+
```
71+
72+
For example, if you plan to use the name *welcome-bot-powered-ace* with ngrok, and the Client ID of your application is *fff49e21-925f-4dc9-be03-2680c4783091* the "Application ID URI" should be:
73+
74+
```http
75+
api://welcome-bot-powered-ace.ngrok.io/fff49e21-925f-4dc9-be03-2680c4783091
76+
```
77+
78+
> [!NOTE]
79+
> Mind the api:// moniker at the beginning of the Application ID URI value, and be careful to not use http:// or https:// unless you want to use a verified ___domain of the organization or its subdomain.
80+
81+
Now in the "Scopes defined by this API" section add a new scope by selecting the "Add a scope" button. Provide the following settings for the new scope:
82+
83+
* Scope name: *access_as_user*.
84+
* Who can consent?: Admins and users.
85+
* Admin consent display name: Teams can access the user's profile.
86+
* Admin consent description: Allows Teams to call the app's web APIs as the current user.
87+
* User consent display name: Teams can access the user's profile and make requests on the user's behalf.
88+
* User consent description: Enables Teams to call this app's APIs with the same rights as the user.
89+
* State: Enabled.
90+
91+
![The panel to add a new permission scope. There are options to configure the scope name, who can consent the scope, the admin consent display name and description, the user consent display name and description, and the state of the scope.](./images/Azure-Portal-Create-Azure-Bot-07.png)
92+
93+
Lastly, in the "Authorized client applications" section, you need to configure the client ID of the "SharePoint Online Web Client Extensibility" application. You also need to authorize that client application to consume your Microsoft App, so that users shouldn't be asked to consent when the Viva Connections client calls your API. The client ID of the "SharePoint Online Web Client Extensibility" application is the following one:
94+
95+
* 08e18876-6177-487e-b8b5-cf950c1e598c
96+
97+
While adding it to the list of "Authorized client applications", select the permission scope that you configured for the API.
98+
99+
![The panel to add a new authorized client application. You can provide the client ID of the authorized client application and you can select the scopes that you want to authorize for that specific client application.](./images/Azure-Portal-Create-Azure-Bot-08.png)
100+
101+
At the end of this stage, the "Expose an API" panel should look like in the following picture.
102+
103+
![The "Expose an API" panel configured with a custom Application ID URI, a custom scope with name "access_as_user", and a couple of authorized client applications.](./images/Azure-Portal-Create-Azure-Bot-09.png)
104+
105+
## Configuring the OAuth connection for the Azure Bot
106+
107+
Then you need to configure an OAuth connection for the Azure Bot. To configure the OAuth connection, go back to the "Configuration" panel of the Azure Bot and select the "Add OAuth Connection Settings" button.
49108

50109
![The configuration panel for an Azure Bot. It includes settings about Messaging Endpoint URL, the Microsoft App ID, the Application Insights keys, the Schema Transformation Version, and the OAuth Connection settings. The "Add OAuth Connection Settings" button is highlighted.](./images/Azure-Portal-Configure-OAuth-Connection-Azure-Bot-01.png)
51110

52-
You're prompted with a panel to configure the name of the new OAuth connection and the service provider that you want to use. The name can be whatever text you like, but you need to save it in a safe place because you need it later. Let's name the connection "WelcomeUserBot-EntraID." The service provider defines the Identity Provider to use for the actual OAuth connection. There are plenty of options. In order to rely on Microsoft Entra ID, even without single sign-on, choose "Azure Active Directory v2."
111+
You're prompted with a panel to configure the name of the new OAuth connection and the service provider that you want to use. The name can be whatever text you like, but you need to save it in a safe place because you need it later. Let's name the connection "WelcomeUserBot-EntraID." The service provider configuration field defines the Identity Provider to use for the actual OAuth connection. There are plenty of options. In order to rely on Microsoft Entra ID, choose "Azure Active Directory v2."
53112
After selecting the service provider, you have to configure it. For "Azure Active Directory v2" you have to provide:
54113

55114
* Client ID: the client ID of the Microsoft App behind the scenes of your Azure Bot. It's the value that you get while registering the Azure Bot.
@@ -71,7 +130,7 @@ If you select the "Copy Token" button, you can then open the [https://jwt.ms](ht
71130
> [!NOTE]
72131
> If you inspect the claims of the token, you can see the `aud` (Audience, which is the Client ID of the Microsoft Graph) `app_displayname` (App display name), `iss` (Token issuer), `appid` (Client ID), `tid` (Tenant ID), `scp` (Permission scopes). You can also double-check that they refer to the application that you just configured.
73132
74-
### Implementing security in your Bot
133+
## Implementing security in your Bot
75134

76135
Go back to the Visual Studio project that you created before. Open the **appsettings.json** file and add a new setting called "ConnectionName" and set its value to the name of the OAuth connection that you created. Here you can see how the settings file should look like.
77136

@@ -95,7 +154,7 @@ Follow the instructions provided in the ["Implement the actual Bot Powered ACE"]
95154
* Signed-Out: it's the Card View to confirm when an authenticated user signed out.
96155
* Error: it's the Card View to show an error message, in case an error occurs.
97156

98-
#### Implementing the welcome card view
157+
### Implementing the welcome card view
99158

100159
In the following code excerpt, you can see how the welcome Card View is defined in the constructor of the Bot.
101160

@@ -142,7 +201,7 @@ cardViews.TryAdd(homeCardViewResponse.ViewId, homeCardViewResponse);
142201

143202
As you can see, it's a Primary Text Card View, which simply renders a text with the current user display name in the header. There's also another text with the user principal name in the body. Additionally there's a "Sign out" button that allows the user to sign out, when there's a current authenticated session.
144203

145-
#### Implementing sign-in card view with automatic magic code handling
204+
### Implementing sign-in card view with automatic magic code handling
146205

147206
To support Microsoft Entra ID (Azure Active Directory v2) authentication with magic code automatic handling, you need to implement the Sign-In card as follows:
148207

@@ -186,7 +245,7 @@ You need to use the `SignInCardViewParameters` factory method to create a Sign I
186245
In the sample implementation, when the user selects the "Complete sign in" button a custom Quick View is rendered in order to collect the magic code and process it to acquire the access token.
187246
One last important thing to notice is the setting of the `CardViewType` property for the Card View object to value "signIn," which is the value required to configure the automatic magic code handling without single sign-on, in case you use Microsoft Entra ID.
188247

189-
#### Implementing other card views
248+
### Implementing other card views
190249

191250
In the following code excerpt you can see the SignedOut card implementation, which defines a card that confirms to the user that the sign out was completed:
192251

@@ -227,7 +286,7 @@ The Signed out Card View is a basic card view with a simple text message in the
227286

228287
In the sample solution, there's also an Error Card View, which for the sake of simplicity isn't illustrated in this article but is available in the [reference solution](https://github.com/pnp/viva-dev-bot-powered-aces/tree/main/samples/dotnet/WelcomeUserBotPoweredAce).
229288

230-
#### Implementing magic code handling quick view
289+
### Implementing magic code handling quick view
231290

232291
Here follows the definition of the Quick View used to implement the "Complete sign in" logic.
233292

@@ -290,11 +349,11 @@ It's a Quick View with a number input field with ID **magicCode** and a submit b
290349
> [!IMPORTANT]
291350
> Being the "Complete sign in" user experience developed by you, it is completely customizable. So the layout, text messages, buttons, etc. are up to you and you can freely design them.
292351
293-
### Handling the magic code
352+
## Handling the magic code
294353

295354
Once you have the magic code, either automatically with Microsoft Entra ID or manually with any other Identity Provider, you need to process its value to acquire an actual access token. Depending on the sign in flow, you can handle the magic code while rendering a Card View in the `OnSharePointTaskGetCardViewAsync` method, or in the `OnSharePointTaskHandleActionAsync` method when the user submits the magic code via the "Complete sign in" manual experience.
296355

297-
#### Automatically handling the magic code
356+
### Automatically handling the magic code
298357

299358
In the following code excerpt, you can see how to process the magic code automatically submitted by the Microsoft Entra ID experience, when rendering a card view.
300359

@@ -433,7 +492,7 @@ private async Task<SignInResource> GetSignInResource(ITurnContext<IInvokeActivit
433492

434493
While the **connectionName** property contains the name of the OAuth connection configured for the Azure Bot.
435494

436-
#### Manually handling the magic code with the "Complete sign in" custom logic
495+
### Manually handling the magic code with the "Complete sign in" custom logic
437496

438497
In case you need to manually handle the magic code, you need to implement some custom logic in the `OnSharePointTaskHandleActionAsync` method. Here follows a code excerpt of the method.
439498

@@ -522,7 +581,7 @@ private async Task SignOutUser(ITurnContext<IInvokeActivity> turnContext, Cancel
522581

523582
The method uses the `UserTokenClient` service to invoke the `SignOutUserAsync` method.
524583

525-
### Configuring the manifest
584+
## Configuring the manifest
526585

527586
The implementation of the Bot Powered ACE is now complete and you just need to create a manifest file and deploy it into the target tenant SharePoint Online App Catalog. You can find step by step instructions about how to do that in the section ["Define the **manifest.json** file for the solution"](./Building-Your-First-Bot-Powered-ACE.md#define-the-manifestjson-file-for-the-solution) section of the reference article ["Building your first Bot Powered Adaptive Card Extension."](./Building-Your-First-Bot-Powered-ACE.md)
528587

@@ -537,8 +596,4 @@ To properly support authentication, you need to add a `webApplicationInfo` secti
537596

538597
The `id` property is the actual Client ID of the Microsoft App behind the scenes of your Azure Bot. The `resource` property is the unique URI that you configured for that Microsoft App.
539598

540-
Consider a Bot Powered ACE configured for multitenant and deployed on a target tenant. The first time users run it, they need to grant consent to your Azure Bot application to access Microsoft Graph with delegated permissions. The user's consent is collected through a custom dialog provided by Microsoft Entra ID. In the following picture, you can see the user's consent dialog in action.
541-
542-
![The popup dialog of Microsoft Entra ID to collect the user's consent to access specific resources based on the current Azure Bot application permissions.](./images/Bot-Powered-ACE-Secured-Consent-Multitenant.png)
543-
544599
You're now ready to package the solution, deploy it on the SharePoint Online App Catalog, and play with it. You can follow the instructions provided in section ["Run and test the solution"](./Building-Your-First-Bot-Powered-ACE.md#run-and-test-the-solution) of the reference article ["Building your first Bot Powered Adaptive Card Extension."](./Building-Your-First-Bot-Powered-ACE.md)

docs/spfx/viva/bot-powered/Building-Your-First-Bot-Powered-ACE-TTK-TS.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: Building your first Bot Powered Adaptive Card Extension with Microsoft Teams Toolkit and TypeScript
33
description: Learn how to build your first Bot Powered Adaptive Card Extension (ACE) using the Bot Framework with Microsoft Teams Toolkit and TypeScript.
4-
ms.date: 11/10/2024
4+
ms.date: 11/15/2024
55
ms.localizationpriority: high
66
---
77
# Building your first Bot Powered Adaptive Card Extension with Microsoft Teams Toolkit and TypeScript
@@ -26,7 +26,7 @@ Following picture you can see how the Adaptive Card Extension looks like in the
2626

2727
From a developer point of view, you build the ACE once and you benefit of it in both desktop and mobile experiences.
2828

29-
## Prerequirements
29+
### Prerequirements
3030

3131
First of all, in order to develop a Bot Powered ACE with Microsoft Teams Toolkit and TypeScript, you need to have the following tools and packages installed on your development machine:
3232

0 commit comments

Comments
 (0)