In my previous post you were able to learn how to authenticate user in Power Virtual Agent. This post is about getting and using context of the authenticated user.

Authentication in PVA

Authentication in PVA is quite simple. It is built out of the below steps basically.

  1. User enters communication with the Bot
  2. Bot display button to log in
  3. User provides credentials
  4. After is logged in, authentication provider (AAD in this case) returns validation code
  5. Validation code, once provided back in a chat window, generates and stores bearer token in the AuthToken variable.
Authentication in Power Virtual Agent

Using the user’s context

To use now context of the user in your Power Automate, you have to use obtained bearer token as the authorization method.

Important! Power Automate flows having actions with a defined connection, authorized for different user, will not be executed using the context of the user from bot conversation.

To use context of a user you have to choose actions, that will authenticate on-the-go, for example HTTP (Premium). Then provide the token as the parameter in “Action” calling Power Automate:

And finally use the passed token from PVA as the “Raw” authentication method:

Using token from PVA to get user context in calling Microsoft Graph API.

In result you will be able (in this example) to call Graph API using context of a user who is authenticated in the conversation with a bot.

And that’s it. I hope this will help you benefit from calling action with user context and therefore personalize user experience in your Power Virtual Agents conversations. If you have any questions post them in comments below!