Skip to content

Commit be8ab9c

Browse files
committed
Phase 3: Enhanced Microsoft 365 Authentication and Authorization
- Enhanced AuthService with Microsoft Graph integration - Added comprehensive user claims with Graph data - Implemented permission-based access control - Added token validation and caching - Enhanced agent app with permission checking - Added comprehensive test suite for auth service - All 74 tests passing with proper mocking Features: - Microsoft Graph user information retrieval - Group and role-based permissions - Token caching and validation - Enhanced error handling - Permission mapping for different access levels - Integration with existing RAG backend
1 parent e7116f0 commit be8ab9c

File tree

4 files changed

+854
-8
lines changed

4 files changed

+854
-8
lines changed

agents/agent_app.py

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
from config.agent_config import AgentConfig
3131
from services.rag_service import RAGService
32-
from services.auth_service import AuthService
32+
from services.auth_service import AuthService, UserClaims
3333
from handlers.message_handler import MessageHandler
3434
from handlers.teams_handler import TeamsHandler
3535
from adapters.response_adapter import ResponseAdapter
@@ -99,8 +99,33 @@ async def on_message_activity(self, turn_context: TurnContext) -> None:
9999
conversation_data.message_count += 1
100100
conversation_data.last_activity = turn_context.activity.text
101101

102-
# Get user authentication claims
103-
auth_claims = await self.auth_service.get_user_claims(turn_context)
102+
# Get enhanced user authentication claims
103+
user_claims = await self.auth_service.get_enhanced_user_claims(turn_context)
104+
auth_claims = {
105+
"oid": user_claims.user_id,
106+
"name": user_claims.user_name,
107+
"email": user_claims.email,
108+
"tenant_id": user_claims.tenant_id,
109+
"groups": user_claims.groups,
110+
"roles": user_claims.roles,
111+
"is_authenticated": user_claims.is_authenticated,
112+
"additional_claims": user_claims.additional_claims
113+
}
114+
115+
# Check user permissions
116+
if not user_claims.is_authenticated:
117+
await turn_context.send_activity(
118+
MessageFactory.text("I'm sorry, I need to verify your identity before I can help you. Please ensure you're properly authenticated.")
119+
)
120+
return
121+
122+
# Check if user has basic read permission
123+
has_read_permission = await self.auth_service.check_user_permission(user_claims, "read_documents")
124+
if not has_read_permission:
125+
await turn_context.send_activity(
126+
MessageFactory.text("I'm sorry, you don't have permission to access the document search functionality. Please contact your administrator.")
127+
)
128+
return
104129

105130
# Process the message based on channel
106131
if turn_context.activity.channel_id == "msteams":

agents/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ aiohttp>=3.8.0
1212

1313
# Authentication
1414
msal>=1.24.0
15+
azure-identity>=1.15.0
1516

1617
# Utilities
1718
python-dotenv>=1.0.0

0 commit comments

Comments
 (0)