Add Agent 365 token support#628
Conversation
|
This change is part of the following stack: Change managed by git-spice. |
a33ab81 to
9961c24
Compare
66a1dec to
96485b1
Compare
There was a problem hiding this comment.
Pull request overview
Adds foundational types and plumbing for Agent 365 token scenarios across @microsoft/teams.api and @microsoft/teams.apps, including new agent identity modeling, an extensible token-provider callback shape, and a new TokenManager agentic token acquisition path.
Changes:
- Introduces
AgenticIdentityand exports it from the API models barrel. - Extends auth surface area:
CloudEnvironment.agenticBotScopeandTokenCredentials.token(..., options?: TokenRequestOptions). - Updates
TokenManagerwithgetAppToken(...)andgetAgenticToken(...)plus an@azure/msal-nodeversion bump.
Reviewed changes
Copilot reviewed 7 out of 8 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/apps/src/token-manager.ts | Adds getAppToken and implements a 3-step getAgenticToken exchange flow plus new MSAL client caching. |
| packages/apps/src/token-manager.spec.ts | Updates TokenCredentials-provider expectations for the new optional options argument. |
| packages/apps/package.json | Bumps @azure/msal-node dependency version. |
| packages/api/src/models/index.ts | Exports the new agentic-identity model. |
| packages/api/src/models/agentic-identity.ts | Adds the AgenticIdentity type. |
| packages/api/src/auth/credentials.ts | Adds TokenRequestOptions and extends TokenCredentials.token signature to accept options. |
| packages/api/src/auth/cloud-environment.ts | Adds agenticBotScope to CloudEnvironment and populates it for predefined clouds. |
| package-lock.json | Updates lockfile for the MSAL dependency bump. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| const confidentialClient = this.getConfidentialClient(this.credentials, tenantId); | ||
| const t1Result = await confidentialClient.acquireTokenByClientCredential({ | ||
| scopes: [TOKEN_EXCHANGE_SCOPE], | ||
| fmiPath: agenticIdentity.agenticAppId, | ||
| }); |
There was a problem hiding this comment.
Hm it should... the latest version of msal should include this.
There was a problem hiding this comment.
False positive — fmiPath is available in @azure/msal-node 5.3.0 (our installed version). It's used in ClientCredentialClient for the FMI exchange step. The Copilot review was checking against outdated type defs.
| async getAgenticToken( | ||
| agenticIdentity: AgenticIdentity, | ||
| scope: string | ||
| ): Promise<IToken | null> { |
There was a problem hiding this comment.
We should add tests.
There was a problem hiding this comment.
Agree — will add tests for getAgenticToken in a follow-up.
| async getAppToken(scope: string, tenantId?: string, defaultTenantId?: string): Promise<IToken | null> { | ||
| return await this.getToken(scope, this.resolveTenantId(tenantId, defaultTenantId ?? this.cloud.loginTenant)); |
| const tenantId = agenticIdentity.tenantId ?? this.credentials?.tenantId; | ||
| if (!tenantId) { | ||
| throw new Error('tenantId is required to get an agentic token'); | ||
| } | ||
|
|
||
| if (!this.credentials) { | ||
| return null; | ||
| } |
| const cacheKey = `${tenantId}:${agenticAppId}`; | ||
| const cachedClient = this.agentIdentityClientsByTenantAndAppId[cacheKey]; | ||
| if (cachedClient) { | ||
| return cachedClient; | ||
| } |
| async getAgenticToken( | ||
| agenticIdentity: AgenticIdentity, | ||
| scope: string | ||
| ): Promise<IToken | null> { |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Adds foundational token support for Agent 365 scenarios:
AgenticIdentitytype (agenticAppId, agenticUserId, tenantId, agenticAppBlueprintId)agenticBotScopeonCloudEnvironment(https://botapi.skype.com/.default)TokenRequestOptionstype for extensible token callback optionsTokenManager.getAgenticToken(agenticIdentity, scope)— 3-step FMI token exchange (T1 → T2 → T3)TokenManager.getAppToken(scope, tenantId?)— generalized app token methodTokenCredentials.tokensignature extended:(scope, tenantId?, options?: TokenRequestOptions)