You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/spfx/viva/bot-powered/AuthN-and-AuthZ-in-Bot-Powered-ACEs-Magic-Code.md
+73-18Lines changed: 73 additions & 18 deletions
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
---
2
2
title: Building Bot Powered Adaptive Card Extensions with Magic Code authentication
3
3
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
5
5
ms.localizationpriority: high
6
6
---
7
7
# 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
36
36
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)
37
37
For the sake of simplicity, assume that the Bot Powered ACE project name is "WelcomeUserBotPoweredAce" and register the Azure Bot accordingly to the guidance.
38
38
39
-
###Configuring security for a Bot Powered ACE
39
+
## Configuring security for the Bot Powered ACE
40
40
41
41
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.
43
45
44
46
```http
45
47
https://token.botframework.com/.auth/web/redirect
46
48
```
47
49
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
+

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
+

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:
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:
> 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
+

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
+

100
+
101
+
At the end of this stage, the "Expose an API" panel should look like in the following picture.
102
+
103
+

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.
49
108
50
109

51
110
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."
53
112
After selecting the service provider, you have to configure it. For "Azure Active Directory v2" you have to provide:
54
113
55
114
* 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
71
130
> [!NOTE]
72
131
> 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.
73
132
74
-
###Implementing security in your Bot
133
+
## Implementing security in your Bot
75
134
76
135
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.
77
136
@@ -95,7 +154,7 @@ Follow the instructions provided in the ["Implement the actual Bot Powered ACE"]
95
154
* Signed-Out: it's the Card View to confirm when an authenticated user signed out.
96
155
* Error: it's the Card View to show an error message, in case an error occurs.
97
156
98
-
####Implementing the welcome card view
157
+
### Implementing the welcome card view
99
158
100
159
In the following code excerpt, you can see how the welcome Card View is defined in the constructor of the Bot.
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.
144
203
145
-
####Implementing sign-in card view with automatic magic code handling
204
+
### Implementing sign-in card view with automatic magic code handling
146
205
147
206
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:
148
207
@@ -186,7 +245,7 @@ You need to use the `SignInCardViewParameters` factory method to create a Sign I
186
245
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.
187
246
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.
188
247
189
-
####Implementing other card views
248
+
### Implementing other card views
190
249
191
250
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:
192
251
@@ -227,7 +286,7 @@ The Signed out Card View is a basic card view with a simple text message in the
227
286
228
287
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).
229
288
230
-
####Implementing magic code handling quick view
289
+
### Implementing magic code handling quick view
231
290
232
291
Here follows the definition of the Quick View used to implement the "Complete sign in" logic.
233
292
@@ -290,11 +349,11 @@ It's a Quick View with a number input field with ID **magicCode** and a submit b
290
349
> [!IMPORTANT]
291
350
> 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.
292
351
293
-
###Handling the magic code
352
+
## Handling the magic code
294
353
295
354
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.
296
355
297
-
####Automatically handling the magic code
356
+
### Automatically handling the magic code
298
357
299
358
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.
While the **connectionName** property contains the name of the OAuth connection configured for the Azure Bot.
435
494
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
437
496
438
497
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.
The method uses the `UserTokenClient` service to invoke the `SignOutUserAsync` method.
524
583
525
-
###Configuring the manifest
584
+
## Configuring the manifest
526
585
527
586
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)
528
587
@@ -537,8 +596,4 @@ To properly support authentication, you need to add a `webApplicationInfo` secti
537
596
538
597
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.
539
598
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
-

543
-
544
599
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)
Copy file name to clipboardExpand all lines: docs/spfx/viva/bot-powered/Building-Your-First-Bot-Powered-ACE-TTK-TS.md
+2-2Lines changed: 2 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
---
2
2
title: Building your first Bot Powered Adaptive Card Extension with Microsoft Teams Toolkit and TypeScript
3
3
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
5
5
ms.localizationpriority: high
6
6
---
7
7
# 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
26
26
27
27
From a developer point of view, you build the ACE once and you benefit of it in both desktop and mobile experiences.
28
28
29
-
## Prerequirements
29
+
###Prerequirements
30
30
31
31
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:
0 commit comments