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-Entra.md
+103-1Lines changed: 103 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -100,6 +100,8 @@ Go back to the Visual Studio project that you created before. Open the **appsett
100
100
}
101
101
```
102
102
103
+
To have the latest types needed to support the security infrastructure of the Bot Powered ACE, upgrade the NuGet package with name "Microsoft.Bot.Builder.Integration.AspNet.Core" to version 4.22.9 or higher.
104
+
103
105
Rename the **EmptyBot.cs** file into **WelcomeUserBot.cs**, change the base class from `ActivityHandler` to `SharePointActivityHandler`, and import the namespace `Microsoft.Bot.Builder.SharePoint`.
104
106
Follow the instructions provided in the ["Implement the actual Bot Powered ACE"](./Building-Your-First-Bot-Powered-ACE.md#implement-the-actual-bot-powered-ace) section of the reference article ["Building your first Bot Powered Adaptive Card Extension"](./Building-Your-First-Bot-Powered-ACE.md) to implement the basic code of the Bot Powered ACE. Specifically, implement four Card Views:
105
107
@@ -231,6 +233,94 @@ The Signed out Card View is a basic card view with a simple text message in the
231
233
232
234
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-SSO).
233
235
236
+
#### Implementing Bot Powered ACEs specific methods
237
+
238
+
You also need to implement couple of methods to handle the card view rendering and any action, like a button selection, in the UI of the card views. Following code excerpt shows how to implement both the `OnSharePointTaskGetCardViewAsync` and `OnSharePointTaskHandleActionAsync` methods.
The `OnSharePointTaskGetCardViewAsync` method handles the rendering of the Welcome card view, rendering the display name and the user principal name of the currently authenticated user, if any. On the contrary, if there isn't a user's security context, it renders the Sign-in card view, configuring the name of the OAuth connection to use and retrieving the Sign-in URL from the infrastructural services provided by the Bot Framework via the `GetSignInResource` method.
321
+
322
+
The `OnSharePointTaskHandleActionAsync` method handles the selection of all the buttons provided in the UI of the Bot Powered ACE.
323
+
234
324
#### Handling single sign-on dedicated logic
235
325
236
326
To authenticate users with single sign-on, you need to override the `OnSignInInvokeAsync` method to handle the single sign-on request.
@@ -313,7 +403,7 @@ If you're using dependency injection, you can configure the cache manager as a s
313
403
314
404
Once you support the single sign-on logic, you can rely on a set of utility methods to retrieve the current user's information. These methods retrieve the current authenticated user, their token, and provide the sign out logic, if there's need.
315
405
316
-
Here follows the internal logic that you should rely on to manage the access token and the current user's identity retrieval through the `GetAuthenticatedUser`and `GetUserToken` methods.
406
+
Here follows the internal logic that you should rely on to manage the access token and the current user's identity retrieval through the `GetAuthenticatedUser`, `GetUserToken`, and `GetSignInResource` methods.
The `GetAuthenticatedUser` method accepts the magic code value and the Bot `TurnContext` instance. Internally it uses the `GetUserToken` method to retrieve the actual access token value and then uses the `JwtSecurityToken` class of `System.IdentityModel.Tokens.Jwt` to decode the token and get access to the user's display name and user principal name.
@@ -370,6 +470,8 @@ The `GetUserToken` method retrieves an instance of the `UserTokenClient` service
370
470
The result of the `GetUserTokenAsync` method is an instance of the `TokenResponse` type that includes a `Token` property with the actual value of the access token.
371
471
Once you have the access token and you extracted the display name and the user principal name, you can render them in the welcome card view.
372
472
473
+
The `GetSignInResource` method relies on an instance of the `UserTokenClient` service and retrieves the URL to use for signing in the user invoking the `GetSignInResourceAsync` method.
474
+
373
475
In the code excerpt, you can also see how the sign out is handled, invoking the custom `SignOutUser` method, which is illustrated in the following code excerpt.
Copy file name to clipboardExpand all lines: docs/spfx/viva/bot-powered/AuthN-and-AuthZ-in-Bot-Powered-ACEs-Magic-Code.md
+4-2Lines changed: 4 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -25,8 +25,8 @@ Following picture you can see how the Adaptive Card Extension looks like in the
25
25
26
26
In both scenarios (desktop and mobile), there are:
27
27
28
-
-a "Sign in" button to initiate the sign-in flow
29
-
-a "Complete sign in" button to provide the magic code obtained by the Bot Framework and complete the authentication flow
28
+
- "Sign in" button to initiate the sign-in flow
29
+
- "Complete sign in" button to provide the magic code obtained by the Bot Framework and complete the authentication flow
30
30
31
31
From a developer point of view, you build the ACE once and you benefit of it in both desktop and mobile experiences.
32
32
The whole source code of the .NET sample is available in the following GitHub repository: [Welcome User Bot Powered ACE](https://github.com/pnp/viva-dev-bot-powered-aces/tree/main/samples/dotnet/WelcomeUserBotPoweredAce).
@@ -85,6 +85,8 @@ Go back to the Visual Studio project that you created before. Open the **appsett
85
85
}
86
86
```
87
87
88
+
To have the latest types needed to support the security infrastructure of the Bot Powered ACE, upgrade the NuGet package with name "Microsoft.Bot.Builder.Integration.AspNet.Core" to version 4.22.9 or higher.
89
+
88
90
Rename the **EmptyBot.cs** file into **WelcomeUserBot.cs**, change the base class from `ActivityHandler` to `SharePointActivityHandler`, and import the namespace `Microsoft.Bot.Builder.SharePoint`.
89
91
Follow the instructions provided in the ["Implement the actual Bot Powered ACE"](./Building-Your-First-Bot-Powered-ACE.md#implement-the-actual-bot-powered-ace) section of the reference article ["Building your first Bot Powered Adaptive Card Extension"](./Building-Your-First-Bot-Powered-ACE.md) to implement the basic code of the Bot Powered ACE. Specifically, implement four Card Views:
0 commit comments