Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Note
This article applies to multiple harnesses. The harness you use affects the billing, features, and capabilities of what you build.
Use the Copilot Studio client in Microsoft 365 Agents SDK to connect your application's interface to a published Copilot Studio agent. Your application handles authentication and displays the activities returned by the agent.
The client is available for:
Code examples focus on .NET for illustrative purposes.
Select an authentication model
Microsoft supports the following two authentication models:
- Delegated access
- Service-to-service (S2S)
Select delegated access when the application should call as a signed-in user. Select service-to-service (S2S) access when a trusted backend should call as an application, without a signed-in user.
Important
Microsoft 365 Agents SDK and Copilot Studio's Microsoft Copilot Harness support both delegated access and service-to-service. Standard harness agents in Copilot Studio only support delegated access.
| Aspect | Delegated access | S2S application access |
|---|---|---|
| Calling identity | A signed-in user through your application. | Your backend's application identity. |
| Typical use | An employee-facing desktop app or signed-in web app. | A background worker, scheduled process, or backend service. |
| Token | User-delegated access token. | App-only access token. |
| Power Platform API permission | Delegated CopilotStudio.Copilots.Invoke. |
Application CopilotStudio.Copilots.Invoke. |
| Credential | A native/public client uses no secret. A server-side web app might require a backend credential. | A backend credential, such as a secret or certificate. |
| Agent authentication | Configure Integrated Authentication or Manual Authentication by using Entra ID. | Configure the agent to require No authentication on the agent. |
| Agent access | The user needs permission to use the agent as owner or the agent is shared with the user identity it is using. | Share the agent with the calling application identity. |
| Supported tool authentication methods (MCS 2) | End user or shared account. | Shared account. |
For browser and native applications, keep the following boundary in mind:
Delegated native app:
User signs in -> native application -> Copilot Studio
Delegated web app:
User signs in -> web application/backend -> Copilot Studio
S2S:
Trusted backend obtains an app-only token -> Copilot Studio
Web or native UI using an S2S backend:
UI -> your protected backend -> Copilot Studio
Never place an S2S client secret or app-only token in browser JavaScript or distribute a confidential credential inside a desktop or mobile application. Put the S2S caller on a trusted backend. That backend must enforce its own caller authorization.
Prepare the agent and Power Platform environment
Complete the following steps for both delegated and S2S authentication:
- Select the Power Platform environment that contains the agent. For the setup described in this article, register the calling application in the same Microsoft Entra tenant as the agent.
- Record the calling application's Directory (tenant) ID and Application (client) ID from Microsoft Entra.
- Confirm that you can publish the agent and that the environment has the required billing capacity or billing plan.
- Configure the agent's authentication and tools for the chosen model, and then save and publish the agent.
- Obtain the agent connection details using the option required by your chosen sample:
- Connection URL: Open Channels, select App, and copy the Connection string under Microsoft 365 Agents SDK. If the connection string or its copy button is unavailable, save and publish the agent, then reopen the App channel.
- Metadata-based configuration: If your sample uses metadata instead of a connection URL, obtain the Environment ID and Schema name from the agent's advanced settings. Use this option instead of the connection URL.
Configure SDK connection settings in code
Complete this shared setup, then follow either Configure delegated user access or Configure S2S application access, depending on your authentication model.
Reference the Copilot Studio client package. For .NET, use
Microsoft.Agents.CopilotStudio.Clientand the authentication dependencies required by your chosen flow.Define named configuration values rather than inlining IDs and URLs throughout the authentication code:
var tenantId = "<directory-tenant-id>"; var clientId = "<application-client-id>"; var agentConnectionUrl = "<connection-string-from-the-App-channel>";Following the initialization pattern in your chosen sample, configure
ConnectionSettings.DirectConnectUrlwithagentConnectionUrl, or use the supported environment and agent metadata instead. The authentication snippets below refer to this configuredConnectionSettingsinstance assettings.Configure the SDK's named
HttpClientto add the access token obtained through your chosen authentication flow as a bearer token. Acquire tokens through a supported identity library, not through your own token implementation.
Use the official sample for the complete settings and HTTP-client initialization. The following examples show how to get an access token. Use the official sample to see how this code fits into a working application.
Configure delegated user access
Follow this section for a signed-in user. For an application identity without a signed-in user, use Configure S2S application access instead.
Prerequisites
- A published agent and a user authorized to use it.
- Permission to create or configure a Microsoft Entra app registration.
- A tenant that permits user consent for the delegated
CopilotStudio.Copilots.Invokepermission, or an administrator who can grant consent. - A supported sign-in flow for your application type.
Configure the app registration in Microsoft Entra ID
In Microsoft Entra ID > App registrations, create or select a single-tenant registration.
Note
If you're using the console application sample and running a local .NET console or native-app test, open Authentication > Add a platform > Mobile and desktop applications and add
http://localhost.For a web application, configure the correct Web or Single-page application platform and its redirect URI instead of copying the console's redirect configuration. A server-side web application can use authorization-code sign-in. A browser/native public client uses authorization code with Proof Key for Code Exchange (PKCE). Use on-behalf-of (OBO) only when your architecture actually includes an API-to-downstream-API user token exchange.
Open API permissions > Add a permission > APIs my organization uses.
Find Power Platform API and select Delegated permissions > CopilotStudio > CopilotStudio.Copilots.Invoke and add it.
Obtain administrator consent if your organization's policy requires it.
Confirm that the signed-in user has permission to use the agent.
A native/public client doesn't need a client secret. Don't create one for the console's interactive sign-in.
Configure and test the client in code
Use the tenant ID, client ID, and settings you configured in Configure SDK connection settings. Obtain a delegated token through MSAL, and then attach it as the bearer token for the SDK's HTTP requests.
For a public-cloud console test, the authentication step follows this pattern:
var redirectUri = "http://localhost";
var identity = PublicClientApplicationBuilder.Create(clientId)
.WithTenantId(tenantId)
.WithRedirectUri(redirectUri)
.Build();
var result = await identity
.AcquireTokenInteractive([CopilotClient.ScopeFromSettings(settings)])
.ExecuteAsync(cancellationToken);
This token-acquisition step isn't a complete application. In a long-running application, use the MSAL cache and silent acquisition before prompting again. Choose an appropriate protected cache if persisting tokens.
Start a conversation, send a message, and verify that the agent responds. Test both an authorized user and a user who should be denied access.
Configure service-to-service (S2S) application access
Follow this section for an application identity without a signed-in user. For a signed-in user, use Configure delegated user access instead.
Prerequisites
- An environment or tenant where the S2S flow is available.
- A published agent set to No authentication, as required by the current onboarding guide.
- A same-tenant application identity with the application
CopilotStudio.Copilots.Invokepermission and administrator consent. - The agent shared with the calling application identity.
- A credential held only by a trusted backend.
- Tools and data connections that don't require an interactive end-user sign-in.
Configure the app registration in Microsoft Entra ID
- In the calling app registration, open API permissions > Add a permission > APIs my organization uses > Power Platform API.
- Select Application permissions >
CopilotStudio.Copilots.Invoke, add it, and grant administrator consent.
Configure the agent in Copilot Studio
- In Copilot Studio, open the agent's Share pane. Add the calling application identity, save it, and reopen the pane to confirm the assignment.
- Set the agent to No authentication, then save and publish it.
- Review and restrict other channels before exposing this agent. An app's Direct-to-engine (D2E) sharing grant doesn't secure an independently accessible anonymous channel.
You can use the same app registration for delegated and application testing, but each permission authorizes a different flow. Keep only the permissions you need. Separate development and production identities, and consider separate registrations when ownership or risk differs.
Create and store a credential
Important
Only use this approach for testing purposes. Don't use this approach for production agents.
For a short local test:
- In Microsoft Entra ID, open App registrations > your app > Certificates & secrets > New client secret.
- Choose a short, appropriate lifetime.
- Copy the secret's Value when it is displayed. The Secret ID isn't the credential.
- Enter the value into a local masked prompt or a suitable local secret store. Don't commit it, put it in a command-line argument, or paste it into chat.
- Delete the temporary secret after testing.
For production purposes, use a certificate or a supported workload identity/federation setup over a manually handled shared secret. Confirm support and agent sharing for the actual calling identity. Use a managed secret store where secrets are necessary, and assign an owner for rotation and expiry.
Acquire an app-only token in code
Use the tenant ID, client ID, and settings configured in Configure SDK connection settings. With a client secret, the MSAL authentication step follows this pattern:
var identity = ConfidentialClientApplicationBuilder.Create(clientId)
.WithTenantId(tenantId)
.WithClientSecret(clientSecretFromSecureStorage)
.Build();
var result = await identity
.AcquireTokenForClient([CopilotClient.ScopeFromSettings(settings)])
.ExecuteAsync(cancellationToken);
Reuse the confidential client so MSAL can cache and refresh application tokens. This flow doesn't use a browser, redirect URI, or user account.
For the public cloud, the scope resolves to https://api.powerplatform.com/.default. Use the SDK's cloud-aware scope resolution for other clouds.
Connect the SDK to your web or native interface
After completing the shared SDK setup and your chosen authentication path, adapt the official sample to your application's architecture:
- Use
StartConversationAsyncto start a conversation andAskQuestionAsyncorSendActivityAsyncto send input. - Render returned message activities, cards, and suggested actions as appropriate to your UI. Events such as
turn.completeare protocol notifications, not agent-authored chat text. - Isolate conversation state by authorized user/session. Don't share one stateful client or conversation across unrelated users. Keep application and delegated conversations separate, and start a new conversation if the identity type, application, or user changes.
- Support cancellation, timeouts, and safe error reporting. Don't blindly retry a failed turn that might already have performed a business action.
For a server-backed UI, authenticate and authorize requests to your backend, protect session cookies, and prevent cross-user access to conversation IDs.
For a native application that needs S2S behavior, call your protected backend rather than shipping the S2S credential with the app.
Govern each integration
There are three separate authorization boundaries:
- Who can call your application
- Which identity can invoke the agent
- Which identity can access each downstream tool or data source
Granting agent invocation doesn't grant Microsoft Graph, connector, or business-system permissions.
| Control | Delegated integration | S2S integration |
|---|---|---|
| Identity and access | Restrict user access and consent; apply relevant Entra sign-in and Conditional Access policies. | Restrict application permissions and agent sharing; protect the backend's own inbound API. |
| Tool authorization | Verify which user or configured connection each tool actually uses. | Use approved non-user-dependent connections. Don't assume the app token automatically authenticates every tool. |
| Credential protection | Keep public clients secret-free; protect user tokens and server credentials where applicable. | Keep app credentials server-side, rotate them, and monitor expiry and workload sign-ins. |
| Data and channels | Apply data policies to connectors, HTTP endpoints, knowledge, and publication channels. | Apply the same controls, with an explicit review of anonymous channels and service-owned data access. |
| Audit | Correlate user/session, agent, request IDs, and business actions without logging tokens. | Correlate application identity, job/request, agent, and actions; retain the backend's original caller context where needed. |
| Lifecycle | Separate development, test, and production; control publishing and access changes. | Also review credential owners, app-sharing grants, unattended job schedules, and decommissioning. |
Use Power Platform data policies to govern allowed connections and channels. A policy that blocks Chat without Microsoft Entra ID authentication in Copilot Studio can conflict with the current S2S No authentication requirement. Work with your administrator to resolve the policy conflict rather than turning off protections for the whole organization.
For S2S, turn off or restrict unneeded anonymous entry points by using the controls supported by your deployment. Verify those controls through a negative access test. Check that applications you didn't share the agent with can't access it. Getting an access token doesn't automatically give an application permission to use the agent.
Apply least privilege to knowledge and tools. Protect high-impact operations by using explicit backend authorization and appropriate approvals, not prompt instructions alone. Review transcript retention, personal data, and telemetry access before enabling detailed logging.
Plan billing and consumption
The authentication model determines the calling identity, not a free-use entitlement. Calling from anywhere to a Copilot Studio Agent incurs usage and requires appropriate billing and cost controls configured before you make the test. You're responsible for ensuring you set up and configure this and for the usage of your agents. See standard-harness billing, GitHub Harness/Microsoft Copilot Harness billing, and the current licensing guide.
The service principal, app registration, and SDK don't replace the environment's capacity or billing setup. For GitHub Harness/Microsoft Copilot Harness usage, credits are charged to the environment where the agent runs, through the applicable prepaid capacity or pay-as-you-go plan.
Troubleshoot the connection
| Symptom | What to check |
|---|---|
| Interactive sign-in fails | Tenant, client ID, app platform, redirect URI, delegated permission, consent, and relevant sign-in policy. |
| App-only token acquisition fails | Client ID, tenant, credential value rather than Secret ID, credential expiry, and application configuration. |
| HTTP 401 or 403 | Token audience, permission type, consent, tenant, and user/app authorization to the agent. |
| HTTP 405 with an access-denied message | Confirm the published authentication setting, app sharing, and S2S enablement for the actual endpoint/environment. The status alone doesn't identify the failed check. |
| HTTP 404 or protocol error | Agent publication, current connection URL, selected environment, and SDK version. |
| Identity mismatch during a conversation | Start a new conversation under the intended identity. Don't reuse another identity's conversation. |
| Agent responds but a tool fails | Inspect that tool's connection, permissions, data policy, and whether it requires a user context unavailable to S2S. |
| Usage limit or billing error | Environment funding, prepaid capacity, tenant-pool settings, pay-as-you-go configuration, and agent-level limits. |
If you need help troubleshooting, include the time of the issue in UTC, the HTTP status code, any error message with sensitive details removed, request or correlation IDs, and your SDK version. Don't include secrets, access tokens, refresh tokens, or authorization headers. To report an issue, go to https://github.com/microsoft/Agents/ and choose the Agents SDK repository for your programming language.
FAQ
Should I modify the connection URL when the agent uses No authentication?
No. Use the connection URL provided by Copilot Studio. Don't reconstruct its path or remove /authenticated/ when setting the agent to no authentication. That setting concerns end-user authentication, while the D2E endpoint still authenticates the SDK caller.
Can I use Web Chat or Direct Line credentials with this SDK?
The SDK connection is distinct from the default Web Chat iframe and Direct Line. Don't use their credentials or configuration instructions interchangeably.
Related information
- Copilot Studio client: .NET sample
- Copilot Studio client: JavaScript sample
- Copilot Studio client: Python sample
- S2S onboarding, identity checks, and sharing requirements
- Configure data policies for agents
- Standard-harness billing rates and management
- GitHub Harness/Microsoft Copilot Harness usage-based billing
- Manage costs and consumption controls
- Billing and licensing FAQ
- Microsoft Copilot Studio Licensing Guide