Skip to content

Latest commit

 

History

History
132 lines (100 loc) · 7.18 KB

File metadata and controls

132 lines (100 loc) · 7.18 KB

Copilot Studio Client Console Sample

Instructions - Setup

Prerequisite

To setup for this sample, you will need the following:

  1. An Agent Created in Microsoft Copilot Studio
  2. Ability to Create a Application Identity in Azure for a Public Client/Native App Registration Or access to an existing Public Client/Native App registration with the CopilotStudio.Copilot.Invoke API Permission assigned.

Create a Agent in Copilot Studio

  1. Create a Agent in Copilot Studio
    1. Publish your newly created Agent
    2. In Copilot Studio, go to Settings => Advanced => Metadata and copy the following values, You will need them later:
      1. Schema name
      2. Environment Id

Create an Application Registration in Entra ID - User Interactive Login

This step will require permissions to Create application identities in your Azure tenant. For this sample, you will be creating a Native Client Application Identity, which does not have secrets.

  1. Open https://portal.azure.com
  2. Navigate to Entra Id
  3. Create an new App Registration in Entra ID
    1. Provide a Name
    2. Choose "Accounts in this organization directory only"
    3. In the "Select a Platform" list, Choose "Public Client/native (mobile & desktop)
    4. In the Redirect URI url box, type in http://localhost (note: use HTTP, not HTTPS)
    5. Then click register.
  4. In your newly created application
    1. On the Overview page, Note down for use later when configuring the example application:
      1. the Application (client) ID
      2. the Directory (tenant) ID
    2. Goto Manage
    3. Goto API Permissions
    4. Click Add Permission
      1. In the side panel that appears, Click the tab API's my organization uses
      2. Search for Power Platform API.
        1. If you do not see Power Platform API see the note at the bottom of this section.
      3. In the permissions list choose Delegated Permissions, CopilotStudio and Check CopilotStudio.Copilots.Invoke
      4. Click Add Permissions
    5. (Optional) Click Grant Admin consent for copilotsdk
    6. On the Authentication page, under Advanced settings, make sure the Enable the following mobile and desktop flows toggle is set to Yes.
    7. Close Azure Portal

Tip

If you do not see Power Platform API in the list of API's your organization uses, you need to add the Power Platform API to your tenant. To do that, goto Power Platform API Authentication and follow the instructions on Step 2 to add the Power Platform Admin API to your Tenant

Instructions - Configure the Example Application - User Interactive Login

With the above information, you can now run the client CopilostStudioClientSample.

  1. Open the appSettings.json file for the CopilotStudioClientSample, or rename launchSettings.TEMPLATE.json to launchSettings.json.
  2. Configured the placeholder values for the various key's based on what was recorded during the setup phase.
  "CopilotStudioClientSettings": {
    "EnvironmentId": "", // Environment ID of environment with the CopilotStudio App.
    "SchemaName": "", // Schema Name of the Copilot to use
    "TenantId": "", // Tenant ID of the App Registration used to login,  this should be in the same tenant as the Copilot.
    "AppClientId": "" // App ID of the App Registration used to login,  this should be in the same tenant as the Copilot.
  }

Create an Application Registration in Entra ID - Service Principal Login

Warning

The Service Principal login method is not generally supported in the current version of the CopilotStudioClient.

Current use of this feature requires authorization from Copilot Studio team and will be made generally available in the future.

Important

When using Service Principal login, Your Copilot Studio Agent must be configured for User Anonymous authentication.

This step will require permissions to Create application identities in your Azure tenant. For this sample, you will be creating a Native Client Application Identity, which does not have secrets.

  1. Open https://portal.azure.com
  2. Navigate to Entra Id
  3. Create an new App Registration in Entra ID
    1. Provide an Name
    2. Choose "Accounts in this organization directory only"
    3. Then click register.
  4. In your newly created application
    1. On the Overview page, Note down for use later when configuring the example application:
      1. the Application (client) ID
      2. the Directory (tenant) ID
    2. Goto Manage
    3. Goto API Permissions
    4. Click Add Permission
      1. In the side panel that appears, Click the tab API's my organization uses
      2. Search for Power Platform API.
        1. If you do not see Power Platform API see the note at the bottom of this section.
      3. In the permissions list choose Application Permissions, then CopilotStudio and Check CopilotStudio.Copilots.Invoke
      4. Click Add Permissions
    5. (Optional) Click Grant Admin consent for copilotsdk
    6. Close Azure Portal

Tip

If you do not see Power Platform API in the list of API's your organization uses, you need to add the Power Platform API to your tenant. To do that, goto Power Platform API Authentication and follow the instructions on Step 2 to add the Power Platform Admin API to your Tenant

Instructions - Configure the Example Application - Service Principal Login

With the above information, you can now run the client CopilostStudioClientSample.

  1. Open the appSettings.json file for the CopilotStudioClientSample, or rename launchSettings.TEMPLATE.json to launchSettings.json.
  2. Configured the placeholder values for the various key's based on what was recorded during the setup phase.
  "CopilotStudioClientSettings": {
    "EnvironmentId": "", // Environment ID of environment with the CopilotStudio App.
    "SchemaName": "", // Schema Name of the Copilot to use
    "TenantId": "", // Tenant ID of the App Registration used to login,  this should be in the same tenant as the Copilot.
    "UseS2SConnection": true,
    "AppClientId": "" // App ID of the App Registration used to login,  this should be in the same tenant as the Copilot.
    "AppClientSecret": "" // App Secret of the App Registration used to login,  this should be in the same tenant as the Copilot.
  }
  1. Run the CopilotStudioClientSample.exe program.

This should challenge you for login in a new browser window or tab and once completed, connect ot the Copilot Studio Hosted Agent, allowing you to communicate via a console interface.

Authentication

The CopilotStudio Client requires a Token provided by the developer to operate. For this sample, by default, we are using a user interactive flow to get the user token for the application ID created above.

The Copilot client will use a named HttpClient retrieved from the IHttpClientFactory as mcs injected in DI. This client needs to be configured with a DelegatingHandler to apply a valid Entra ID Token. In this sample using MSAL.