Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .github/workflows/e2e-nodejs-copilot-studio.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
nodejs-copilot-studio:
name: Node.js Copilot Studio Agent
runs-on: windows-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4
Expand Down Expand Up @@ -74,7 +74,8 @@ jobs:
-ClientId "${{ secrets.MCP_CLIENT_ID }}" `
-TenantId "${{ secrets.MCP_TENANT_ID }}" `
-Username "${{ secrets.MCP_TEST_USERNAME }}" `
-Password "${{ secrets.MCP_TEST_PASSWORD }}"
-Password "${{ secrets.MCP_TEST_PASSWORD }}" `
-Scope "https://api.powerplatform.com/CopilotStudio.Copilots.Invoke"
echo "BEARER_TOKEN=$token" >> $env:GITHUB_OUTPUT
echo "::add-mask::$token"

Expand Down
19 changes: 12 additions & 7 deletions nodejs/copilot-studio/sample-agent/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,17 +186,22 @@ export async function getClient(
// Load Copilot Studio connection settings from environment
const settings = loadCopilotStudioConnectionSettingsFromEnv();

// Acquire token for Copilot Studio API
const tokenResult = await authorization.exchangeToken(turnContext, authHandlerName, {
scopes: ['https://api.powerplatform.com/.default']
});
let authtoken = process.env.BEARER_TOKEN;
if (!authtoken) {
// Acquire token for Copilot Studio API
const tokenResult = await authorization.exchangeToken(turnContext, authHandlerName, {
scopes: ['https://api.powerplatform.com/.default']
});

if (!tokenResult?.token) {
throw new Error('Failed to acquire token for Copilot Studio. User may need to sign in.');
}

if (!tokenResult?.token) {
throw new Error('Failed to acquire token for Copilot Studio. User may need to sign in.');
authtoken = tokenResult.token;
}

// Create the Copilot Studio client with the token
const copilotClient = new CopilotStudioClient(settings, tokenResult.token);
const copilotClient = new CopilotStudioClient(settings, authtoken);

return new McsClient(copilotClient);
}
Loading