Skip to main content

A msal-based authentication library for Microsoft Agents

Project description

Microsoft Agents MSAL Authentication

PyPI version

Provides secure authentication for your agents using Microsoft Authentication Library (MSAL). It handles getting tokens from Azure AD so your agent can securely communicate with Microsoft services like Teams, Graph API, and other Azure resources.

What is this?

This library is part of the Microsoft 365 Agents SDK for Python - a comprehensive framework for building enterprise-grade conversational AI agents. The SDK enables developers to create intelligent agents that work across multiple platforms including Microsoft Teams, M365 Copilot, Copilot Studio, and web chat, with support for third-party integrations like Slack, Facebook Messenger, and Twilio.

Release Notes

Version Date Release Notes
0.8.0 2026-02-23 0.8.0 Release Notes
0.7.0 2026-01-21 0.7.0 Release Notes
0.6.1 2025-12-01 0.6.1 Release Notes
0.6.0 2025-11-18 0.6.0 Release Notes
0.5.0 2025-10-22 0.5.0 Release Notes

Packages Overview

We offer the following PyPI packages to create conversational experiences based on Agents:

Package Name PyPI Version Description
microsoft-agents-activity PyPI Types and validators implementing the Activity protocol spec.
microsoft-agents-hosting-core PyPI Core library for Microsoft Agents hosting.
microsoft-agents-hosting-aiohttp PyPI Configures aiohttp to run the Agent.
microsoft-agents-hosting-teams PyPI Provides classes to host an Agent for Teams.
microsoft-agents-storage-blob PyPI Extension to use Azure Blob as storage.
microsoft-agents-storage-cosmos PyPI Extension to use CosmosDB as storage.
microsoft-agents-authentication-msal PyPI MSAL-based authentication for Microsoft Agents.

Additionally we provide a Copilot Studio Client, to interact with Agents created in CopilotStudio:

Package Name PyPI Version Description
microsoft-agents-copilotstudio-client PyPI Direct to Engine client to interact with Agents created in CopilotStudio

Installation

pip install microsoft-agents-authentication-msal

Quick Start

Basic Setup with Client Secret

Define your client secrets in the ENV file

CONNECTIONS__SERVICE_CONNECTION__SETTINGS__CLIENTID=client-id
CONNECTIONS__SERVICE_CONNECTION__SETTINGS__CLIENTSECRET=client-secret
CONNECTIONS__SERVICE_CONNECTION__SETTINGS__TENANTID=tenant-id

Load the Configuration (Code from main.py Quickstart Sample)

from .start_server import start_server

start_server(
    agent_application=AGENT_APP,
    auth_configuration=CONNECTION_MANAGER.get_default_connection_configuration(),
)

Then start the Agent (code snipped from (start_server.py Quickstart Sample](https://github.com/microsoft/Agents/blob/main/samples/python/quickstart/src/start_server.py)):

def start_server(
    agent_application: AgentApplication, auth_configuration: AgentAuthConfiguration
):
    async def entry_point(req: Request) -> Response:
        agent: AgentApplication = req.app["agent_app"]
        adapter: CloudAdapter = req.app["adapter"]
        return await start_agent_process(
            req,
            agent,
            adapter,
        )
[...]

Authentication Types

The M365 Agents SDK in Python supports the following Auth types:

class AuthTypes(str, Enum):
    certificate = "certificate"
    certificate_subject_name = "CertificateSubjectName"
    client_secret = "ClientSecret"
    user_managed_identity = "UserManagedIdentity"
    system_managed_identity = "SystemManagedIdentity"

Key Classes

  • MsalAuth - Core authentication provider using MSAL
  • MsalConnectionManager - Manages multiple authentication connections

Features

Multiple auth types - Client secret, certificate, managed identity
Token caching - Automatic token refresh and caching
Multi-tenant - Support for different Azure AD tenants
Agent-to-agent - Secure communication between agents
On-behalf-of - Act on behalf of users

Security Best Practices

  • Store secrets in Azure Key Vault or environment variables
  • Use managed identities when possible (no secrets to manage)
  • Regularly rotate client secrets and certificates
  • Use least-privilege principle for scopes and permissions

Quick Links

Sample Applications

Explore working examples in the Python samples repository:

Name Description README
Quickstart Simplest agent Quickstart
Auto Sign In Simple OAuth agent using Graph and GitHub auto-signin
OBO Authorization OBO flow to access a Copilot Studio Agent obo-authorization
Semantic Kernel Integration A weather agent built with Semantic Kernel semantic-kernel-multiturn
Streaming Agent Streams OpenAI responses azure-ai-streaming
Copilot Studio Client Console app to consume a Copilot Studio Agent copilotstudio-client
Cards Agent Agent that uses rich cards to enhance conversation design cards

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file microsoft_agents_authentication_msal-0.9.0.dev10.tar.gz.

File metadata

File hashes

Hashes for microsoft_agents_authentication_msal-0.9.0.dev10.tar.gz
Algorithm Hash digest
SHA256 b0134b6307f3b1287530de9125d4cc95e419d0d2e111dad4f5f1129a69a28647
MD5 ef46309a380626510ac558a68fa7a375
BLAKE2b-256 9625ac9320b075ba91bd6b83f0095637f24c8b53a3ac1b4ac90d01c607ef7f25

See more details on using hashes here.

File details

Details for the file microsoft_agents_authentication_msal-0.9.0.dev10-py3-none-any.whl.

File metadata

File hashes

Hashes for microsoft_agents_authentication_msal-0.9.0.dev10-py3-none-any.whl
Algorithm Hash digest
SHA256 ea278d922d9238f4135d83f2be6470af73619ea5f4200e358742fd57223ae493
MD5 1a44d538d8d91557c311bd1191a39d1f
BLAKE2b-256 35d4bba073b32fa20c41ae9db66e0a40ec1f88eb4b3894c0f6e6eff0080682da

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page