-
Notifications
You must be signed in to change notification settings - Fork 25
[A365 support] Add Agent 365 token support #457
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
heyitsaamir
merged 6 commits into
feature_agent365_support
from
add_agent365_token_support
Jun 18, 2026
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ca1c27c
Add Agent 365 token support
heyitsaamir f9d51e4
Improve Agent 365 token errors
heyitsaamir adc286d
Cache Agent ID MSAL clients
heyitsaamir 365b889
Address Agent 365 token review feedback
heyitsaamir e222f20
Avoid blocking on Agent ID user token exchange
heyitsaamir 03d91ce
Rename Agent ID token API to agentic
heyitsaamir File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| # agent365 | ||
|
|
||
| Acquire an Agent 365 agent user token using an agent identity blueprint, an agent identity app ID, and an agent user. | ||
|
|
||
| ## Run | ||
|
|
||
| Set these environment variables or add them to `.env`: | ||
|
|
||
| ```bash | ||
| AGENT365_TENANT_ID=<tenant-id> | ||
| AGENT365_BLUEPRINT_CLIENT_ID=<agent-identity-blueprint-app-id> | ||
| AGENT365_BLUEPRINT_CLIENT_SECRET=<agent-identity-blueprint-secret> | ||
| AGENT365_AGENT_IDENTITY_APP_ID=<agent-identity-app-id> | ||
| AGENT365_AGENT_USER_ID=<agent-user-object-id> | ||
| ``` | ||
|
|
||
| Then run: | ||
|
|
||
| ```bash | ||
| uv run --project examples/agent365 python src/main.py | ||
| ``` | ||
|
|
||
| By default this requests a Teams bot API token for `https://botapi.skype.com/.default`. | ||
|
|
||
| To request another resource, set `AGENT365_SCOPE`, for example: | ||
|
|
||
| ```bash | ||
| AGENT365_SCOPE=https://graph.microsoft.com/.default | ||
| ``` | ||
|
|
||
| You can use `AGENT365_AGENT_USER_UPN` instead of `AGENT365_AGENT_USER_ID`. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| [project] | ||
| name = "agent365" | ||
| version = "0.1.0" | ||
| description = "Agent 365 token example" | ||
| readme = "README.md" | ||
| requires-python = ">=3.11,<4.0" | ||
| dependencies = [ | ||
| "dotenv>=0.9.9", | ||
| "microsoft-teams-apps", | ||
| ] | ||
|
|
||
| [tool.uv.sources] | ||
| microsoft-teams-apps = { workspace = true } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| """ | ||
| Copyright (c) Microsoft Corporation. All rights reserved. | ||
| Licensed under the MIT License. | ||
| """ | ||
|
|
||
| import asyncio | ||
| import os | ||
|
|
||
| from dotenv import load_dotenv | ||
| from microsoft_teams.api import ClientCredentials | ||
| from microsoft_teams.apps.token_manager import AGENT_BOT_API_SCOPE, TokenManager | ||
|
|
||
|
|
||
| def get_required_env(name: str) -> str: | ||
| value = os.getenv(name) | ||
| if not value: | ||
| raise ValueError(f"{name} must be set") | ||
|
|
||
| return value | ||
|
|
||
|
|
||
| async def main(): | ||
| load_dotenv() | ||
|
|
||
| tenant_id = get_required_env("AGENT365_TENANT_ID") | ||
| blueprint_client_id = get_required_env("AGENT365_BLUEPRINT_CLIENT_ID") | ||
| blueprint_client_secret = get_required_env("AGENT365_BLUEPRINT_CLIENT_SECRET") | ||
| agentic_app_id = get_required_env("AGENT365_AGENTIC_APP_ID") | ||
| agentic_user_id = os.getenv("AGENT365_AGENTIC_USER_ID") | ||
| agentic_user_upn = os.getenv("AGENT365_AGENTIC_USER_UPN") | ||
| scope = os.getenv("AGENT365_SCOPE", AGENT_BOT_API_SCOPE) | ||
|
|
||
| credentials = ClientCredentials( | ||
| client_id=blueprint_client_id, | ||
| client_secret=blueprint_client_secret, | ||
| tenant_id=tenant_id, | ||
| ) | ||
| token_manager = TokenManager(credentials=credentials) | ||
|
|
||
| token = await token_manager.get_agentic_token( | ||
| tenant_id, | ||
| agentic_app_id, | ||
| scope, | ||
| agentic_user_id=agentic_user_id, | ||
| agentic_user_upn=agentic_user_upn, | ||
| ) | ||
|
|
||
| print(f"Acquired agent user token for {scope}") | ||
| print(f"Token preview: {str(token)[:20]}...") | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| asyncio.run(main()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.