22# Licensed under the MIT License.
33
44import pathlib
5+ from os import environ , path
56from dotenv import load_dotenv
67from aiohttp .web import Application , Request , Response , run_app
78
8- from microsoft .agents .hosting . core import RestChannelServiceClientFactory
9- from microsoft .agents .hosting . core . state import UserState
9+ from microsoft .agents .activity import load_configuration_from_env
10+ from microsoft .agents .authentication . msal import MsalConnectionManager
1011from microsoft .agents .hosting .aiohttp import CloudAdapter , jwt_authorization_decorator
11- from microsoft .agents .hosting .core .authorization import (
12- Connections ,
13- AccessTokenProviderBase ,
14- ClaimsIdentity ,
15- )
16- from microsoft .agents .authentication .msal import MsalAuth
17- from microsoft .agents .hosting .core .storage import MemoryStorage
12+ from microsoft .agents .hosting .core import Authorization , MemoryStorage , UserState
1813
1914from teams_handler import TeamsHandler
2015from teams_sso import TeamsSso
2116from teams_multi_feature import TeamsMultiFeature
2217from config import DefaultConfig
2318
24- load_dotenv ()
19+ load_dotenv (path . join ( path . dirname ( __file__ ), ".env" ) )
2520
2621CONFIG = DefaultConfig ()
27- AUTH_PROVIDER = MsalAuth (DefaultConfig ())
2822
23+ agents_sdk_config = load_configuration_from_env (environ )
2924
30- class DefaultConnection (Connections ):
31- def get_default_connection (self ) -> AccessTokenProviderBase :
32- pass
33-
34- def get_token_provider (
35- self , claims_identity : ClaimsIdentity , service_url : str
36- ) -> AccessTokenProviderBase :
37- return AUTH_PROVIDER
38-
39- def get_connection (self , connection_name : str ) -> AccessTokenProviderBase :
40- return AUTH_PROVIDER
41-
42-
43- CHANNEL_CLIENT_FACTORY = RestChannelServiceClientFactory (CONFIG , DefaultConnection ())
44-
45- # Create adapter.
46- ADAPTER = CloudAdapter (CHANNEL_CLIENT_FACTORY )
47-
48- # Create the storage and user state (for SSO agent)
4925STORAGE = MemoryStorage ()
26+ CONNECTION_MANAGER = MsalConnectionManager (** agents_sdk_config )
27+ ADAPTER = CloudAdapter (connection_manager = CONNECTION_MANAGER )
28+ AUTHORIZATION = Authorization (STORAGE , CONNECTION_MANAGER , ** agents_sdk_config )
29+
5030USER_STATE = UserState (STORAGE )
5131
5232
@@ -55,7 +35,7 @@ def create_agent(agent_type: str):
5535 Create the appropriate agent based on configuration.
5636 """
5737 if agent_type == "TeamsSso" :
58- return TeamsSso (USER_STATE , CONFIG .CONNECTION_NAME , CONFIG .CLIENT_ID )
38+ return TeamsSso (STORAGE , USER_STATE , CONFIG .CONNECTION_NAME , CONFIG .CLIENT_ID )
5939 elif agent_type == "TeamsMultiFeature" :
6040 return TeamsMultiFeature ()
6141 else : # Default to TeamsHandler
0 commit comments